How to remove files with zero lenght


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to remove files with zero lenght
# 1  
Old 09-07-2005
How to remove files with zero lenght

How to remove files with zero lenght with one or more commands from the same directory?

Thanks.
# 2  
Old 09-07-2005
This script is in Csh.

#!/bin/csh
foreach file(`ls`)
if (-z $file) /bin/rm -rf $file
end
# 3  
Old 09-08-2005
And in bash:
Code:
#!/bin/bash
for FILE in /path/to/dir
   do [ ! -s $FILE ] && /bin/rm -f $FILE
done

OR

Code:
find /path/to/dir -size 0 | xargs /bin/rm -f

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

C: lenght of array

Doing some training code with arrays i run into the following issue: If i ask the user how long the array is supposed to be, malloc it and then ask for the values inside the array and return the list to main and assing it to a pointer to list of integers: #include <stdio.h> #include... (7 Replies)
Discussion started by: tornow
7 Replies

2. Solaris

Command to remove existing files in the tar files in Solaris 10

Hi, I am using solaris 10 OS.Please help me out with the commands needed in below two scenarios. 1)How to delete the existing files in the tar file. suppose i have a main tarfile named application.tar and it contains a file called ingres.tar. what is the command to remove ingres.tar... (2 Replies)
Discussion started by: muraliinfy04
2 Replies

3. UNIX for Advanced & Expert Users

how to find lenght of fixed width file record?

actually i am trying to find the lenght of fixed width file record reading from teradata db but its not working can u guys help me out? code which i wrote--- colmn_lngth=`cat $RPT_FILE | awk -F~ '{print $1}'` rm $RPT_FILE while read line do result=`echo $line | wc -m` ... (4 Replies)
Discussion started by: Seshendranath
4 Replies

4. Shell Programming and Scripting

Check input for lenght, special characters and letter case

I made menu script for users so they can run other script without going in shell just from menu. But i must control their input. These are criteria: Input must have 4 signs First two signs are always lower case letters Input shall not have some special signs just letters and numbers ... (1 Reply)
Discussion started by: waso
1 Replies

5. Shell Programming and Scripting

korn shell display lenght problem!!! i got stuck on this

Using the KSH, write a shell script called display_by_length, which takes an absolute pathname to a directory and displays all ordinary files in the directory ordered by their length; for each file listed, display the name of the file and its length - nothing else. Extend this script to take an... (1 Reply)
Discussion started by: babuda0059
1 Replies

6. UNIX for Advanced & Expert Users

NIS username max lenght

Hi I want to know the maximum length of user name under NIS? I tried googling but it didnt help :(. If there is any command to find out this please let me know. I know on unix user name should be 8 characters long but just i want to know if i can have 9 letter user under mapped under NIS. (1 Reply)
Discussion started by: zedex
1 Replies

7. Shell Programming and Scripting

Sort based on string lenght.

I'm not familiar with find. If i use find in a certain directory i want it to show based on hierarchy. find . type d fol1 fol1/subfol1 fol1/subfol1/subfol1 fol2 fol2/subfol2 i want it to show like this fol1/subfol1/subfol1 fol1/subfol1 fol1 fol2/subfol2 fol2 do i need to use... (5 Replies)
Discussion started by: ryandegreat25
5 Replies

8. Shell Programming and Scripting

compare two files and to remove the matching lines on both the files

I have two files and need to compare the two files and to remove the matching lines from both the files (4 Replies)
Discussion started by: shellscripter
4 Replies

9. Shell Programming and Scripting

Can we convert a '|' file into a fixed lenght???

Hi All, I have a pipe separated flat file.But there is often some problem with the records.So is it possible to convert the '|' separated file into a fixed length file by means of some script. The file has 11 columns which means 10 pipes.Your help is appreciated. i'm using Sun OS Version... (2 Replies)
Discussion started by: kumarsaravana_s
2 Replies

10. IP Networking

how can change udp lenght?

How can change udp lenght? Hello. I have FreeBsd 4.7 and i want to change udp datagramm lenght. Where it can be? What i must do? I can rebuild my core but it is not good for me. Thanks! (4 Replies)
Discussion started by: Vvlad
4 Replies
Login or Register to Ask a Question