The ls command is one of the most frequently used commands in Linux and Unix-like operating systems. It lists the contents of a directory, and when used with various options, it can provide detailed information about files, including permissions, ownership, size, and modification dates. This article delves into the ls command’s long listing format output and how to interpret permission bits.
In this tutorial you will learn:
- How to use the
lscommand with the long listing format option - How to interpret the permission bits in the output

| Category | Requirements, Conventions or Software Version Used |
|---|---|
| System | Any Linux or Unix-like system |
| Software | ls command (part of the GNU core utilities) |
| Other | Basic understanding of command line usage |
| Conventions | # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command$ – requires given linux commands to be executed as a regular non-privileged user |
Using the ls Command with the Long Listing Format
The ls -l command is used to display files and directories in a long listing format. This format provides detailed information, including file permissions, number of links, owner, group, file size, and the last modified date and time.
- Basic Usage of ls -l: The basic usage of the
lscommand with the long listing format option.$ ls -l
This command lists all files and directories in the current working directory with detailed information. Each line of the output corresponds to a single file or directory, providing a wealth of information in a structured format.
For example:
$ ls -l total 16 drwxr-xr-x 2 user group 4096 May 25 10:45 dir1 -rw-r--r-- 1 user group 123 May 25 10:45 file1
In this output:
–drwxr-xr-xshows the file type and permissions.
–2indicates the number of links.
–useris the owner of the file.
–groupis the group associated with the file.
–4096is the file size in bytes.
–May 25 10:45is the last modification date and time.
–dir1andfile1are the names of the directory and file, respectively.Understanding Permission Bits: An introduction to understanding the permission bits displayed by the
ls -lcommand.$ ls -l
The first column in the
ls -loutput shows the file type and permissions. The first character indicates the file type:
–-for a regular file
–dfor a directory
–lfor a symbolic linkThe next nine characters are grouped into three sets of three, representing the permissions for the owner, group, and others:
–rstands for read permission
–wstands for write permission
–xstands for execute permissionFor example:
-rw-r--r--
This indicates a regular file with:
– Read and write permissions for the owner
– Read permission for the group
– Read permission for others - Changing Permissions: How to change file permissions using the
chmodcommand.$ chmod 755 file1
This command changes the permissions of
file1torwxr-xr-x, which means:
– The owner has read, write, and execute permissions
– The group has read and execute permissions
– Others have read and execute permissionsTo verify the change:
$ ls -l file1
- Recursive Listing: Using the
-Roption withlsto list directories and their contents recursively.$ ls -lR
This command lists the contents of directories recursively, providing a comprehensive view of all files and subdirectories within the specified directory.
For example:
$ ls -lR .: total 4 drwxr-xr-x 2 user group 4096 May 25 10:45 dir1 -rw-r--r-- 1 user group 123 May 25 10:45 file1 ./dir1: total 0 -rw-r--r-- 1 user group 0 May 25 10:45 file2
This output shows that
dir1contains another file namedfile2. - Listing Hidden Files: How to list hidden files using the
-aoption.$ ls -la
Hidden files in Linux are those whose names start with a dot (.). They are not displayed by default. The
-aoption reveals these hidden files.For example:
$ ls -la total 20 drwxr-xr-x 3 user group 4096 May 25 10:45 . drwxr-xr-x 5 user group 4096 May 25 10:45 .. -rw-r--r-- 1 user group 123 May 25 10:45 .hiddenfile drwxr-xr-x 2 user group 4096 May 25 10:45 dir1 -rw-r--r-- 1 user group 123 May 25 10:45 file1
This output shows all files, including the hidden file
.hiddenfile. - Sorting Files: How to sort files by modification time using the
-toption.$ ls -lt
The
-toption sorts files by modification time, with the most recently modified files appearing first.For example:
$ ls -lt total 16 -rw-r--r-- 1 user group 123 May 25 10:45 file1 drwxr-xr-x 2 user group 4096 May 24 09:30 dir1
This output shows
file1listed beforedir1because it was modified more recently.
Conclusion
Understanding the ls command and its long listing format is essential for managing files and directories in Linux. By mastering the various options and interpreting the output, you can efficiently navigate and manipulate the file system. This tutorial has covered the basic usage, permission bits, and some useful options of the ls command to enhance your command line proficiency.