Delete Old Files In Unix

Print E-mail
Programming - Unix Shell Scripts
Written by Ross Alvarez   
Tuesday, 16 May 2006 13:05

To delete old files in unix, you can execute the following command from the shell:

find <path> -mtime +30 -exec rm -f {} \;

For example, to delete all file more than 30 days older:

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


About FIND command:

NAME
find - find files

SYNOPSIS
/usr/bin/find path... expression

/usr/xpg4/bin/find path... expression

DESCRIPTION
The find utility recursively descends the directory  hierar-
chy for each path seeking files that match a Boolean expres-
sion written in the primaries given below.

find will be able to descend to arbitrary depths in  a  file
hierarchy  and  will not fail due to path length limitations
(unless a path operand specified by the application  exceeds
PATH_MAX requirements).

for more info, type "man find" from your shell.

Last Updated on Saturday, 14 March 2009 07:25
 

Networks
JoomlaHacks | Technovibe | PinoyProfessionals | MamboServe
© Ross Alvarez