Question

I use below UNIX command to list files in order of their creation/modification. But as the directory has hundreds of files, it take few seconds to list down. but I don't want all age old files to be listed.

ls -ltr

Please provide the command for below situations.

  1. List files generated/created in last 24 hours.
  2. List down 50 latest files

Please help me with Unix commands for above 2 cases.

Was it helpful?

Solution

50 latest files:

ls -ltr | tail -50

or

ls -lt | head -50

Edit: Files modified in last day

find . -mtime -1

You could also try

ls -lt `find . -mtime -1` | head -50

But there is a problem... if find . -mtime -1 would return nothing (no file was modified in last day) you will get the last 50 files of all the time %\

OTHER TIPS

  1. List files generated/created in last 24 hours.

Use find newer or mtime parameters:

find . -newer
find . -mtime -50
  1. List down 50 latest files

Pipe through head or tail depending on the sort order you used

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top