Unix Technical Forum

filter files

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 ...


Go Back   Unix Technical Forum > Unix Operating Systems > AIX Operating System

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-04-2008, 10:06 PM
MadUNIX
 
Posts: n/a
Default filter files

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


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-04-2008, 10:07 PM
Steve Nottingham
 
Posts: n/a
Default Re: filter files

"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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-04-2008, 10:07 PM
Mike
 
Posts: n/a
Default Re: filter files

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-04-2008, 10:07 PM
no mail
 
Posts: n/a
Default Re: filter files

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 01-04-2008, 10:07 PM
Mike
 
Posts: n/a
Default Re: filter files

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 01-04-2008, 10:07 PM
=?iso-8859-1?Q?St=E9phane?= GASSIES
 
Posts: n/a
Default Re: filter files

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 01-04-2008, 10:07 PM
=?iso-8859-1?Q?St=E9phane?= GASSIES
 
Posts: n/a
Default Re: filter files

>
> 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 01:11 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com