Delete old files script
Hello, I'm new in Linux world. I want to figure out how to delete old files from particular folder. Can anyone help me?
My webcamera produces many photos per day and I need to delete photos which are older than five days. Can anyone help me with the script? And is there some program in linux which can execute this script every day in particular time? I have UBUNTU. thanx a lot. |
find -atime +5 -iname '*.jpg' -exec rm {} \;
you could just run that through a cronjob if you wished. |
I'd suggest using ctime instead of atime, just seems more
logical to me. |
hello,
thx for that command ctime but I have problem with that -exec. it writes me that there is missing argument for -exec. I tried to use command find -ctime +4 -iname '*.jpg' -exec rm {} thanks |
You forgot \; after the {}
Cheers, Tink |
I found command
find -ctime +4|rm *.jpg is it correct too? or does it have some side effects? thx |
You left out the xargs command after the pipe character "|".
Code:
find ./ -ctime +5 -print0 | xargs -0 -L 500 rm |
there are about 2k-3k new files per day. so sometimes I need to delete about 5k of files or more.
and there aren't whitespace characters in names of files. so what is the best solution for this case? |
How about you actually respond to Tinksters advice?? he's told you what you did wrong, but you're ignoring his advice it seems.
|
when I write there full command what Tinkers wrote it writes me still the same error.
find ctime +2 -iname '*.jpg' -exec rm {}\; find: missing argument for "-exec" but it is written in my language. :( I didn't ignoring him, I just wanna try some command and syntax I know a little bit. That was the reason why I asked to that command. |
And there's a space between {} and \; ?
Try copy and paste: Code:
find -ctime +2 -iname '*.jpg' -exec rm {} \; Cheers, Tink |
txh, that works.
|
All times are GMT -5. The time now is 04:11 AM. |