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 Activities item which you can find on the top left of the screen, type “terminal”, “shell” or “Command”. We will cover about Linux Command – Listing Files & Dir in this post.

Linux Command
Linux Command - Listing Files & Dir 13

“Ls”  is Linux shell command. This command used to lists directory and files in the directory. This Command uses multiple parameters as per the requirement that we will discuss with an example. 

Syntax
ls [Option][File Name | Director Name]
ls List file without option

“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 specific directory, pass the absolute path to ls command
E.g. ls / Directory name

$ ls /var

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

$ ls /home /var
ls -a | –all View Hidden Files

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

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

$ ls -a
ls -R List files / Directories / Sub – Directories

ls -R” will list all the files from directory and sub-directories. Command is case sensitive “ls -r” will give different result. Please check folder structure and command result as follow.

  • BlogImg – Parent Directory
    • Folder1 – Sub Directory
    • Folder2 – Sub Directory
    • Folder3 – Sub Directory
    • RowImg – Sub Directory
      • ls_Command.jpg – File Name
  • ls_Command.jpg – File Name
  • ls_a_Command.jpg – File Name
  • ls_DirectoryName.jpg – File Name
  • ls_MultipleDirectoryName.jpg – File Name
$ ls -R /home/arjun/Desktop/BlogImg/
ls -al View Hidden Files.

ls -al” will give detailed information of files in columnar format. Definition of columns are as follow

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 Indictors to Files and Directories

ls -F” appends symbols to files 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 and Directories in reverse order.

ls -r” This option will display files and directories in reverse order. By default “ls” command sort 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 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

If you want to sort by size, largest size being list first, by using the “-S” option.

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

-Sr” use to list smallest size first.

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

71 / 100

Share and Enjoy !

Shares

Leave a Reply