Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete files by date

Status
Not open for further replies.

mjschroed

MIS
Jun 19, 2001
8
US
Sorry - this may be a basic question but I am new to Solaris...

I want to delete all the files in a folder that are older than a certain date. How do I do that?

Thanks in advance.
Melissa
 
Finding files by specifying
their modification time
The find command is one of the most flexible and powerful commands in the Solaris operating system. You can use it to find files with almost any search criteria and then perform operations on the files it finds. As an example, suppose you created a file in the /home/fregal directory within the last 30 days, but you can't remember the name of the file. To search for all files that were modified in the /home/fred directory within the last 30 days, use the following command:


$ find /home/fregal -mtime -30 -ok rm {}\;

if you know the file name you can specify
find / -name -mtime 30 -exec rm {}\;

Suppose, however, that you created the file more than 30 days ago. To search for files in this directory modified more than 30 days ago, simply change the -30 to +30:

$ find /home/fregal -mtime +30 -exec rm {} \;

Finally, if you somehow knew that you modified the file exactly 30 days ago, exclude the sign on the number 30 altogether to search for files modified exactly 30 days ago and delete it

$ find /home/fregal -mtime 30 -exec rm -r {}\;

for deleting

$ find /home/fregal -size 1000 -exec rm {} \;


$



.

F. regal
good luck
"think twice and hit enter once"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top