![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Transfer files wih directory structure. | uxlunatick | SCO | 11 | 04-28-2008 12:25 PM |
| remove empty directory | sirrtuan | Shell Programming and Scripting | 6 | 03-04-2008 06:50 AM |
| copy files with directory structure | adddy | UNIX for Dummies Questions & Answers | 3 | 12-11-2006 05:50 AM |
| MV files from one directory structure(multiple level) to other directory structure | srmadab | UNIX for Advanced & Expert Users | 4 | 09-13-2006 01:01 PM |
| disk space used for files with in a directory structure. | kasala | Shell Programming and Scripting | 8 | 01-14-2005 01:26 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Script to remove all empty files within the directory structure?
Hi I need to write a shell script which basically searches for all the empty files within the directory structure, lists them before asking the user to confirm if they would like to delete them. If the user deletes the file then a notice would appear confirming the file is deleted.
I've be trying to do this for weeks now and its driving me mad, I'm quite new to this, although I am getting to grips with it slowly. Cheers |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
use the following command to identify the empty files in ur directory
find . -name "*.*" -size 0c |
|
#3
|
|||
|
|||
|
Thanks for the reply m8.
I don't think I explained what I was trying to do correctly, I'm trying to create a shell script that will allow me to find all empty files within my directory tree, list them and then give me the option of deleting them. I would like to be able to get the option of deleting them in the format of : delete word.doc y/n? :> y word.doc deleted. I know some files that are empty are not to be deleted this is why I need to see what I am about to get rid of. I'm just strating out doing Linux and I've hit a brick wall with this so any help would be appreciated, cheers. Last edited by cat123; 06-05-2008 at 03:56 AM. |
|
#4
|
|||
|
|||
|
This pseudo code may put you on right lines...
Code:
file_names=`find . -name "*.*" -size 0c` for i in $file_names do print "Do you want to delete the file?" read input if ans='y' or 'Y' rm -f $i else #do nothing echo "File not deleted" fi done |
|
#5
|
|||
|
|||
|
You can also use
Code:
find . -name "*.*" -size 0c -exec rm -i {} \;
Btw. that find did not work for me on Debian and AIX. If you encounter the same problem, you might try: Code:
find . -type f -size -1 -exec rm -i {} \;
|
|
#6
|
|||
|
|||
|
cheers guys for the help, im gonna give it a go and I'll let you's know how I do.
Cheers |
|||
| Google The UNIX and Linux Forums |