This is a discussion on filter files within the AIX Operating System forums, part of the Unix Operating Systems category; --> How can I remove files in directory which older than 2 days? How can I list files in a ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| |||
| "MadUNIX" <madunix@web.de> wrote in message news:<c4ghok$2hcihp$1@ID-172702.news.uni-berlin.de>... > How can I remove files in directory which older than 2 days? > > How can I list files in a direcory which changed last 2 days? > > Thanks find is your friend. "find . -mtime +2 -exec rm{} \;" will delete files over 48 hours old, you might want to run "find -mtime +2 -ls" first, just to be sure. "find . -mtime -2 -ls" will list files changed in the last 48 hours. Steve |
| |||
| In article <42862645.0404010543.235d8171@posting.google.com >, Steve Nottingham wrote: > "MadUNIX" <madunix@web.de> wrote in message news:<c4ghok$2hcihp$1@ID-172702.news.uni-berlin.de>... >> How can I remove files in directory which older than 2 days? >> >> How can I list files in a direcory which changed last 2 days? >> >> Thanks > > find is your friend. > > "find . -mtime +2 -exec rm{} \;" will delete files over 48 hours old, > you might want to run "find -mtime +2 -ls" first, just to be sure. > > "find . -mtime -2 -ls" will list files changed in the last 48 hours. > > Steve it is faster to do find . -mtime +2 -print | xargs rm |
| |||
| Mike <mikee@mikee.ath.cx> wrote: >> "find . -mtime +2 -exec rm{} \;" will delete files over 48 hours old, > it is faster to do > find . -mtime +2 -print | xargs rm Significantly faster ? Do you know why ?? Yves. ---- http://www.cuug.ab.ca/~dorfsmay http://www.SollerS.ca |
| |||
| In article <TsZac.6240$Pk3.4302@pd7tw1no>, no mail wrote: > Mike <mikee@mikee.ath.cx> wrote: > >>> "find . -mtime +2 -exec rm{} \;" will delete files over 48 hours old, > >> it is faster to do >> find . -mtime +2 -print | xargs rm > > Significantly faster ? > Do you know why ?? Yes, using the -exec find does an fork(2)/exec(2) for each file found. With the '| xargs', xargs knows how big the command line is and sticks as many files (read from stdin) on a single command line, then executes the lot. Anytime you can reduce the number of Chapter 2 calls, the faster your program is. |
| |||
| MadUNIX a écrit: > > How can I remove files in directory which older than 2 days? > find dir -mtime +2 | xargs rm -f HINT: to check it find dir -mtime +2 | xargs echo rm -f HINT: to control the deleted files find dir -mtime +2 | xargs rm -fe > How can I list files in a direcory which changed last 2 days? > find dir -mtime -2 (for filenames) find dir -mtime -2 -ls (for file details) > Thanks Regards, Stephane |
| ||||
| > > Mike <mikee@mikee.ath.cx> wrote: > > >> "find . -mtime +2 -exec rm{} \;" will delete files over 48 hours old, > > > it is faster to do > > find . -mtime +2 -print | xargs rm > > Significantly faster ? > Do you know why ?? > > Yves. When you call -exec, a new process is started to deal with the command. By defauld, xargs starts a process every 50 words, but it can be less ( ... | xargs -n200 rm, for example, is 1 process for 200 filenames found by find). Then it is really faster and lighter for the system point of view. Stephane |