Deleting all empty files in sub directories with a command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Deleting all empty files in sub directories with a command
# 1  
Old 12-04-2009
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:

Code:
ls -l */* | awk '{if ($5==0) printf "%3s %2d %s %15d\n",$6,$7,$9,$5}'

as a result this command is not working as i like, can u suggest a better one?
# 2  
Old 12-04-2009
Try the find command with the -empty option:

Code:
find . -empty -exec rm -f {} \;

# 3  
Old 12-04-2009
Thanks Franklin, it gave bad option warning for -empty. However cant i display the empty files before or after they are removed, like the above AWK command?

Code:
server1{root}/acb>find . -empty -exec rm -f {} \;
find: bad option -empty

# 4  
Old 12-04-2009
Your find version doesn't support the -empty option, try this one:

Code:
find . -size 0c -exec rm -f {} \;

# 5  
Old 12-04-2009
Ok thanks,it works well. I have added "-print" option so that i can see what i delete:

server1{root}/>
Code:
find . -size 0c -print -exec rm -f {} \;

./aaaa.txt
# 6  
Old 12-18-2009
You can also use verbose option of rm command as,

Code:
find . -size 0c -exec rm -vf {} \;
removed `./t'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Find and delete empty files and directories

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Need to make a script, to remove all empty files and folders from current category. It also should show the name... (2 Replies)
Discussion started by: Itixop
2 Replies

2. Shell Programming and Scripting

Script for deleting files and directories when the file system reaches the threshold

Hi Can someone assist in writing a script. I have a filesystem named /sybase in my aix lpar. When this filesystem becomes 94% full all the files and directories under /sybase/logs should be deleted immediately. :confused: (7 Replies)
Discussion started by: newtoaixos
7 Replies

3. Shell Programming and Scripting

Empty out multiple files with a single command?

I have a log directory: /logs/foo.log /logs/bar.log /logs/err.out I'm trying to find a way to > /logs/*.log > /logs/*.out to blank them out, but of course, that doesn't work. Any suggestions? (4 Replies)
Discussion started by: Validatorian
4 Replies

4. Shell Programming and Scripting

Deleting all files recursively from directories while ignoring one file type

Hi, Seems like I need help again with a problem: I want to delete all files from my lets say "Music" Directory inkluding all of the subfolders except for .mp3 and .MP3 files. I tried it with globalignoring mp3 files, finding and deleting all other files, which resulted in all files... (3 Replies)
Discussion started by: pasc
3 Replies

5. Shell Programming and Scripting

deleting files in sub directories!

Hello out there, I want to setup a crontab feature to remove temporary pdf files from sub directories that are older than 30 days. I want to presevere the directory structer though. I got this far for a command. Will this remove the pdf's in subdirectories or just directly under the pdf folder? If... (6 Replies)
Discussion started by: vsekvsek
6 Replies

6. Shell Programming and Scripting

Deleting empty directories using find

Hello, I'm submitting this thread, because I was looking a way to delete empty directories using find and I found a thread from 2007 that helped me. I have worked from that threat, but I found that the command sent would analyze original directory and may delete it to. I have come up with expanded... (3 Replies)
Discussion started by: lramirev
3 Replies

7. Shell Programming and Scripting

deleting empty files in a directory

Hello Gurus, I want to delete only empty files (files with 0 bytes) at once from the local directory. Rightnow I need to go through all the files one by one manually and check the empty files before deleting them. Is there any unix command that finds and deletes empty files in a directory?... (5 Replies)
Discussion started by: berlin_germany
5 Replies

8. Shell Programming and Scripting

deleting the empty files

as of our requiremnt some x no of files will be created from a third party tool ,out of them one or two files will be empty i.e size is 0. so i want to remove those files which are empty. naming of the files which are created will be like this abc_.txt 0 size abc_1.txt 4000 size abc_2.txt... (1 Reply)
Discussion started by: srivsn
1 Replies

9. UNIX for Dummies Questions & Answers

What/How to check before deleting files and directories

Hi there, I have a some directories containing web files that are old, and I need to remove them. I know that there might be sym links and hyperlinks pointing to these old directories. If that's the case, then I'll have to fix the links before deleting these old directories to avoid broken... (4 Replies)
Discussion started by: yvochan
4 Replies

10. UNIX for Dummies Questions & Answers

deleting log files only in particular directories

Hi My problem is i have to remove some log files in specific named directories on a regular basis using shell scripts. What i want my shell script to do is i give the shell script some listing of directories from which to delete all log files recursively. Can anyone please help me. ... (2 Replies)
Discussion started by: sameervs
2 Replies
Login or Register to Ask a Question