How to list files in a Linux (Ubuntu | Debian | Centos) 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

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

Leave a Reply

Please log in using one of these methods to post your comment: 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