DbAppWeb.com

Menu
  • Home
  • Linux
  • HP-UX
  • macOS
  • Windows
  • Web Servers
  • App Servers
  • Storage

How to sort the directories in Linux/RHEL

April 12, 2017 DbAppWeb Admin

Sort the directories in Linux/RHEL

Generally, we sort the list of the directory in ascending/descending order of the date/time but sometimes we need to sort the list of directories on the basis of the group or owner. Use the below commands to sort the list of directories in different ways.

  • ls -l | awk '{print $3, $4, $8, $0}' | sort | column -t
    added the $8 and the column -t for pretty print
  • ls -l | sort -k 3 – sorts by owner and by default sorts the next field (group) and on
  • ls -l | sort -k 4,4 -k 3 – sorts by group and then by owner
  • ls -l | sort -k 3,3 -k 8 – sorts by owner and then by filename
[user@server ~]# ls -l | sort -k 4,4 -k 3
total 2118560
-rw-rw-r-- 1 root       apache        4841403 Jan  9  2017 PKIServer.zip
-rw-r--r-- 1 root       apache           6144 May 25 09:58 frm.css
-rw-r--r-- 1 root       root         20441395 Dec  5  2016 access_log
-rw-r--r-- 1 root       root        243035185 Dec 11  2016 access_log.4_83
-rw-r--r-- 1 root       root          8347982 Dec  5  2016 error_log
-rw-rw-r-- 1 sonu.patel sonu.patel      13507 Aug 10 16:38 home_error.html
drwxrwxr-x 2 sonu.patel sonu.patel       4096 Nov 23  2016 new_ssl_web02

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Telegram (Opens in new window)
  • Click to share on WhatsApp (Opens in new window)
Prev Article
Next Article
Tags:Linux Sys Admin

Leave a Reply Cancel Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • Popular
  • Recent

Categories

  • Android (2)
  • Blogger (16)
  • Domain and Hosting (1)
  • Hardware Issues (7)
  • HP-UX (55)
  • HPE Data Protector (9)
  • IBM Lotus Notes (2)
  • IBM WebSphere Application Server (16)
  • Internet Tips & Tricks (15)
  • iOS (8)
  • JBoss/WildFly Application Server (2)
  • Linux (76)
  • macOS (15)
  • Microsoft Windows (31)
  • News and Updates (11)
  • Oracle Database (5)
  • SSL/TLS (1)
  • Storage Servers (23)
  • Tools/Softwares (1)
  • VMware ESXi (17)
  • Web Servers (14)
  • WordPress (5)

Archives

DbAppWeb.com

Solution of Database, Application and Web Server Problems

About DbAppWeb.com

One Stop Solution for Database Server, Application Server and Web Server Problems.

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

DbAppWeb on Social Media

Copyright © 2025 DbAppWeb.com
Terms and Conditions   Theme by MyThemeShop.com