The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help Required: Command to find IP address and command executed of a user loggedout Security 2 08-06-2008 05:12 PM
how to? launch command with string of command line options TinCanFury Shell Programming and Scripting 5 04-28-2008 03:06 PM
inconsistent ls command display at the command prompt & running as a cron job rajranibl Linux 5 07-30-2007 05:26 AM
How to use more than one MPE command STREAM with Unix command in a single shell? bosskr HP-UX 1 10-16-2006 01:16 PM
How to use more than one MPE command STREAM with Unix command in a single shell? bosskr Shell Programming and Scripting 0 09-19-2006 06:44 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-12-2007
Registered User
 

Join Date: Apr 2007
Posts: 24
Stumble this Post!
ls command help

I was givin the task to clear up space in one of our directories. I was wondering if their was an ls command that I can search for a certain date (i.e. all files created in 2005) to display those files and then use a wildcard to delete all files created in a certain year. If so, this would make my life alot easier. I appreciate any help.

Thanks
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-12-2007
reborg's Avatar
Administrator
 
Join Date: Mar 2005
Location: Ireland
Posts: 3,513
Stumble this Post!
Take a look at the find command.
Reply With Quote
  #3 (permalink)  
Old 04-12-2007
Registered User
 

Join Date: Apr 2006
Location: Iraq
Posts: 34
Stumble this Post!
dear

you can use the find command as below to find the files that have been modified more than two days ago and delete them:
find /ect -type f -mtime +2 -exec rm -fr {} \;
for more info see the man find

regards;
The Engineer
IBM Certified Specialist
Reply With Quote
  #4 (permalink)  
Old 04-12-2007
Registered User
 

Join Date: Apr 2007
Posts: 24
Stumble this Post!
Thanks for the head start. Please any other help will be greatly appreciated.
Reply With Quote
  #5 (permalink)  
Old 04-12-2007
Registered User
 

Join Date: Apr 2007
Posts: 24
Stumble this Post!
Ooopsie, Thank you!
Reply With Quote
  #6 (permalink)  
Old 04-12-2007
Registered User
 

Join Date: Apr 2007
Posts: 24
Stumble this Post!
I see that the help you guys have givin me so far are a start. Is their not a way you can search by the YEAR instead of "how many days" a file was lost modified or accessed? Let me know either way please.

Thanks again
Reply With Quote
  #7 (permalink)  
Old 04-12-2007
awk awk is offline
Registered User
 

Join Date: Feb 2007
Posts: 115
Stumble this Post!
ls -l | awk '$8==2005{print $NF}' | xargs ls -l

will give you a long listing of all files that have 2005 in the date.

This will not work for files less than 6 months old (it shows the time, not the year in all versions of UNIX I have worked in).

Of course, you could get really fancy and use the system function in awk, but this is slightly faster.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
mtime

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:27 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0