Files delete script!

Taking care of your Linux box.
refra
Naik
Posts: 69
Joined: Wed Dec 06, 2006 3:51 pm

Files delete script!

Postby refra » Tue Jul 14, 2009 1:08 pm

AOA


My files are:

1-090712
1-090713
1-090714
2-090712
2-090713
2-090714
3-090712
3-090713
3-090714
4-090712
4-090713
4-090714



Now i want to delete a 2 days old files means all files of 090712

lambda
Major General
Posts: 3452
Joined: Tue May 27, 2003 7:04 pm
Location: Lahore
Contact:

Postby lambda » Tue Jul 14, 2009 9:07 pm

read the man page for "find" carefully.
Watch out for the Manners Taliban!
Isn't it amazing how so many people can type "linuxpakistan.net" into their browsers but not "google.com"?

LinuxFreaK
Site Admin
Posts: 5132
Joined: Fri May 02, 2003 10:24 am
Location: Karachi
Contact:

Re: Files delete script!

Postby LinuxFreaK » Mon Jul 20, 2009 8:40 am

Dear refra,
Salam,

refra wrote:My files are:

1-090712
1-090713
1-090714
2-090712
2-090713
2-090714
3-090712
3-090713
3-090714
4-090712
4-090713
4-090714

Now i want to delete a 2 days old files means all files of 090712


You can use find for this purpose.

# find -type f -name "*-09712" -atime +1 -print0 | xargs -0 rm -f

FYI,

-atime n
File was last accessed n*24 hours ago. When find figures out how many 24-hour periods ago the file was last accessed, any frac-
tional part is ignored, so to match -atime +1, a file has to have been accessed at least two days ago.


Best Regards.
Farrukh Ahmed

ranatanveer
Subedar
Posts: 355
Joined: Sat May 07, 2005 11:54 am
Location: Lahore
Contact:

Postby ranatanveer » Thu Jul 30, 2009 4:53 am

and also better if you google "regex"
Regards

Rana Tanveer
+923224194457
Linux Student

For Affordable Web Development http://www.affordableprogrammers.com
http://www.qualityprogrammers.com


Return to “Administration”

Who is online

Users browsing this forum: No registered users and 2 guests