Red Hat Linux Ls Command Training – How Run the Ls Command With Examples

Red Hat Linux – Using the Linux ls Command to List the Contents of A Directory

The Linux ls command is one of the most commonly used commands. It is used to list the contents of a directory and show the files and other directories in a directory.

In the Windows world, a Linux directory is called a Windows folder.

There are lots of options that can be used with the ls command to see different information on the files and directories that are in a directory.

Running the Linux ls Command with Examples of Options

You can run the following Linux ls command examples at the command line prompt to get real, practical commands training experience!

Linux Commands Training Tips: When you run the ls commands below, with the examples of ls command options and parameters, don’t type in the $ (dollar sign) prompt. Just type in the commands shown at the right of the $ sign.

Run the ls command without any options to see the contents of the current directory.

    $ ls

Run the ls command with the -l option for “long” option to see a longer and more detailed listing of the current directory.

    $ ls -l

Now run the command below and add the -a option to show “all” files (which will cause the normally hidden files to appear) in the current directory.

    $ ls -la

The ls command below shows the contents of the root directory. Many of the directory names that appear in the / (root) directory are common to all Linux distros. Notice that a directory named sbin (for superuser binaries) appears.

    $ ls /

Now list the contents of the sbin directory.

    $ ls /sbin

Now get a “long” listing of the sbin directory.

    $ ls -l /sbin

The next ls command shows the contents of sbin sorted by size (due to the upper case S option), with the largest file at the top. You can see the size of items in the fifth column from the left. And you can click on the scroll bar on the right side of the terminal emulation window to scroll up!

    $ ls -lS /sbin

Now see the files in reverse order, due to the -r option.

    $ ls -lSr /sbin

And now add the h option for “human readable” to cause a file with a size of 7,169 to appear as 7k.

    $ ls -lSrh /sbin

The ls command is one of the GNU Linux commands, which are the “core” Linux commands that are common to ALL Linux distributions.

By learning the GNU Linux commands, you learn how to use ALL Linux versions!