ls command linux

ls Command in Linux


Commands in the GNU/Linux terminal greatly simplify any interaction with the system. Among them are frequently used ones, such as viewing a list of files, disk space, replacing characters, etc. In this article, the ls command is considered. It shows a list of files of the specified directory, as well as their additional attributes, such as the name of the owner, creation date, and others. It work is independent of the distribution.

Syntax and Parameters of ls Command

The ls command has a fairly large set of options, providing the most detailed information about system objects. The general syntax is as follows:

ls [flags] [/path/to/directory]

Square brackets mean that these parameters are not required for typing, but expand the capabilities of the command. If you enter ls without parameters, a list of file names of the current directory will be displayed, placed by columns from left to right and separated by a tab character. The size of the column is determined by the number of objects and the size of the terminal window.

ls command

Flags filter and customize the output. Many of them have short and long forms. By combining flags, short ones can be written together after one dash, while long ones are always written separately. A small list of options is presented in the table below.

Flag Description
-a, –all all files of the specified directory are shown, including hidden ones (the name of which begins with a dot “.”)
-A, –almost-all all files are displayed, including hidden ones, but links of current and previous directories are not displayed
–author creators of objects are shown; used with the detailed list option
-b, –escape object names include escape sequence
–block-size=SIZE the sizes of objects are displayed in the specified unit of measure (for example, –block-size=M indicates the size in megabytes); used with the detailed list option
-B, –ignore-backups do not show backup files; their names contain at the end the tilde symbol “~”
-c sorting objects by time (without date) of their modification or creation (ctime), starting with new ones; with the -l flag shows ctime and sorts objects alphabetically; with the -lt flag sorts by ctime and shows it
-C output in the form of columns (as without parameters)
–color[=WHEN] colors the displayed objects in different colors depending on their type; the WHEN parameter may contain the values ‘always’, ‘auto’ and ‘never’ (in many distributions the default is ‘auto’
-d, –directory output only directories without showing their contents; efficiently combined with recursive inference
-D, –dired output mode as in Emacs
-f sorting and color formatting are disabled
-F, –classify indicates the type of object in the form of adding to it one of the special characters: * / => @ |
–file-type same as –classify, but without *
–format=WORD additionally displays of the list of objects, where WORD can take one of the following values: across or horizontal (tabular view, but the output is line-by-line), commas (one line, objects separated by commas), vertical (analogue of the -C flag)
-full-time detailed information is displayed in the detailed view mode with the time in ISO format
-g detailed viewing without specifying owners of objects
–group-directories-first directories are located first, and then all other files
-G, –no-group group names are not shown
-h, –human-readable the sizes of objects are shown in an understandable and convenient way for a person
-i, –inode displayed inodes of objects
-r reverse sorting
-R recursive mapping of directories and their contents
-S sorting by size, starting from the larger
-t sort by last modified time

All flags of ls can be found on the corresponding help page.

Regarding links to the current and previous directory. They are indicated by “.” and “..” respectively and are often used, for example, when the absolute path to an object is inconvenient to indicate.

Using ls

Below are examples of using this command in combination with various parameters.

Show root directory contents:

ls /

ls command in linux

Show contents of several directories (for example, / var and /):

list only directories linux

Detailed view mode of the specified directory:

ubuntu ls

Show a list of files in the current directory, separated by commas, sorted by time and date of the last change:

linux ls options

You may also like:

Linux Alias Command The GNU/Linux terminal (namely, the Bash shell) copes with the tasks of automated system management. A user is good enough to know the shell commands ...
How to Use Bash Sort Command? One of the most useful commands in Bash — sort — is also one of the most underrated. It is engaged in sorting incoming data (whether it is a file or t...
Windows Subsystem for Linux Last time Microsoft has been actively involved in supporting the Linux kernel and GNU software components. It all started with financial assistance, a...
How to Install Google Chrome on Linux? Despite the fact that the Google Chrome is now inferior in terms of performance and privacy to the same Brave, it is still the most popular browser on...
How to Install GIT on Ubuntu and Other GNU/Linux S... GIT is a service that facilitates the work of updating various information on a remote server, also by different people. And this is not only about so...

Add Your Comment