Linux ls command is a basic command which is essential to know for all Linux users. It is used to list information of files and directories within a file system.

To use ls command, you don’t need to install any special package in your Linux machine. It is a part of GNU core utility package which is come with all distro of Linux.

The ls is very common utility, where you can’t imagine your work without using this utility. If you start working on Linux machine, be leave me within 60 min you will use this ls command uncountable numbers of time.

In this tutorial article, we will show you how to use ls command by using several examples of ls command.

Suggested Reading: Linux sed command Structure

Examples:

Example 1: List all files in Linux

The “ls” command is use to list all files and directory. You can use the “ls” command without any option to list all files and directories in the current location.

Output:

Example 2: Use ls command with option -l

You can use the “-l” option with “ls” command to display file or directory, size, modified date and time, owner or files and permission on the file, as shown below:

Output:

Example 3: Use ls to view hidden files

You can use the “ls” command to check hidden files or directories by using “-a” option, as shown below:

Output:

Example 4: Get ls command output in Human Readable format

You can use “-lh” option with the “ls” command to get the size of files and directories in a human-readable format, as shown below:

Output:

Example 5: List files and Directories with ‘/’ Character at the end

When you use the “-F” option with the “ls” command, it will add the “/” character at the end of each directory.

Output:

Example 6: List Linux files in Reverse Order

The “ls” command with the “-r” option use to display files and directories in reverse order.

Output:

Example 7: List out Sub-Directories recursively

You can display sub-directories in a recursive list by using the “ls” command with the “-R” option, as shown below:

Output:

Example 8: Reverse ls command output order

You can use the “-ltr” option with ls command to show the latest modification file or directory date as last, as shown below:

Output:

Example 9: Sort ls command output with File Size

You can sort the ls command output by the size of files and big size file display first by using the “-ls” option, as shown below:

Output:

Example 10: Display inode number of file using ls

You can also find the inode number of file and directory by using ls command with the “-i” option, as shown below:

Output:

Example 11: List Directory information

You can use the path of a directory with ls command to get the information of the directory to list out the files and directory available with a given directory, as shown in the below example to display files and directory.

Output:

Example 12: Display UID and GID of files using ls

You can display UID and GID of files and directories using the “-n” option with ls command.

Output:

Example 13: ls command and its Aliases

You can have made an alias for ls command when you execute ls command; it will take the “-l” option by default and display long listing as mentioned earlier.

Output:

You can see the number of alias available in your system by using the “alias” command, as shown below:

Output:

To remove previously defined an alias, use the unalias command as shown below:

Output:

Example 14: Show version of ls command

You can check the installed “ls” command utility version using the “–version” option, as shown below:

Output:

Example 15: Show ls help page

Check the help page for the “ls” command using the “–help” option.

Output:

If You Like What We Do Here On LinuxConcept, You Should Consider:

Stay Connected to: Twitter | Facebook

Subscribe to our email updates: Sign Up Now

 

We are thankful for your support.

Follow me

SATISH KUMAR

I am Satish Kumar, Founder of LinuxConcept. Linux and F.O.S.S enthusiast, love to work on open source platform and technologies.
Follow me