Deleting files with zero length using ls command


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Deleting files with zero length using ls command
# 1  
Old 07-07-2005
Deleting files with zero length using ls command

Hi,
How can I use ls command to Delete all files with zero length in a given path using ls command (I guess awk is required!)?

Thanks.
# 2  
Old 07-07-2005
hi,

try this,

ls -l | awk ' { if ($5 == 0) print "rm -f "$9 }' | sh
# 3  
Old 07-07-2005
works very well but why do you use the "| sh" at the end?

Thanks much.
# 4  
Old 07-07-2005
Code:
find -maxdepth 1 -type f -size 0 -exec rm -f {} \;

# 5  
Old 07-07-2005
Code:
find -maxdepth 1 -type f -size 0 | xargs rm -f

The xargs will cause all the filenames to be sent as arguments to the 'rm -f' commands. This will save processes that are forked everytime '-exec rm -f' is run.
# 6  
Old 07-07-2005
to be robust:
Code:
find -maxdepth 1 -type f -size 0 -print0 | xargs -0 rm -f

# 7  
Old 07-10-2005
Thanks guys.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script deleting my files, and editing files in subdirectories question

#!/bin/bash # name=$1 type=$2 number=1 for file in ./** do if then filenumber=00$number elif then filenumber=0$number fi tempname="$name""$filenumber"."$type" if (4 Replies)
Discussion started by: TheGreatGizmo
4 Replies

2. Shell Programming and Scripting

Deleting lines in a fixed length file where there is a word at specific location

I have a big file having 100 K lines. I have to read each line and see at 356 character position whethere there is a word "W" in it. If it is their then don't delete the line otherwise delete it. There are two lines as one Header and one trailer which should remain same. Can somebody... (5 Replies)
Discussion started by: mohit kanoongo
5 Replies

3. UNIX for Dummies Questions & Answers

Crontab deleting files command question

Hello out there, Our system has a pdf generator that creates pdf files. We dont need them pas 120 days. So I have this command in my crontab. I currently set it to "0" for testing. But normally have it set to -mtime 120 to remove files out of the folders from PDF out to several other potential... (7 Replies)
Discussion started by: vsekvsek
7 Replies

4. Shell Programming and Scripting

AIX system.... deleting files in remote directory after retrieving files

Hi Friends, I am new to this , I am working on AIX system and my scenario is to retrive the files from remote system and remove the files from the remote system after retreving files. I can able to retrieve the files but Can't remove files in remote system. Please check my code and help me out... (3 Replies)
Discussion started by: vinayparakala
3 Replies

5. Shell Programming and Scripting

Deleting all empty files in sub directories with a command

Hello Friends, Im trying to delete empty files in subdirectories with a command. I can find them checking only one directory in each step and then show them with my command like below moreover i could not add removing part: ls -l */* | awk '{if ($5==0) printf "%3s %2d %s... (5 Replies)
Discussion started by: EAGL€
5 Replies

6. Shell Programming and Scripting

Deleting Characters at specific position in a line if the line is certain length

I've got a file that would have lines similar to: 12345678 x.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 23456781 x.00 xx.00 xx.00 xx.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 34567812 x.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 45678123 x.00 xx.00 xx.00 xx.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 xx.00... (10 Replies)
Discussion started by: Cailet
10 Replies

7. UNIX for Dummies Questions & Answers

What the command to find out the record length of a fixed length file?

I want to find out the record length of a fixed length file? I forgot the command. Any body know? (9 Replies)
Discussion started by: tranq01
9 Replies

8. Shell Programming and Scripting

Deleting files using find command

I want to find the files and delete all the files except the last file. I am using find command , I am sending the find output to a file and getting all the lines except the last one and sending it to the remove command . This is not working. can anyone help me out to do it in the find command... (8 Replies)
Discussion started by: deepaklanka
8 Replies

9. UNIX for Dummies Questions & Answers

limit of command length

Hi! Can you please help me with one question? Does rexec command have some limitation of the length of the deliveded cmd? Thanks in advance, Anta (2 Replies)
Discussion started by: Anta
2 Replies

10. Shell Programming and Scripting

command for deleting log files based on some condition

Hello, Can anyone pls. provide me with the command for deleting files older then 15 days with a restriction to keep at least 5 files in a directory even if they are older then 15 days. Any help will be highly appreciated. Thanks, Pulkit (4 Replies)
Discussion started by: pulkit
4 Replies
Login or Register to Ask a Question