ls -alt: How to list/get last modified files from current directory or any other specific directory in Linux

The ls command lists the contents of, and optional information about, directories and files. ls without option lists the files contained in the current directory, sorting them alphabetically.

By using the below command, you can list the last modified files from the current directory or form any other directory.

From current directory

Syntax:

# ls -alt | head -n

[number of files to be listed]

-a do not ignore entries starting with .
-l list one file per line. Avoid ‘\n’ with -q or -b
-t sort by modification time, newest first

Example:

To list last 10 modified files:

# ls -alt | head -n 10

To list last 20 modified files:

# ls -alt | head -n 20

To list last 55 modified files:

# ls -alt | head -n 55

From another directory

Syntax:

# ls -alt

[Folder path]

 | head -n

[number of files to be listed]

-a do not ignore entries starting with .
-l list one file per line. Avoid ‘\n’ with -q or -b
-t sort by modification time, newest first

Example:

To list last 10 modified files:

# ls -alt /home/gowri/Documents | head -n 10

To list last 20 modified files:

# ls -alt /home/gowri/Documents | head -n 20

To list last 55 modified files:

# ls -alt /home/gowri/Documents | head -n 55

You Might Also Like

Leave a Reply

Your email address will not be published. Required fields are marked *