How to list files in a Linux directory CLI

This is a quick reference guide on how to list files in a directory on Linux Based Operating Systems.

The ls command list files and directories within a directory in alphabetical order.

root@VPS:/etc/ssh# ls
moduli                  ssh_host_ed25519_key      ssh_import_id
ssh_config      sshd_config
ssh_host_ecdsa_key      ssh_host_rsa_key          sshd_config.ucf-dist

The ls -a command includes all files including hidden files.

root@VPS:/etc/ssh# ls -a
.             ssh_import_id
..                  ssh_host_ed25519_key      sshd_config
moduli      sshd_config.ucf-dist
ssh_config          ssh_host_rsa_key

The ls -X will sort by file extension.

ls -X 
-X                         sort alphabetically by entry extension

The ls -R will display the sub-directories of the directories.

ls -R
-R, --recursive            list subdirectories recursively

The ls -l will display detailed information about files.

ls -l
 -l                         use a long listing format

To check all the options available use the help command.

ls --help

If you are new to the world of Linux, an avid Linux enthusiast or a student why not try our 0.99p per month Linux VPS.

Simply click on the screen shot below to find out more or navigate to

Thank you for reading and please feel free to leave any feedback.

Leave a Reply

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

You are commenting using your 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