The ls command accepts a directory name as an argument. It lists the content of the specified directory. It supports many options. Options allow us to modify the default output.
By default, the ls command lists only the names of the files and directories. It does not provide any additional detail about them. If we need more information about the files and directories, we use the -l option with the ls command.
The ls -l command provides detailed information about files and directories stored in the specified directory. It formats the output in columns.
The first column shows the resource type. It uses a letter to indicate the resource type. The following table lists the resource type.
Letter | Description |
l | It is a symbolic link to another file or directory. |
d | It is a directory. |
- | It is a regular data file. |
b | It is a block device such as a hard disk. |
c | It is a character device such as a terminal. |
The second column shows a sequence of nine characters. These characters define the permission of the resource. A resource can have three types of permission: Read, Write, and Execute. For each permission type, it uses a letter. It uses the letter r for read, w for write, and x for execute permission.
Linux divides users into three groups: owner, group, and other. For each user type, it defines all three types of permission. To define three types of permissions for three types of users, it uses 3 x 3 = 9 characters. The first three characters belong to the owner, the next three characters represent the group, and the last three characters belong to other users.
It uses a hyphen (-) in place of a letter to indicate no permission for a specific operation on the file. For example, if you see the letters rwxrw-r-- in this field, it means the owner can read (r), write (w), and execute (x) the file. The group users can read (r) and write (w) the file, but they cannot execute (-) the file. Other users can only read (r) the file. They cannot write (-) and execute (-) the file.
- The next column shows the number of links the resource has.
- The next column shows the name of the owner and group.
- The next column shows the file size in bytes.
- The next column shows the date and time when the file was last modified.
- The last column shows the name of the resource.
By default, the ls command does not show the hidden files. If you want to view hidden files with regular files, you need to use the -a option. A hidden file starts with a dot.
#ls -la
By default, the ls -l command displays the file size in bytes. If you want to view the file size in a human-friendly format, you need to use the -h option with it.
#ls -lh
That's all for this tutorial. In this tutorial, we learned how to use the ls -l command and read its output.