×

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

adduser Command in Linux with Examples

What is the adduser command? The adduser command creates a new user, and this command may be used to add apre-existing user to a group that already exists. How to use the...

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.

cd Command in Linux/Unix with Examples

The 'cd' command in Linux is used to change the current working directory. The command stands for "change directory" and it is used to navigate the file system on a...

3 minutes read.

netstat Command in Linux/Unix with Examples

The "netstat" command in Linux is a command-line utility that displays network connections, routing tables, and various network statistics. It is used to display the status of network connections, both...

3 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.

touch Command in Linux/Unix with Examples

The "touch" command in Linux (and other Unix-like operating systems) is used to create new empty files or update the timestamps of existing files. The touch command is a simple...

4 minutes read.

wc Command in Linux/Unix with Examples

The wc command in Linux is a command-line utility that is used to count the number of lines, words, and characters in a text file or standard input. The name...

4 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.

chown Command in Linux/Unix with Examples

The 'chown' command in Linux is used to change the ownership of a file or directory. The command stands for "change owner" and it allows you to change the user...

3 minutes read.

man Command in Linux/Unix with Examples

The man command in Linux is used to display the manual pages for a given command or system call. These manual pages provide detailed information on the command's usage, options,...

3 minutes read.

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.

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.

awk Command in Linux/Unix with Examples

The 'awk' command in Linux is a powerful text processing tool that allows you to perform various operations on text files, such as searching, replacing, and manipulating text. The command...

4 minutes read.

telnet Command in Linux/Unix with Examples

The telnet command in Linux is a command-line utility that allows you to connect to a remote host using the Telnet protocol. Telnet is a network protocol that provides a...

3 minutes read.

cp Command in Linux/Unix with Examples

The cp (copy) command in Linux is a command-line utility that is used to copy files and directories. It is one of the most basic and commonly used commands in...

5 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.

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...

5 minutes 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.

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.

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.