The ls command is one of the more basic commands in Linux. It is designed to list the names and features of files and directories. It can be used for a single file or as many as all files and folders in a selected set of directories.
Synopsis: ls [option]… [file]…
ls Command Options
To use the ls command, you can open a terminal window and run it, also the “man” command will provide the manual on how to use the ls command.
You should see results similar to this, you can scroll down the terminal window to view more details.
Below is a list of the options that can be used with the ls command in Linux. You can use more than one at a time, making the command more efficient for your needs.
|Lists all files including those that begin with .
|Lists all files except . and ..
|print octal escapes for nongraphic characters
|does not list implied entries ending with ~
|with -lt: sort by, and show, ctime (time of last modification of file status information) with -l: show ctime and sort by name otherwise: sort by ctime
|list entries by columns
|list directory entries instead of contents, and do not dereference symbolic links
|generate output designed for Emacs in dired mode
|do not sort
|append indicator (one of */=>@|) to entries
|Works like -l (long list) but does not display owner.
|Works like -l (long list) but does not group names.
|when used with -l (long list), prints sizes in human readable format (e.g., 1K 234M 2G)
|follow symbolic links listed on the command line
|print the index number of each file
|do not list implied entries matching shell PATTERN
|Displays entry size in kilobytes (rounded up). Long name allows to set block size.
|Displays entries in a long list format.
|when showing file information for a symbolic link, show information for the file the link references rather than for the link itself
|fills the width of the terminal with a comma separated list of entries
|like -l (long list), but lists numeric user and group IDs instead of name
|prints raw entry names (does not treat e.g. control characters special)
|like -l, but do not list group information
|appends a / indicator to directories
|print ? instead of non graphic characters
|display entries enclosed in double quotes
|reverse order while sorting
|lists all subdirectories recursively
|print the allocated size of each file, in blocks
|displays entries sorted by filesize
|sort by modification time
|assume tab stops at each column instead of 8
|with -lt: sort by, and show, access time. with -l: show access time and sort by name. otherwise: sort by access time
|do not sort; list entries in directory order
|natural sort of (version) numbers within text
|assume screen width instead of current value
|list entries by lines instead of by columns
|sort alphabetically by entry extension
|list one file per line
|Display security context so it fits on most displays. Displays only mode, user, group, security context and file name.
ls Command Examples
Now that you have been introduced to the ls command, we’ll show you how to use it.
The ls Base Bommand
This example displays the base command with no switches or parameters. Note the files and folders are displayed in a row. Directories display in blue and have a trailing slash. You can use the cd command to change to a different folder or directory.
The results will look similar to this, but keep in mind it will differ based on your specific files:
./ ../ error_log images/ index.php testfile.txt
Using the Long List Option
One of the more common switches, the long listing (-l) displays much more data than the base command. It displays the permissions, the owner, group, size, date last modified, and the name of the file.
drwxr-xr-x 3 root root 4096 Jun 3 10:19 ./
drwxr-x--- 25 root root 4096 Jun 3 10:16 ../
-rw-r--r-- 1 root root 12523 May 5 13:29 error_log
drwxr-xr-x 2 root root 4096 Jun 3 10:19 images/
-rw-r--r-- 1 root root 52 May 5 13:29 index.php
-rw-r--r-- 1 root root 0 Jun 3 10:15 testfile.txt
List All Files Including Hidden
If you want to view all the files including ones that are hidden such as the .htaccess you can use the all option.
You will then see all of your files listed, including hidden files.
. .cache .dmrc .gconf .gnupg .htaccess .ICEauthority
.local .putty test.txt .var .wget-hsts .zoom
Congratulations, you should now know the basics of using the ls command in Linux. We recommend bookmarking our Linux section for future reference.