Reputation: 7028
I am writing a script to cleanup user dir on "/srv". At present every user keeps some temp files on "/srv/$USER".
Following is my script :
for x in $(cut -d: -f1 /etc/passwd); do
if [ -d "/srv/${x}" ]; then
echo "/srv/${x}"
find /srv/${x} -mindepth 1 -type f -not -amin -10080 -exec rm {} \;
fi
done
So I tried this script replacing rm with ls
/srv/abc
/srv/abc/2015-04-20-11-multi-interval.json
/srv/abc/2015-04-20-10-mimic.json
/srv/xyz
/srv/xyz/magnetic_hadoop/fabfile.py
here i want to exclude /srv/abc which is parent dir and delete only files, So I added -mindepth 1, but still I didn't get what I want.
Then I added -not -path /srv/${x} but no difference.
Anyone know what am I missing here ?
Thanks
Upvotes: 0
Views: 49
Reputation: 176
the '-type f' means that you will get only files. and your output shows that: after the folder name which comes from the echo command, only files are shown. unless you want to leave user folders intact, you don't want the '-mindepth 1' option; it does not change the fact that '-type f'
Upvotes: 1