Introduction to the ls
Command in Linux

The ls command in Linux is one of the most fundamental and frequently used commands, serving as a powerful tool for file and directory management. Whether you’re a beginner or an experienced user, understanding how to effectively use the ls
command is essential for navigating the Linux file system. This command allows you to list files and directories, providing a quick overview of the contents within a specified location.
In this article, we will delve into the ls command in Linux in detail, exploring its various options and functionalities. From displaying hidden files to sorting output by size or date, we’ll cover everything you need to know to make the most of this essential command. By the end of this guide, you’ll be equipped with the knowledge to navigate your Linux environment more efficiently and confidently. Let’s get started!
To view a directory’s contents, use the ‘ls’ command. Running the “ls” command without any additional options will list the contents of your current working directory, which is just a technical term for the directory that your terminal is currently in.
$ ls afs boot etc init lib64 media opt root sbin sys usr bin dev home lib lost+found mnt proc run srv tmp var
Here is the breakdown of the output of ls -l
and ls -ld
<directory name> commands, as well as the stat
<file name/directory name> command:
To see the long listing of the files and directories:
# ls -l -rwxrwxrwx . 4 root root 644432 Dec 22 06:49 File name
Below are the brief descriptions of ls -l
command output
-
-> Type of file, in this case, it's a directory.rwx
-> Owner permissions, which means the owner of the file has read (r), write (w), and execute (x) permissions.rwx
-> Group permissions, which means the group owner of the file has read (r), write (w), and execute (x) permissions.rwx
-> Others permissions, which means others (users not in the owner group or group owner) have read (r), write (w), and execute (x) permissions..
-> No ACL (Access Control List) permissions applied.4
-> The number of links to the file or directory.root
-> Owner of the file.root
-> Group ownership of the file.644432
-> Size of the file.Dec 22 06:49
-> Date and Time of the creation or modification of the file.File name
-> Name of the file.
How to see the long listing of the directories.
#ls -ld <directory name> d rwx rwx rwx . 2 root root 6 Dec 17 18:00 Directory name
Below are the brief descriptions of ls -ld
command output
d
-> Type of file, in this case, it's a directory.rwx
-> Owner permissions, which means the owner of the file has read (r), write (w), and execute (x) permissions.rwx
-> Group permissions, which means the group owner of the file has read (r), write (w), and execute (x) permissions.rwx
-> Others permissions, which means others (users not in the owner group or group owner) have read (r), write (w), and execute (x) permissions..
-> No ACL (Access Control List) permissions applied.2
-> The number of links to the file or directory.root
-> Owner of the file.root
-> Group ownership of the file.6
-> Size of the file.Dec 17 18:00
-> Date and Time of the creation or modification of the file.File name
-> Name of the file.
How to see the statistics of the file or directory: stat command
stat <file name/directory name>
File: <file name/directory name> Size: 6 Blocks: 8 IO Block: 4096 <file type> Device: fd02h/64770d Inode: 2634200 Links: 2 Access: (0777/drwxrwxrwx) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2021-12-17 18:00:00.000000000 +0000 <creation or modification time> Modify: 2021-12-17 18:00:00.000000000 +0000 <modification time> Change: 2021-12-17 18:00:00.000000000 +0000 <change time> Birth: -