Techolac - Computer Technology News
  • Home
  • Internet
  • Business
  • Computers
  • Gadgets
  • Lifestyle
  • Phones
  • Travel
  • Tech
  • More
    • Automotive
    • Education
    • Entertainment
    • Health
    • SEO
    • Linux
    • WordPress
    • Home Improvement
    • How to
    • Games
No Result
View All Result
  • Home
  • Internet
  • Business
  • Computers
  • Gadgets
  • Lifestyle
  • Phones
  • Travel
  • Tech
  • More
    • Automotive
    • Education
    • Entertainment
    • Health
    • SEO
    • Linux
    • WordPress
    • Home Improvement
    • How to
    • Games
No Result
View All Result
Techolac - Computer Technology News
No Result
View All Result
Home Linux

Guide to Sort Files by Date Using LS Commandline in Linux

by Editorial Staff
November 17, 2018
in Linux
Reading Time: 3 mins read

[ad_1]

The ls command is used to list directory contents and the results can be sorted upon several criteria such as by date, alphabetical order of filenames, modification time, access time, version and file size.

In this article, I will show you how to sort files by date using ls command in Linux.

1) List Files directory with Last Modified Date/Time

To list files and shows the last modified files at top, we will use -lt options with ls command.

$ ls -lt /run
output
total 24
-rw-rw-r--.  1 root utmp 2304 Sep  8 14:58 utmp
-rw-r--r--.  1 root root    4 Sep  8 12:41 dhclient-eth0.pid
drwxr-xr-x.  4 root root  100 Sep  8 03:31 lock
drwxr-xr-x.  3 root root   60 Sep  7 23:11 user
drwxr-xr-x.  7 root root  160 Aug 26 14:59 udev
drwxr-xr-x.  2 root root   60 Aug 21 13:18 tuned

2) List Files with Last Modified Date/Time (most recent at bottom)

We will use -ltr options with ls command to list files of a specific directory with recently modified files at the bottom.

$ ls -ltr /run
$ ls -ltr /run
total 13404
drwxr-xr-x 2 root        root           4096 Dec 14  2016 scripts
-rwxr-xr-x 1 root        root           4688 Dec 14  2016 perms.py
-rw-r--r-- 1 root        root           9718 Jun 23 14:47 ddagent-install.log
-rw-r--r-- 1 root        root        1457471 Jun 26 01:26 rocket.zip
drwxr-xr-x 2 root        root           4096 Jun 26 10:40 ssl-21APR2018-11JUN2020
drwxr-xr-x 6 root        root           4096 Jun 27 09:29 incubator-pagespeed-ngx-latest-stable
drwxr-xr-x 9 root        root           4096 Jun 27 09:29 nginx-1.15.0
drwxr-xr-x 3 root        root           4096 Jul  2 19:55 rocket-nginx
-rw-r--r-- 1 root        root          18186 Jul 11 13:17 memcachy.zip
-rwxr-xr-x 1 root        root       12202195 Sep  4 12:21 Linux_64bit.install
:~#

If you want to sort by directory, then by dates use

$ ls -Rltr

3) Display in Human Readable format

We will use -halt options with ls command to list files of a specific directory in human readable file sizes, long format. It uses K, M, G, and T suffixes (or no suffix for bytes)

$ ls -halt /run
  total 28K
  -rw-rw-r--.  1 root utmp 1.9K Oct 28 06:02 utmp
  drwxr-xr-x.  3 root root   60 Oct 28 06:02 user
  drwxr-xr-x.  4 root root  100 Oct 28 03:48 lock
  -rw-r--r--.  1 root root    4 Oct 28 02:50 dhclient-eth0.pid
  drwxr-xr-x.  7 root root  160 Oct 25 12:16 udev
  drwxr-xr-x. 21 root root  600 Oct 25 12:15 .

4) Find files modified in Last 10 minutes

We can get files modified in last 10 minutes with command below:

$ find . -mmin -10 -type f -exec ls -l {} +
-rw-r--r--. 1 root root 53 Nov  1 01:58 ./smart.txt
-rw-r--r--. 1 root root 15 Nov  1 02:00 ./test/file1

5) Recently modified 10 files

Let see how to check recently modified 10 files in a directory using ls commands. We will use a combination of ‘ls” and ‘head’ command.

See also  OpenBSD install MariaDB database server

Below command will show modified 10 files with the recently updated file at the top

$ ls -lt /run/ | head -10
 -rw-rw-r--.  1 root utmp 1920 Oct 31 01:57 utmp
drwxr-xr-x.  3 root root   60 Oct 31 01:57 user
drwxr-xr-x. 16 root root  400 Oct 30 23:06 systemd
-rw-r--r--.  1 root root    4 Oct 30 18:42 dhclient-eth0.pid
drwxr-xr-x.  4 root root  100 Oct 30 03:06 lock
drwxr-xr-x.  7 root root  160 Oct 28 06:09 udev
-rw-------.  1 root root    3 Oct 25 12:15 syslogd.pid
drwxr-xr-x.  2 root root   60 Oct 25 12:15 tuned
-rw-r--r--.  1 root root    4 Oct 25 12:15 sshd.pid

Or

with tail combination, it shows recently updated file at the bottom.

$ ls -ltr /run/ | tail -10
drwxr-xr-x.  3 root root  100 Oct 25 12:15 NetworkManager
-rw-r--r--.  1 root root    4 Oct 25 12:15 sshd.pid
drwxr-xr-x.  2 root root   60 Oct 25 12:15 tuned
-rw-------.  1 root root    3 Oct 25 12:15 syslogd.pid
drwxr-xr-x.  7 root root  160 Oct 28 06:09 udev
drwxr-xr-x.  4 root root  100 Oct 30 03:06 lock
-rw-r--r--.  1 root root    4 Oct 30 18:42 dhclient-eth0.pid
drwxr-xr-x. 16 root root  400 Oct 30 23:06 systemd
drwxr-xr-x.  3 root root   60 Oct 31 01:57 user
-rw-rw-r--.  1 root utmp 1920 Oct 31 01:57 utmp

Thanks for reading this article and please comment below if you find any other options useful.

Read Also:

[ad_2]

Related Posts

Top Commands to Check the Running Processes in Linux
Linux

Top Commands to Check the Running Processes in Linux

May 27, 2022
4 Tips to Prevent and Troubleshoot the ImagePullBackOff Kubernetes Error
Linux

4 Tips to Prevent and Troubleshoot the ImagePullBackOff Kubernetes Error

March 30, 2022
How Common Signals are Used in Kubernetes Pod Management
Linux

How Common Signals are Used in Kubernetes Pod Management

November 20, 2021

Leave a Reply Cancel reply

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

30 9XMovies Alternatives To Watch Movies And TV Shows Online

30 9XMovies Alternatives To Watch Movies And TV Shows Online

August 10, 2022
Bitcoin Cloud Mining Sites

12 Best Bitcoin Cloud Mining Sites In 2022

August 9, 2022
Why did the Parag Parikh Long Term Equity Fund change its name to Parag Parikh Flexi Cap Fund?

Why did the Parag Parikh Long Term Equity Fund change its name to Parag Parikh Flexi Cap Fund?

August 9, 2022
Why Measuring Customer Experience Score Generate More Business Value?

Why Measuring Customer Experience Score Generate More Business Value?

August 9, 2022
The Key Phases for Successful Onboarding

The Key Phases for Successful Onboarding

August 9, 2022
  • DashTech
  • TechDaddy
  • Terms and Conditions
  • Disclaimer
  • Write for us

© Techolac © Copyright 2019 - 2022, All Rights Reserved.

No Result
View All Result
  • Home
  • Internet
  • Business
  • Computers
  • Gadgets
  • Lifestyle
  • Phones
  • Travel
  • Tech
  • More
    • Automotive
    • Education
    • Entertainment
    • Health
    • SEO
    • Linux
    • WordPress
    • Home Improvement
    • How to
    • Games

© Techolac © Copyright 2019 - 2022, All Rights Reserved.

Go to mobile version