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 Is

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.

Options Explanation
ls -a Directories 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 -l The -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 -A This 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 -b This option is used for escapes. This helps in printing non-graphical characters in C-style.
ls -B The 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 -c This command is mainly used with the ls -lt and ls -l. This option is used for sorting by ctime or name.
ls -C The ls -C option is used when the user wants to list or frame all the entries of the current directory by the columns.
ls -d Linux 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 -f This 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 -F The 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 -g The 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 -G This command is used when we don’t want to print the group names during the long list with the help of ls -lG.
ls -h The 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 -i The 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 -I The 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 -k This 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 -l The ls -l command is used to list the information. But this listing is a long listing with details.
ls -m Suppose 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 -n When 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 -N This 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 -o Ls -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 -p This option is used when the user wants to append the / at the end of the directories listed using the ls command.
ls -Q The ls -Q command is used when the user wants to enclose the files and directories listed by the command into double quotes.
ls -r When the user wants to reverse the sorting order of the listing, all the files and folders listed will get sorted in reverse order.
ls -R The use of ls -R provides an output of directories and subdirectories printed or listed recursively on the terminal.
ls -s This 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 -S The 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 -t Suppose 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 -U When the user wants to list the entries in the directory order without sorting them, it lists the entries in the directory order.
ls -v This 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 -w This 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 -x If you want to list the entries or information according to the lines without using the columns, the ls -x command should be used.
ls -X The ls -X command is used to sort the list alphabetically but based on the file’s extension.
ls -Z This 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.