5 Different Ways to List Files on a Linux Server

On your desktop or laptop computer, viewing files is usually as simple as clicking an icon.  Most file managers also have sorting features so that you can view your files in columns, grouped by type, and numerous other variants.

On a Unix or Linux dedicated server, you do not have this luxury.  While you can install a control panel that comes with a file manager or use a visual text interface like Midnight Commander, there are times when it is easiest and most efficient to use the simple “ls” command.  The following are five different ways you can use “ls” to display your files.

1. ls -t
When you need to know which files in a directory are the most recent, the “-t” option will sort files by modification time, showing the file that was edited last at the beginning.

2. ls -l
To display all information about files and directories, use the “-l” option.  It will show file permissions, number of links, file owner, group, size, modification date and time, and the file name.  Output will look like this:

drwxr-xr-x  3 root    root      4096 2011-04-29 22:01 ufw

3. ls -a

On Unix-like operating systems, files with a period in front of their names are hidden. Often times, these are configuration files, especially those kept in a user’s home directory. Using the “-a” option, you can view any hidden files in a directory.

4. ls -R
Use the “-R” option to list files recursively.  That means it will display all of the files in the directory you specify as well as the contents of any sub-directories in the tree.  Here is a sample output:

after6.rules  after.rules  applications.d  before6.rules  before.rules  sysctl.conf  ufw.conf

cups  openssh-server  samba

5. ls –color=auto

Many Linux files do not have file extensions, so it can sometimes be difficult to tell what is a file and what is a directory.  Using colors, you can display directories as blue, regular files as the default color (usually black), and commands as green.