Some useful commands for list files and directories in the Linux {ls commands}


This article is all about listing the files and directories in the Linux operating system. In this article, you will study about those commands which are used to list the files and directories in the Linux. Here you will study how to list the all files and directories in the different order using different options. And here you will study how to view the contents of the directories and how to display the contents of the current directory.

ls command is one of the most used commands in the Linux. ls command is a Linux shell command which is used to lists contents of files and directories. ls command without any option is shown only the name of files and directories it does not show the detail information of the files and directories and does not show the hidden files. So here we will study all the ls option to cover as much parameter as possible.

ls syntax

ls [options] [file or directory]

List of files and directories using ls command without any option

ls command without any option list files and directories name where you won’t be able to view the details like file size, permission, links, file type etc.

root@kali:~# ls
a       Documents f     Pictures r.mp4  student   Videos
Desktop Downloads Music Public   satish Templates

List of hidden files and directories using ls -a command

ls -a command is used to list the hidden files and directories in the Linux. These hidden files and directories are started with a dot(.).

root@kali:~# ls -a
.             .config   .gconf        .nano    satish      .zenmap
..            .dbus     .gnupg        Pictures student
a             Desktop   .ICEauthority .profile .subversion
.bash_history Documents .local        Public   Templates
.bashrc       Downloads .mozilla      r.mp4    Videos
.cache        f         Music         .rnd     .viminfo

List of files and directories with ls -l command

ls -l command is used to show the detailed description of the files listed in the terminal, such as file or directories type, size, modified date and time, permission of the file, name etc.

root@kali:~# ls -l
total 48
-rw-r--r-- 1 root root 2719 Jun 9 22:39 a
drwxr-xr-x 5 root root 4096 Jun 11 00:00 Desktop
drwxr-xr-x 2 root root 4096 Jun 4 21:37 Documents
drwxr-xr-x 3 root root 4096 Jun 10 16:38 Downloads
-rw-r--r-- 1 root root 0 Jun 10 17:52 f
drwxr-xr-x 2 root root 4096 Jun 4 21:37 Music
drwxr-xr-x 2 root root 4096 Jun 26 20:15 Pictures
drwxr-xr-x 2 root root 4096 Jun 4 21:37 Public
-rw-r--r-- 1 root root 3    Jun 21 18:53 r.mp4
drwxr-xr-x 2 root root 4096 Jun 26 21:59 satish
drwxr-xr-x 2 root root 4096 Jun 22 14:43 student
drwxr-xr-x 2 root root 4096 Jun 4 21:37 Templates
drwxr-xr-x 2 root root 4096 Jun 4 21:37 Videos

List of files and directories with ls -lh command

ls -lh command is used to list the files and directory in the more human-friendly units, so we can easily read and understand the size of the file. This command displayed the most appropriate unit and is rounded to two decimal places.

root@kali:~# ls -lh
total 48K
-rw-r--r-- 1 root root 2.7K Jun 9 22:39 a
drwxr-xr-x 5 root root 4.0K Jun 11 00:00 Desktop
drwxr-xr-x 2 root root 4.0K Jun 4 21:37 Documents
drwxr-xr-x 3 root root 4.0K Jun 10 16:38 Downloads
-rw-r--r-- 1 root root 0 Jun 10 17:52 f
drwxr-xr-x 2 root root 4.0K Jun 4 21:37 Music
drwxr-xr-x 2 root root 4.0K Jun 26 20:15 Pictures
drwxr-xr-x 2 root root 4.0K Jun 4 21:37 Public
-rw-r--r-- 1 root root 3 Jun 21 18:53 r.mp4
drwxr-xr-x 2 root root 4.0K Jun 26 21:59 satish
drwxr-xr-x 2 root root 4.0K Jun 22 14:43 student
drwxr-xr-x 2 root root 4.0K Jun 4 21:37 Templates
drwxr-xr-x 2 root root 4.0K Jun 4 21:37 Videos

List of files and directories with ls -F command

ls -F command is used to add the ‘/’ character at the end of each directory. This character will add only in the directory, not in the files. So we can easily distinguish the directories from files.

root@kali:~# ls -F
a        Documents/ f      Pictures/ r.mp4   student/   Videos/
Desktop/ Downloads/ Music/ Public/   satish/ Templates/

Recursively list subdirectories with ls -R command

ls -R command will list very long listing directory trees. This command will show all the directories and sub-directories and the files in each single directory. So the output of this command can be very long it depends on your current directory.

root@kali:~# ls -R
.:
a Documents f Pictures r.mp4 student Videos
Desktop Downloads Music Public satish Templates

./Desktop:
google-chrome-stable_current_amd64.deb wine-staging-2.9
linux important softwares wine-staging-2.9.tar.gz
linux softwares

./Desktop/linux important softwares:
AdbeRdr9.4-1_i486linux_enu.bin

List files and directories with ls -lS command

ls -lS command is used to display the file in order of their size, by this command big file or directory will display in the first and then small file after that.

root@kali:~# ls -lS
total 48
drwxr-xr-x 5 root root 4096 Jun 11 00:00 Desktop
drwxr-xr-x 2 root root 4096 Jun 4 21:37 Documents
drwxr-xr-x 3 root root 4096 Jun 10 16:38 Downloads
drwxr-xr-x 2 root root 4096 Jun 4 21:37 Music
drwxr-xr-x 2 root root 4096 Jun 26 20:15 Pictures
drwxr-xr-x 2 root root 4096 Jun 4 21:37 Public
drwxr-xr-x 2 root root 4096 Jun 26 21:59 satish
drwxr-xr-x 2 root root 4096 Jun 22 14:43 student
drwxr-xr-x 2 root root 4096 Jun 4 21:37 Templates
drwxr-xr-x 2 root root 4096 Jun 4 21:37 Videos
-rw-r--r-- 1 root root 2719 Jun 9 22:39 a
-rw-r--r-- 1 root root 3    Jun 21 18:53 r.mp4
-rw-r--r-- 1 root root 0    Jun 10 17:52 f

List of files and directories with ls -r command

ls -r command is used to list the files and directories in the reverse order.

root@kali:~# ls -r
Videos    student r.mp4  Pictures f         Documents a
Templates satish  Public Music    Downloads Desktop

List of files and directories with ls -ltr command

ls -ltr command is used to show previous modification files and directories in the first and latest modification files and directories as last and it arranges on the basis of modification date.

root@kali:~# ls -ltr
total 48
drwxr-xr-x 2 root root 4096 Jun 4 21:37 Videos
drwxr-xr-x 2 root root 4096 Jun 4 21:37 Templates
drwxr-xr-x 2 root root 4096 Jun 4 21:37 Public
drwxr-xr-x 2 root root 4096 Jun 4 21:37 Music
drwxr-xr-x 2 root root 4096 Jun 4 21:37 Documents
-rw-r--r-- 1 root root 2719 Jun 9 22:39 a
drwxr-xr-x 3 root root 4096 Jun 10 16:38 Downloads
-rw-r--r-- 1 root root 0 Jun 10 17:52 f
drwxr-xr-x 5 root root 4096 Jun 11 00:00 Desktop
-rw-r--r-- 1 root root 3 Jun 21 18:53 r.mp4
drwxr-xr-x 2 root root 4096 Jun 22 14:43 student
drwxr-xr-x 2 root root 4096 Jun 26 20:15 Pictures
drwxr-xr-x 2 root root 4096 Jun 26 21:59 satish

Display inode number of files and directories with ls -i command

ls -i command is used to display the inode number of files and directories. These inode numbers are printed before the file or directory name.

root@kali:~# ls -i
3611937 a         4005892 f        4006218 r.mp4     3604507 Videos
3604500 Desktop   3604505 Music    3613575 satish
3604504 Documents 3604506 Pictures 3622085 student
3604501 Downloads 3604503 Public   3604502 Templates

Check version of ls command

ls –version command is used to show the version of ls command in your computer.

root@kali:~# ls --version
ls (GNU coreutils) 8.26
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Richard M. Stallman and David MacKenzie.

Show help page of ls command

ls –help command is used to list the help page of ls command with their option.

root@kali:~# ls --help
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.

Mandatory arguments to long options are mandatory for short options too.
-a, --all do not ignore entries starting with .
-A, --almost-all do not list implied . and ..
--author with -l, print the author of each file
-b, --escape print C-style escapes for nongraphic characters
--block-size=SIZE scale sizes by SIZE before printing them; e.g.,
'--block-size=M' prints sizes in units of
1,048,576 bytes; see SIZE format below
-B, --ignore-backups do not list implied entries ending with ~
-c with -lt: sort by, and show, ctime (time of last
modification of file status information);
with -l: show ctime and sort by name;
otherwise: sort by ctime, newest first
-C list entries by columns
--color[=WHEN] colorize the output; WHEN can be 'always' (default
if omitted), 'auto', or 'never'; more info below
-d, --directory list directories themselves, not their contents
-D, --dired generate output designed for Emacs' dired mode
-f do not sort, enable -aU, disable -ls --color
-F, --classify append indicator (one of */=>@|) to entries

List directory information with ls -l /tmp command

ls -l /tmp command is used to list the files in directory /tmp. And ls -ld command is used to display information of /tmp directory.

root@kali:~# ls -l /tmp
total 20
drwx------ 2 root root 4096 Jun 28 16:46 firefox-esr_root
drwx------ 2 root root 4096 Jun 28 16:26 ssh-UV4MDREp8ott
drwx------ 3 root root 4096 Jun 28 16:26 systemd-private-a40fc65432ca4b288355b9a352e7569f-colord.service-Bq6kbI
drwx------ 3 root root 4096 Jun 28 16:25 systemd-private-a40fc65432ca4b288355b9a352e7569f-rtkit-daemon.service-hUkv0f
drwx------ 2 root root 4096 Jun 28 16:26 tracker-extract-files.0
root@kali:~# ls -ld /tmp
drwxrwxrwt 12 root root 4096 Jun 28 18:09 /tmp

Display UID and GID of files using ls -n command

ls -n command is used to display the UID and GID of files.

root@kali:~# ls -n
total 48
-rw-r--r-- 1 0 0 2719 Jun 9  22:39 a
drwxr-xr-x 5 0 0 4096 Jun 11 00:00 Desktop
drwxr-xr-x 2 0 0 4096 Jun 4  21:37 Documents
drwxr-xr-x 3 0 0 4096 Jun 10 16:38 Downloads
-rw-r--r-- 1 0 0 0    Jun 10 17:52 f
drwxr-xr-x 2 0 0 4096 Jun 4  21:37 Music
drwxr-xr-x 2 0 0 4096 Jun 26 20:15 Pictures
drwxr-xr-x 2 0 0 4096 Jun 4  21:37 Public
-rw-r--r-- 1 0 0 3    Jun 21 18:53 r.mp4
drwxr-xr-x 2 0 0 4096 Jun 26 21:59 satish
drwxr-xr-x 2 0 0 4096 Jun 22 14:43 student
drwxr-xr-x 2 0 0 4096 Jun 4  21:37 Templates
drwxr-xr-x 2 0 0 4096 Jun 4  21:37 Videos

                                                                              THAT’S IT

These are the whole commands by which we can list all the directories and files in Linux. By using these commands you can easily operate Linux operating system. I think this article is helpful for you. If you have any queries regarding this then simply solved out through the comment section. Also, provide feedback to us because your feedback is valuable for us. Subscribe and follow our blog for further updates.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s