Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List files by last edited date

Tags:

bash

shell

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?

like image 515
Marty Avatar asked Sep 10 '09 12:09

Marty


People also ask

How do I list last modified files?

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.

What command allows you to list files sorted by when they were last modified?

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.

How do you sort files by date modified in Unix?

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'.

Does ls Show last modified?

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.


1 Answers

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.

like image 159
mipadi Avatar answered Sep 19 '22 18:09

mipadi