LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Delete old files script (https://www.linuxquestions.org/questions/linux-newbie-8/delete-old-files-script-636208/)

simpi 04-18-2008 06:24 AM

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.

acid_kewpie 04-18-2008 06:26 AM

find -atime +5 -iname '*.jpg' -exec rm {} \;

you could just run that through a cronjob if you wished.

Tinkster 04-18-2008 03:41 PM

I'd suggest using ctime instead of atime, just seems more
logical to me.

simpi 04-24-2008 04:22 AM

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

Tinkster 04-24-2008 04:34 AM

You forgot \; after the {}


Cheers,
Tink

simpi 04-24-2008 05:18 AM

I found command

find -ctime +4|rm *.jpg

is it correct too? or does it have some side effects?

thx

jschiwal 04-24-2008 06:00 AM

You left out the xargs command after the pipe character "|".

Code:

find ./ -ctime +5 -print0 | xargs -0 -L 500 rm
You might use this is you had a very large number of results that would cause the shell to run out of memory. The "-L 500" argument limits the number of arguments handled at once. The "-print0" argument to find used the NUL character to separate the results. The "-0" argument to xargs means to use NULs to sepatate the arguments. You would want to do this if the filenames contain whitespace characters such as spaces.

simpi 04-24-2008 06:12 AM

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?

acid_kewpie 04-24-2008 06:34 AM

How about you actually respond to Tinksters advice?? he's told you what you did wrong, but you're ignoring his advice it seems.

simpi 04-24-2008 07:03 AM

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.

Tinkster 04-24-2008 02:25 PM

And there's a space between {} and \; ?
Try copy and paste:
Code:

find -ctime +2 -iname '*.jpg' -exec rm {} \;

Cheers,
Tink

simpi 04-25-2008 02:37 AM

txh, that works.


All times are GMT -5. The time now is 04:11 AM.