×

Linux ls

The primary use case of the ls command is to list the content available in the directory. The default directory is the current directory of the user. The below screenshot shows the primary example of using the ls command on the terminal. All the content present in the home directory has been listed or printed on the terminal screen.

Linux ls

The ls command can be used in various ways with various options available. The below table explains all the options used and their significance on the terminal.

OptionExplanation
ls -aDirectories in the Linux system have various types of files. These files have several permissions and features like getting hidden. The -a option is used when we want all kinds of files available in the current directory. The hidden file nomenclature states to use a "." in the name of the file as the first character of the file name.
ls -lThe -l option in the Linux system is used when the user wants detailed information about the content present inside the current directory. Usually, the information is divided into various fields: Name, Time, Read-Write-Executable permission, Size, and Date Modification. The user can also access any specific field by using the name of the field.
ls -AThis command option is very similar to the -a option. The ls -A command is used to print all the files and folders present in the current directory; it will also include the hidden files. But it will exclude the "." and ".." directories from the list.
ls -bThis option is used for escapes. This helps in printing non-graphical characters in C-style.
  
ls -BThe ls -B option is used in the Linux system to ignore the backups. These files have ~ at the end of the file name. This lists all the files other than backups.
ls -cThis command is mainly used with the ls -lt and ls -l. This option is used for sorting by ctime or name.
ls -CThe ls -C option is used when the user wants to list or frame all the entries of the current directory by the columns.
ls -dLinux ls -d command also provides a special need feature. This feature is used to list the directory themselves, and the content present in them is not listed on the terminal.
ls -fThis command is a combination of some well-known options. This command is used when we want the functionality of showing all the files, no coloring in the output text, and even the sorting is not applied. But this is very rare when we want this kind of functionality.
ls -FThe ls -F command is used as a classifier. This command will append or add indicators like * to classify the files in the current directory.
ls -gThe ls -g command is similar to the ls -l command. But the -g will list all the information instead of the owner of the file or directory. The admin could use this to hide the owners.
ls -GThis command is used when we don’t want to print the group names during the long list with the help of ls -lG.
ls -hThe ls -h option is very user-friendly. This command is used to make the output produced human-readable with the help of color and font combinations. Mostly, this option is used with -l and -s to provide the size in a kilobyte, Megabytes, and Gigabytes.
ls -iThe ls -i command is used to provide two field lists. One is the index number of the files, and another is the name of the files. This index number is used in the internal data structure of the file system.
ls -IThe ls -I command is used to ignore any file or directory of a specified pattern. You can mention the pattern, and all the files and directories with that pattern will not be listed on the terminal screen.
ls -kThis option is used with the ls -s command. This option creates blocks of 1024 byte and displays the size in front of the file and directory.
ls -mSuppose the user requirements are to list the output of the ls command with comma-separated values. These values are files and folders present in the current directory. Initially, if you don’t use the -m option, all the files and folders would be separated by the space or tab.
ls -nWhen the requirement is to list the uid and groupid of the owner, this command is similar to ls -l, but instead of the name, the numeric values of uid and groupid are printed in the columns.
ls -NThis option is used to print the entries without the quote. In the Linux system, the files or directories with space in the name are listed with the quote. This -N option will allow you to print those files and directories without quoting.
ls -ols -o is used when the group information column is not printed on the terminal. All the other columns are the same as the -l option.
ls -pThis option is used when the user wants to append the / at the end of the directories listed using the ls command.
ls -QThe ls -Q command is used when the user wants to enclose the files and directories listed by the command into double quotes.
ls -rWhen the user wants to reverse the sorting order of the listing, all the files and folders listed will get sorted in reverse order.
ls -RThe use of ls -R provides an output of directories and subdirectories printed or listed recursively on the terminal.
ls -sThis ls -s command is used to print the size of the files and the folders present in the current directory. The size block is mentioned in front of the file or subdirectory name.
ls -SThe ls -S command is used for sorting the listing according to the size of the file or the directory. By default, this command sorts the content in decreasing order of size.
ls -tSuppose the user is required to print the output according to the modification time. This command helps list the content by modification time. The last modified file or folder will be listed first.
ls -UWhen the user wants to list the entries in the directory order without sorting them, it lists the entries in the directory order.
ls -vThis command is for sorting the entries in natural sort. For example, all the files and folders starting with capital letters will be sorted first, and then those files starting with a small letter.
ls -wThis option is used to set or limit the columns on the list. You can set the arrangement of the number of columns. To set no limit on the columns, you have to give 0 as an argument.
ls -xIf you want to list the entries or information according to the lines without using the columns, the ls -x command should be used.
ls -XThe ls -X command is used to sort the list alphabetically but based on the file’s extension.
ls -ZThis command lists some of the security context or info about the files and directories present in the current directory. If SELinux is not installed or disabled on your system, will it show? (question mark) in front of each file and directory.

Related Topics

apt-get Command in Linux with Examples

The apt-get command is a command-line tool that is used to handle packages in Linux. This command handles the processes like retrieving the packages and information from authentic sources for...

5 minutes read.

sudo Command in Linux/Unix with Examples

The sudo command in Linux is used to run a command or set of commands with the privileges of another user, typically the root user. This allows users to perform...

3 minutes read.

Linux Bash

Linux Bash In this tutorial, we are going to learn what the shell is? And how many various shells we have, we have also covered most of the bash shell features....

4 minutes read.

chmod Command in Linux/Unix with Examples

The chmod command in Linux is a command-line utility that is used to change the permissions of files and directories. It stands for "change mode" and it is used to...

4 minutes read.

Linux Distributions

Linux Distributions Linux OS is not like other operating systems. Linux can be modified according to the user’s requirements, and it is very flexible to any change. Linux distributions are often...

4 minutes read.

addgroup Command in Linux with Examples

What is the addgroup command? It is a command in Linux to create a new group using specified command lined and the system’s default values. How to add groups Adding a user group:...

4 minutes read.

How to change the ApacheHTTP port in Linux

What is an Apache HTTP server in Linux? When we talk about the most commonly used web servers, one of the web servers that cannot be missed is Apache. With the...

4 minutes read.

Linux pwd

The pwd command is used to print or display the name of the working or current directory. Some shells have their own version of the pwd with several features, in...

1 minute read.

Linux Commands with Examples

Linux Commands with Examples All the Linux commands are executed on the terminal provided by the Linux system. This terminal is a command-line interface to implement and display command outputs. Linux...

10 minutes read.

mv Command in Linux/Unix with Examples

The 'mv' command in Linux is used to move or rename files and directories. The command stands for "move" and it allows you to move files and directories from one...

3 minutes read.

addr2line Command in Linux with Examples

Use of addr2line Command The addr2line command is used to convert addresses to line numbers and file names. This command uses debugging info to check which line number and file name...

4 minutes read.

Linux cd

Linux cd: As in GUI operating systems like Windows 10, we use the mouse to travel to various folders back and forth; similarly, we have the “cd” command in Linux...

4 minutes read.

Linux Absolute and Relative Path

The concept of the absolute and relative path is very simple. The names “relative path” and “absolute path” give us little understanding of the concept we are learning here. The...

1 minute read.

ps Command in Linux/Unix with Examples

The 'ps' command in Linux is used to display information about the running processes on a system. The command stands for "process status" and it allows you to view details...

4 minutes read.

mkdir Command in Linux/Unix with Examples

The "mkdir" command in Linux (and other Unix-like operating systems) is used to create new directories. The "mkdir" command stands for "make directory" and it is used to create a...

3 minutes read.

pwd Command in Linux/Unix with Examples

The "pwd" command in Linux (and other Unix-like operating systems) stands for "print working directory." When executed, it simply displays the current directory (or folder) that the user is currently...

3 minutes read.

df Command in Linux/Unix with Examples

The 'df' command in Linux is used to display the amount of disk space available on the file system. The command reports the amount of disk space used and available...

3 minutes read.

Difference Between Unix and Linux

Unix vs Linux Unix and Linux both have been of great use in changing the world of operating systems. Unix was among the very few operating systems which were programmed for...

4 minutes read.

rm Command in Linux/Unix with Examples

The "rm" command in Linux (and other Unix-like operating systems) is used to remove files and directories. The "rm" command stands for "remove" and it is used to delete files...

4 minutes read.

Linux mkdir | Linux Create Directory

The Linux mkdir command is very much similar to Windows’s "new folder" feature. This command is used in Linux os to create new directories. The command mkdir stands for "make...

1 minute read.