shell script
Hi,
I want to write a script that will detect all the unwanted files in a particular directory and delete them in one fly.. Can anyone guide me for this ??? |
Define "Unwanted"
Files older than a certain date? Files named "bad_file"? Files of a size less than 20k? |
What are unwanted files?
You can use find with the --delete option Kind regards |
You'd have to tell us how you define "unwanted" first. What do you intend to key on?
|
Hi,
Quote:
What have you done to find a solution to the problem? Other than to post here. We will aid you when you help yourself to a solution. Provide us with what you have attempted and then maybe someone will be able to assist. You haven't provided enough information for us to aid so; Quote:
1 Linux Documentation Project 2 Rute Tutorial & Exposition 3 Linux Command Guide 4 Bash Beginners Guide 5 Bash Reference Manual 6 Advanced Bash-Scripting Guide 7 Linux Newbie Admin Guide 8 LinuxSelfHelp 9 Utimate Linux Newbie Guide The above links and others can be found at 'Slackware-Links'. More than just SlackwareŽ links! ---------- Post added 04-01-11 at 15:28 ---------- Moved: This thread is more suitable in <Programming> and has been moved accordingly to help your thread/question get the exposure it deserves. |
Quote:
|
Note the date posted. Maybe it was an April Fool's Day joke (I hope :)).
|
Quote:
--- rod. |
Quote:
|
I'll explain with an example...
I have a folder named TEMP.. This folder contains files a.c, b.c, b_bak.c So in this I want to delete only b_bak.c.. So I tried :- find ./TEMP ! -name a.c ! -name b.c | xargs -r rm Now after executing this script it deletes the file but it says cannot delete ./TEMP as it is a directory... So now I modified above since I do not want to delete the Folder itself:- find ./TEMP ! -name a.c ! -name b.c ! -type d ./TEMP | xargs -r rm but now it does nothing and says that Conjunction missing in find.. Plz can anyone help me with this ??? |
Wouldn't it be a better idea to delete everything ending with _bak.c instead of entering the files that shouldn't be deleted? Seems like it would be both easier and less risky.
Code:
find TEMP -name '*_bak.c' -exec rm '{}' ';' |
Quote:
Code:
find TEMP -name '*_bak.c' -print0 | xargs -0 rm If you use GNU find, then Code:
find TEMP -name '*_bak.c' -delete |
All times are GMT -5. The time now is 03:45 PM. |