remove files older than x days, excluding one of the directory?
hi guys i have done some research and this works for me
to delete files older than 180days Code:
bash -c 'date;find /data/ -type f -mtime +180 -exec rm -v {} \;;date' >> /archive/rmlog /data/1 /data/2 ... /data/50 then i have sub-directory /data/1/a /data/1/b i want to run that script to delete all files older than 180days, under directory /data/, but excluding /data/1/a means the files in /data/1/a will not get deleted after 180days, but files under /data/1/b, and /data/2-50/* will be deleted. is that a easier way ? else i need to copy paste the script and define the path one by one? thanks |
To exclude a dir, use the -prune option http://stackoverflow.com/questions/1...-of-find-in-sh.
I'd do this as a separate cmd from the following. For the others, use a loop that generates the nums 2-50 and feed it to the find cmd. Put it all in a script instead of calling it on one line, then log output Code:
./myscript.sh >myscript.sh 2>&1 |
hi thanks for the help
lets say, now i have /data/Apple/1 /data/Ball/1 /data/Cat/Apple/1 when i run Code:
find /data -name abc -prune -o /data/Apple/ will not be deleted.(which is correct) but /data/Cat/Apple/ will not be deleted too, which i want them deleted. i have tried maxdepths, but /data/Cat/Apple is one more sub-directory. any suggestion? thanks |
All times are GMT -5. The time now is 08:21 PM. |