I have a directory: /home/user/
How can I list every file in this directory (including those in sub directories) and order them by the date that they were last modified?
You can use the ls command to list files including their modification date by adding the -lt flag as shown in the example below. The flag -l is used to format the output as a log. The flag -t is used to list last modified files, newer first.
The 'ls' command lists all files and folders in a directory at the command line, but by default ls returns a list in alphabetical order. With a simple command flag, you can have ls sort by date instead, showing the most recently modified items at the top of the ls command results.
In order to ls by date or list Unix files in last modifed date order use the -t flag which is for 'time last modified'. or to ls by date in reverse date order use the -t flag as before but this time with the -r flag which is for 'reverse'.
The ls command also allows you to check the last modification date of a file individually; for this, just specify the file's name as shown below. As you can see, this output is more user-friendly if you only want to check a single file.
You can use:
ls -Rt
where -R
means recursive (include subdirectories) and -t
means "sort by last modification date".
To see a list of files sorted by date modified, use:
ls -l -Rt
An alias can also be created to achieve this:
alias lt='ls -lht' lt
Where -h
gives a more readable output.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With