1752548 Members
5151 Online
108788 Solutions
New Discussion юеВ

Re: Remove Files

 
Eric Jacklin
Regular Advisor

Remove Files

Hi

I want to delete the file which older then 30 days then would you please let me know the command.

Files are in /var//

OS HPUX 11.11
9 REPLIES 9
Ganesan R
Honored Contributor

Re: Remove Files

Hi,

find /var/dirname -type f -mtime +30 -exec rm {} \;
Best wishes,

Ganesh.
Suraj K Sankari
Honored Contributor

Re: Remove Files

Hi,
The file which havn't been modified in last 30-days

# find /yourpath -xdev -type f -mtime +30 -exec rm -rf {} \;

Suraj
Steven E. Protter
Exalted Contributor

Re: Remove Files

Shalom,

find has a parameter for file detection, called +mtime That means modify time.

You can also check create time with +ctime

find /location -type f -ctime +30 -exec rm {} \;

find /location -type f -mtime +30 -exec rm {} \;

This will work on files except those with open file handles on them

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
James R. Ferguson
Acclaimed Contributor

Re: Remove Files

Hi:

The number of times people equate 'ctime' to a creation time in UNIX is sad!

The 'ctime' is _NOT_ a creation time in UNIX!

Rather the 'ctime' represtents the last _change_ time for permisssions, owenerships and/or a name.

The 'ctime' _may_ coincidently be equivalent to the moment of creation (represented by the first instantiation of '-mtime'). Subsequent modifications to the file or directory's contents alter (update) the 'mtime'.

To find (and remove) files older than 30-days do:

# find /path -xdev -type f -mtime +30 -exec rm {} +

The '-xdev' prevents crossing mountpoints. The '-type f' specifies files only (not directories too). The '-mtime +30' says to look for things that are older than 30-days (where one day is 24-hours). The '-exec rm {} +' causes a 'rm' command to be run for an argument list generated. THe '+' terminator causes multiple arguments to be bundled to each command making the process run faster and spawn significantly less children (an expensive thing).

Regards!

...JRF...
Roland Piette
Regular Advisor

Re: Remove Files

Hello gourou,

I agree with all propositions. Thanks James for your detail answer. I have a question for James. With the + sign at the end of command rm wil be executed one time with all arguments given by find ! How many argument can be given to rm ?

Thanks
Dennis Handly
Acclaimed Contributor

Re: Remove Files

>How many argument can be given to rm?

Lots but it depends on the length of each one. ;-)
I'm not sure what the limit find uses. You could invoke a script to count them and their lengths.
James R. Ferguson
Acclaimed Contributor

Re: Remove Files

Hi (again):

> How many argument can be given to rm?

To add to Dennis's answer, I suspect that 'find' assembles as large a list as possible, passes the list to the command (here, 'rm') and then assembles a new list until every object is satisfied.

Before the advent of the '+' terminator for such assembly, the way to gain performance, was to do:

# find /path -xdev -type f -mtime +30 | xargs rm

THis allowed 'xargs' to perform multiple argument assembly repetively until the arguments were exhausted, for as large a list as it could handle each time.

With 'xargs' should you wish to _control_ the number of arguments you pass (which is sometimes desired), you can add the -n' switch, like:

# find /path -xdev -type f -mtime +30 | xargs -n 10 rm

...which would bundle 10 arguments together for each 'rm' process that it was necessary to spawn.

Regards!

...JRF...
Torsten.
Acclaimed Contributor

Re: Remove Files

Files are in /var//

Be very, very careful!

There are a lot of very important files under /var , even with older dates, e.g. /var/adm/sw

Manually deleting files there will corrupt your system.


Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!   
Dennis Handly
Acclaimed Contributor

Re: Remove Files

>JRF: I suspect that 'find' assembles as large a list as possible

Yes. The source says it starts with ARG_MAX (getconf _SC_ARG_MAX) around 2 Mb, then subtracts PATH_MAX and roughly the size of the current environment.