This is really quick, really simple, and really useful.
It’s often helpful to see which files in a directory have been modified the most recently, For example, which logfiles have been written to recently?
A very simple command would be:
$ ls -lt | head
The ls
lists the files; the -l
gives a long listing with more detail; the -t
sorts files by their last modified time, newest first, and finally piping the result through head
shows only the first 10 lines of the output.
For convenience, I define this in my ~/.bash_profile
:
alias new='ls -lt|head'
Now, simply typing new
at the command prompt shows me the newest files in the current directory. Try it: you’ll use it more than you think.
Could This Linux Tip Be Improved?
Let us know in the comments below.
I generally do it the other way round …
‘ls -lrt | tail’ or just ‘ls -lrt’ which leaves the most recently used files listed in my terminal