Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

With ls command, does it possible to show only file created after a date, hour...

I'm asking it because I have a directory with thousand of files.

I want files created since yesterday.

I use ls -ltr but I have to see all files...

There is an equivalent of DIRECTORY/SINCE=date from OpenVMS ?

share|improve this question
    
ls lists files, but it doesn't offer much to select what files to list or the output format. Use globbing (shell wildcards) or find when you want to select files by name or metadata (e.g. date). –  Gilles Mar 24 '11 at 20:46
    
So how did the date with ls go? Did you two hit it off? –  Garrett Albright Dec 4 '13 at 0:17

2 Answers 2

up vote 26 down vote accepted

You can use the find command to find all files that have been modified after a certain number of days.

For example, to find all files in the current directory that have been modified since yesterday (24 hours ago) use:

find . -maxdepth 1 -mtime -1

Note that to find files modified before 24 hours ago, you have to use -mtime +1 instead of -mtime -1.

share|improve this answer
1  
The very thing I would have said. There's no reason to limit yourself to ls here, Luc. –  Warren Young Mar 24 '11 at 16:04
2  
With GNU find, there are other possibilities. -mmin 5 lists files modified in the last 5 minutes. -newermt "2011-02-27 13:42" lists files modified since the specified date. You can use -exec ls --color -ld {} + instead of -ls to get the usual color display (if you like colored ls output). –  Gilles Mar 24 '11 at 20:44
2  
Note the minus sign: find . -mmin -5 –  user7543 May 17 '11 at 8:32
    
and -maxdepth 1 can be increased to any n value to search files under subdirectory level too –  anshuman Sep 12 '12 at 5:42
    
This is great, except it lists the current directory . also. I had to run this through tail to strip that. Is there a way within find to chop one? –  Geoff Dec 27 '12 at 12:44
ls -ltr | grep "`date | awk '{print $2" "$3}'`"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.