ls command is one of the most frequently used command in Linux. It stands
for 'list', and as the name suggests, it's used to list the contents of a
directory. This tutorial will walk you through the basic usage of
as well as some of its powerful options.
The simplest form of
ls command is to run it without any options. Open your
terminal and type:
ls --options arguments
This command will list the contents of the current directory.
ls Command Options Table
|Do not ignore entries starting with .|
|Do not list implied [Current Directory] and .. [Parent Directory]|
|Use a long listing format to display the information|
|Display file size in human readable format (KB, MB, etc.)|
|Sort by modification time, newest first|
|Reverse order while sorting|
|List subdirectories recursively|
|Append / indicator to directories|
|Append indicator (one of */=>@ ) to entries|
|Sort by file size, largest first|
|List directories themselves, not their contents|
Again, please note that the long options may not work in some systems, but the short options are universally supported in all Unix-like systems.
Listing Contents of Other Directories
You can also use
ls to list contents of any other directory. To do so, you
just need to provide the path of that directory:
ls Command Options
ls command has a number of options that can be used to modify the output.
-l (lowercase 'L') option stands for 'long format', which includes
additional information such as permissions, number of links, owner, group, size,
and time of last modification:
-a option stands for 'all'. By default, files that start with a dot (.)
are hidden. If you want to display these files, use the
-h option stands for 'human-readable'. It displays file size in KB, MB,
etc., which is easier to comprehend than bytes:
-t option sorts the output by modification time, newest first:
-r option reverses the order of sort:
This will list the files and directories sorted by modification time, oldest first.
Displaying Directories Recursively
-R (uppercase 'R') option stands for 'recursive'. It displays the contents
of directories recursively:
Listing Files by File Type
-p option appends a character to each entry indicating the file type. For
instance, a slash (/) is appended to directories:
-F option classifies files by outputting a character at the end of each.
This will add a
/ at the end of directories,
* at the end of executable
@ at the end of symbolic links, etc.:
Listing Files Based on Pattern
You can list files based on a specific pattern. For example, if you want to list all the text files, you can do so by:
ls is a powerful command with numerous options. The examples above
only scratch the surface. To learn more, you can always refer to the
page by typing
man ls in your terminal. The manual page provides a
comprehensive list of all available options.
Level Up Your TypeScript And Object Oriented Programming Skills. The only complete TypeScript course on the marketplace you building TypeScript apps like a PRO.SEE COURSE DETAILS
What Can You Do Next 🙏😊
If you liked the article, consider subscribing to Cloudaffle, my YouTube Channel, where I keep posting in-depth tutorials and all edutainment stuff for ssoftware developers.