Linux

Linux Command – Listing Files & Dir

Share and Enjoy !

Shares

Linux Command

Linux is a UNIX-based operating system. Linux / Unix OS provide a terminal to execute commands to accomplish administrative jobs. To open the terminal, click on the Activities item which you can find on the top left of the screen, and type “terminal”, “shell” or “Command”. This article will cover Linux Command – Listing Files & Dir.

Linux Command
Linux Command - Listing Files & Dir 13

Ls”  is a Linux shell command. This command is used to list directories and files in the directory. This command uses multiple parameters as per the requirement which we will discuss with an example. 

Syntax

ls [Option][File Name | Director Name]
ls 
#List files without options

The “ls” command without any option will list files and directories in plain format without much information like file type, file size, permission, modified date and time.

$ ls

To list files from a specific directory, pass the absolute path to the “ls” command
E.g. ls / Directory name

$ ls /var

We can pass multiple directories or file names to the command.
E.g. ls /Directory1 /Directory2

$ ls /home /var
$ ls -a | -all 
#View hidden files in current or request directory

ls -a” OR “ls –all” list all files including hidden files. In Linux, any file beginning with “.” is a hidden file. When a file is hidden, then you can not list / View it with a simple “ls” command.

To display all files including the hidden files use -a or –all options

$ ls -a
$ ls -R
# List files from /Directories /Sub-Directories

ls -R” will list all the files from the current or requested directory and sub-directories under the parent directory. The command is case-sensitive “ls -r” will give a different result. Please check the folder structure and command result as follows.

  1. BlogImg – Parent Directory
    1. Folder1 – Sub Directory
    2. Folder2 – Sub Directory
    3. Folder3 – Sub Directory
    4. RowImg – Sub Directory
      1. ls_Command.jpg – File Name
  2. ls_Command.jpg – File Name
  3. ls_a_Command.jpg – File Name
  4. ls_DirectoryName.jpg – File Name
  5. ls_MultipleDirectoryName.jpg – File Name
$ ls -R /home/arjun/Desktop/BlogImg/
$ ls -al
#View hidden files.

ls -al” will give detailed information on files in columnar format. the definition of columns is as follows.

1st Column  – Record type and access permission.
2nd Column – Hard links of file.
3rd Column – Owner of file
4th Column – Group of the owner
5th Column – Files Size (Bytes)
6th Column – Date and Time
7th Column – Directory and File Name

$ ls -al
$ ls -F
#To append indicators to files or Directories

ls -F” appends symbols to file names. These symbols tell useful information about files.

  • @ Stand for Symbolic Link or that files have extended attributes.
  • * Stand for Executable.
  • = Stand for Socket.
  • | Stand for named pipe Or FIFO.
  • > Stand for Door.
  • / Stand for Directory.
  • No symbol for regular files.
$ ls -F /var
Ls F Command
$ ls -r 
# To display files or Directories in reverse order.

ls -r” This option will display files and directories in reverse order. So by default “ls” command is sorted by name that is files or directories name.

$ ls -r /home/arjun/Desktop/BlogImg/
Ls R Command1

If you want to sort the folder separately and be displayed before the files, then we can use “–group-directories-first” option.

$ ls /home/arjun/Desktop/BlogImg/ --group-directories-first
Ls Grp Dir Command

If you want to sort files and directories by the last modified time, then we should “-t” options

$ ls -t /home/arjun/Desktop/BlogImg/
Ls T Command

Now let’s check how we can sort by size, our requirement is the largest size to be listed first. So we can use the “-S” option. What if you like to display the smallest file first, then use “-Sr

$ ls -S /home/arjun/Desktop/BlogImg/

-Sr” is used to list the smallest size first.

$ ls -Sr /home/arjun/Desktop/BlogImg
Ls S Sr Command

Let’s understand other commands which are equally important.

The “pwd” is a very useful command, pwd stands for “Print Working Directory”.

$ pwd
# To find out your current Directory.

The “clear” command itself tells us whenever you want to clear your terminal use the “clear” command.

$ clear
# To clear terminal.
76 / 100

Share and Enjoy !

Shares

Leave a Reply