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 !!

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 09-27-2004
Registered User
 

Join Date: Jul 2004
Posts: 7
ls Help

I want to list files in the current directory between a date range (e.g. Sep 20-25). Is the way to do this to use ls -l and then use awk to grab the columns I want and then do a date comparision or is there an easier way?
Reply With Quote
Forum Sponsor
  #2  
Old 09-27-2004
google's Avatar
Moderator
 

Join Date: Jul 2002
Location: Atlanta
Posts: 740
Use the find command

Here are several examples:
Code:
find / -name file1 -print
find / -name '*junk*' -print
find / -name \*.o -print

find / -mtime -6 -print    < 6 days ago
find / -atime +30 -print   > 30 days ago
find / -mtime 7 -print      exactly 7 days ago
You are probably more interested in this flavor....
Code:
find  .  -type  f  -atime  +30  -print

finds files with an access time of greater than 30 days - excludes directories

find / -atime +5 \(-name "*.o" -o -name "*.tmp" \) -print

finds all files with an access time of greater than 5 days that have extension .o or .tmp

The find command is really powerful as you can search for files modifed down to an exact (well almost) time using a reference file

touch -t 03201600 /tmp/datefile
creates a file with timestamp of March 20, 4:00

find . -newer /tmp/datefile -print
find files newer than timestamp of datefile - granular to within one minute
Reply With Quote
  #3  
Old 08-25-2005
Registered User
 

Join Date: Jul 2005
Posts: 29
This was good stuff.. but what do i do to find files that are older than today and move them to another folder. today's files should be there in the directory but older ones to be moved out !!..
Reply With Quote
  #4  
Old 08-26-2005
Bughunter Extraordinaire
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,253
Quote:
Originally Posted by rosh0623
This was good stuff.. but what do i do to find files that are older than today and move them to another folder. today's files should be there in the directory but older ones to be moved out !!..
The same what google already explained:

find /your/directory -type f -ctime +1 -exec mv {} /somewhere/else \;

This will take start in "/your/directory", find all files (-type f) which creation date (-ctime) is older than today (+1) and perform (-exec) the command stated up to the "\;" for every file found that way. The name of the found file will be set in plcae of the "{}".

Best thing to learn this comand is to try it out (replace the "mv" with something less intrusive) with different parameters and see what it does.

bakunin
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 02:58 AM.


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

Content Relevant URLs by vBSEO 3.2.0