ls -1t | head -n10

find the 10 latest (modified) files

order the files by modification (thanks stanishjohnd) time, one file per output line and filter first 10

7
By: wires
2009-06-23 12:15:12

These Might Interest You

  • Sorts by latest modified files by looking to current directory and all subdirectories Show Sample Output


    1
    find . -name '*pdf*' -print0 | xargs -0 ls -lt | head -20
    fuats · 2013-10-03 21:58:51 0
  • This oneliner gets all the 'modified' files in your git repository, and opens all of them in vim. Very handy when you're starting to work in the morning and you simply want to review your modified files before committing them. Maybe there are better ways to do that (and maybe integrated in vim and/or git, who knows), but I found quicker to do this oneliner.


    0
    vim `git status | grep modified | awk '{print $3}'`
    TetsuyO · 2012-11-19 09:48:46 2
  • I have a directory containing log files. This command delete all but the 5 latest logs. Here is how it works: * The ls -t command list all files with the latest ones at the top * The awk's expression means: for those lines greater than 5, delete.


    -2
    ls -t | awk 'NR>5 {system("rm \"" $0 "\"")}'
    haivu · 2009-09-16 04:58:08 0
  • to download latest version of "util", maybe insert a sort if they wont be shown in right order. curl lists all files on mirror, grep your util, tail -1 will gets the one lists on the bottom and get it with wget Show Sample Output


    4
    mirror=ftp://somemirror.com/with/alot/versions/but/no/latest/link; latest=$(curl -l $mirror/ 2>/dev/null | grep util | tail -1); wget $mirror/$latest
    peshay · 2009-08-24 15:58:31 0
  • zsh only If you have this command in your history, you can always re-run it and have it reference the latest file. The glob matches all timestamped files and then the resulting array is sorted by modification time (m) and then the first element in the sorted array is chosen (the latest)


    5
    tail -f /path/to/timestamped/files/file-*(om[1])
    karld · 2009-02-16 22:55:16 0
  • Filter output with default cvs update status (not only modified files 'M')


    0
    cvs up 2>&1 | grep --color 'U \|P \|A \|R \|M \|C \|? '
    RapazP · 2010-06-30 11:43:06 0

What Others Think

-t means sort by modification time. FYI, the last accessed time and last modified time are the only times saved on a traditional UNIX file system.
stanishjohnd · 464 weeks and 5 days ago
Further, some filesystems are mounted with the 'noatime' option set for improved performance and so access times are not recorded. If you really only want to scroll your terminal 10 lines then the command as above is the way to go, but I usually just type: ls -ltr so that the most recently modified/accessed files are at the bottom of the list.
bwoodacre · 464 weeks and 5 days ago
@stanishjohnd: thanks, i've updated the command @bwoodacre: thanks, but I tend to use this in scripts
wires · 464 weeks ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: