How To Sort Directories First in the Linux Terminal

1. Code Used

1: ls --color -h --group-directories-first

2: alias p='ls --color -h --group-directories-first'

2. Example

Usually, when you type a simple ls command in the bash terminal your files will be displayed alphabetically:

cs_1_1

If you want your files sorted with the directory listings first, you can use the following command:

ls --color -h --group-directories-first

This gives the following result:

cs_1_2

Given that this is a pretty long command to type in constantly, you might set it as an alias:

alias p='ls --color -h --group-directories-first'

Now you can type ls for the regular (alphabetic) listing and p for the directories-first listing:

cs_1_3



Categories: Computer

Tags: , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s