Linux ls command Help and Examples

Linux ls command is a basic command which is essential to know for all Linux users. It is used to list information of files and directories within a file system.

To use ls command, you don’t need to install any special package in your Linux machine. It is a part of the GNU core utility package, which comes with all distro of Linux.

The ls is a widespread utility, where you can’t imagine your work without using this utility. If you start working on the Linux machine, within 60 min, you will use this ls command uncountable numbers of time.

ls [OPTIONS] [FILES]

Suggested Reading: Linux sed command Structure

In this tutorial article, we will show you how to use ls command by using these three basic examples:

  1. List all files in Linux
  2. List all files in a long listing format
  3. View hidden files using ls

Examples:

List all files in Linux

The “ls” command is use to list all files and directory. You can use the “ls” command without any option to list all files and directories in the current location.

# ls

Output:

siteadmin@linuxconcept:~$ ls
linuxconcept.zip  tarexample.txt  test  test123.sh  zipcompare.sh
siteadmin@linuxconcept:~$

List all files in a long listing format

You can use the “-l” option with “ls” command to display file or directory, size, modified date and time, owner or files and permission on the file, as shown below:

# ls -l

Output:

siteadmin@linuxconcept:~$ ls -l
total 515340
-rw-r--r-- 1 siteadmin siteadmin 527705843 Jul 15 07:32 linuxconcept.zip
-rw-rw-r-- 1 siteadmin siteadmin         0 Dec  5 04:30 tarexample.txt
-rw-rw-r-- 1 siteadmin siteadmin         0 Dec  5 04:30 test
-rw-rw-r-- 1 siteadmin siteadmin         0 Dec  5 04:30 test123.sh
-rw-rw-r-- 1 siteadmin siteadmin         0 Dec  5 04:30 zipcompare.sh
siteadmin@linuxconcept:~$

View hidden files using ls

You can use the “ls” command to check hidden files or directories by using “-a” option, as shown below:

# ls -a

Output:

siteadmin@linuxconcept:~$ ls -a
.  ..  .bash_history  .bash_logout  .bashrc  .cache  .gnupg  linuxconcept.zip  .profile  .sudo_as_admin_successful  tarexample.txt  test  test123.sh  zipcompare.sh
siteadmin@linuxconcept:~$

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Related Articles