Bash: How to List All Files in Folder by Date


Often you may want to use Bash to list all files in a directory based on their last modified date.

You can use the following syntax to do so:

ls -lRt

This particular syntax will return all files in the current directory in order based on most recently modified.

Here is what the various commands do:

  • ls: List all contents in directory
  • -l: Use list format
  • -R: List files by recursively moving down each subfolder
  • -t: Order files by datetime modified

Note that if the current directory contains subfolders then the files will be shown in order, grouped by subfolder.

To show all files by date without grouping them by subfolders, you can use the following syntax:

find . -type f -printf "%-.22T+ %M %n %-8u %-8g %8s %Tx %.8TX %p\n" | sort | cut -f 2- -d ' '

The following example shows how to use each of these methods in practice.

Example: How to List All Files in Folder by Date

We can use the following syntax to simply view all files in the current directory:

ls -lR

The following screenshot shows how to use this syntax in practice:

Note that this returns all files in the current folder, but the files are simply shown in alphabetical order by default.

To instead show the files in order based on the date and time when they were last modified, we can use the following syntax:

ls -lRt

The following screenshot shows how to use this syntax in practice:

Bash list all files by date

Notice that the files and folders are now in order based on when they were last modified.

However, the files are still grouped based on subfolders.

To simply show all files in order based on when they were last modified, regardless of subfolder, we can use the following syntax:

find . -type f -printf "%-.22T+ %M %n %-8u %-8g %8s %Tx %.8TX %p\n" | sort | cut -f 2- -d ' '

The following screenshot shows how to use this syntax in practice:

Bash list all files by last modified date

Notice that this shows all files in the current directory, including all files in subfolders, in order based on when they were last modified.

Related Tutorials

The following tutorials explain how to perform other common tasks in Bash:

Bash: How to List All Files in Folder by Size
Bash: How to List All Files in Folder Without Extension
Bash: How to List All Files Matching a Specific Pattern

Leave a Reply