03. ls commands - muneeb-mbytes/linux_course GitHub Wiki

ls Command and itโ€™s variations

The below figure represents the ls command variations.

ls-commands

                                   Figure.1.Representation of ls command variation

ls commands cheat sheet

Sr No. ls commands with different options description
1 ls Display contents of working directory
2 ls * Display directories with sub-directories
3 ls -a Display hidden files/directories inside working directory
4 ls -l List the contains of directories in table format
5 ls -la List the contains of directories including hidden file
6 ls -lh List the file/directories with size of file/directories
7 ls -d */ List only directories
8 ls -R List all files & directories with their corresponding file
9 ls -r Display file/directories in reverse alphabetical order
10 ls -S Display file lists according to their size
11 ls -lt Sort the list by displaying modified files at top
12 ls -ltr Sort the list by displaying modified files at bottom
13 ls / Display the contents under root directory
14 ls ~ List the contents under home directory
15 ls --help Give more information about ls command
                                        Tabular column.1.ls command cheat sheet

ls

ls-listing

The ls command is used to list files or directories in Linux and other Unix-based operating systems. Just like you navigate in your File explorer with a GUI, the ls command allows you to list all files or directories in the current directory by default, and further interact with them via the command line.

The below figure shows output of ls command, which indicates directory in orange box and files in yellow box.

ls

                                           Figure.2. ls output

The below GIF shows the whole process from sourcing scripting file till the output.

ls

                                           GIF.1. ls Output GIF

Link to GitHub lab:https://github.com/muneeb-mbytes/linux_course/blob/b7_team_kachori/ls_commands/ls.csh


ls*

ls * command to list the contents of the directory with its sub-directories.

The below figure shows output of ls *, which indicates directory in orange box and files in yellow box.

ls_all

                                             Figure.3. ls * output

The below GIF shows the whole process of sourcing ls * scripting file till the final step.

ls_all

                                               GIF.2. ls * Output GIF

Link to GitHub lab:https://github.com/muneeb-mbytes/linux_course/blob/b7_team_kachori/ls_commands/ls_all.csh


ls -a

a - hidden files

The ls -a command to list files or directories including hidden files or directories. In Linux, anything that begins with a . is considered a hidden file.

The below figure shows output of ls -a, which indicates directory in orange box, files in yellow box and hidden files in brown box.

ls-a

                                                Figure.4. ls -a output

The below GIF shows the whole process from sourcing scripting file till the output.

ls-a

                                                 GIF.3. ls -a Output GIF

Link to GitHub lab:https://github.com/muneeb-mbytes/linux_course/blob/b7_team_kachori/ls_commands/ls-a.csh


ls -l

l - long listing of content

ls -l command to list the contents of the directory in a table format with the below information,

  • owner of the content
  • size of the content in bytes
  • last modified date / time of the content
  • file or directory name

The below figure shows the output of ls -l command, where the owner name, file size, modification date and time and file name.

ls-l

                                              Figure.5. ls -l output 

The below GIF shows the whole process from sourcing scripting file till the output.

ls-l

                                                GIF.4. ls -l Output GIF

Link to GitHub lab:https://github.com/muneeb-mbytes/linux_course/blob/b7_team_kachori/ls_commands/ls-l.csh


ls -la

l - long listing the content
a - hidden files

The ls -la command to list files or directories in a table format with extra information including hidden files or directories.

A link in UNIX is a pointer to a file. Like pointers in any programming languages, links in UNIX are pointers pointing to a file or a directory. Creating links is a kind of shortcuts to access a file.

There are two types of links :
Soft Link or Symbolic links
Hard Links

  1. Soft link:
    Soft Link contains the path for original file and not the contents.

  2. Hard link:
    Links have actual file contents

The below figure shows the output of ls -la, where we get the list of files and directories including hidden files. Soft link also created where we will get the path of the file.

ls-la

                                          Figure.6. ls -la Output

The below GIF shows the whole process from sourcing scripting file till the output.

ls-la

                                           GIF.5. ls -la Output GIF

Link to GitHub lab:https://github.com/muneeb-mbytes/linux_course/blob/b7_team_kachori/ls_commands/ls-la.csh

NOTE:- Here ls -l will display contents list wise and ls -la will display hidden contents list wise. so, we can say that ls -la = ls -l + ls -a.


ls -lh

l - long listing of the content
h - file size in human readable format

ls -lh command to list the files or directories in the same table format above, but with another column representing the size of each file/directory.

The below figure shows the ls -lh output, where we get the file size in human readable format.

ls-lh

                                         Figure.7. ls -lh Output

The below GIF shows the whole process from sourcing scripting file till the output.

ls-lh

                                           GIF.6. ls -lh Output GIF

Link to GitHub lab:https://github.com/muneeb-mbytes/linux_course/blob/b7_team_kachori/ls_commands/ls-lh.csh


ls -d */

d - directory

ls -d */ command to list only directories.

The below figure shows the output for ls -d */ command, where it will display only directories.

ls-d

                                      Figure.8. ls -d */ Output

The below GIF shows the whole process from sourcing scripting file till the output.

                                       GIF.7. ls -d */ Output GIF

ls-d

Link to GitHub lab:https://github.com/muneeb-mbytes/linux_course/blob/b7_team_kachori/ls_commands/ls-d.csh


ls -R

R - list all directory and sub-directory.

ls -R command to list all files and directories with their corresponding subdirectories down to the last file.

The below figure shows the output for ls -R command, where it will display directories and sub-directories including last file.

ls-R

                                       Figure.9. ls -R Output

The below GIF shows the whole process from sourcing scripting file till the output.

ls-R

                                        GIF.8. ls -R Output GIF

Link to GitHub lab:https://github.com/muneeb-mbytes/linux_course/blob/b7_team_kachori/ls_commands/ls-R.csh


ls -r

r - reverse order

ls -r command displays the list in reverse order.

The below figure shows the output for ls -r command, where the files will be sorting based in alphabetical reverse order.

ls_r

                                       Figure.10. ls -r Output

The below GIF shows the whole process from sourcing scripting file till the output.

ls_r

                                         GIF.9. ls -r Output GIF

Link to GitHub lab:https://github.com/muneeb-mbytes/linux_course/blob/b7_team_kachori/ls_commands/ls-r.csh


ls -S

S - display size

ls -S command displays the file list according to their sizes.

The below figure shows the output of ls -S command, where it displays the files and directories with their sizes.

ls-S

                                      Figure.11. ls -S Output

The below GIF shows the whole process from sourcing scripting file till the output.

ls-S

                                         GIF.10. ls -S Output GIF

Link to GitHub lab:https://github.com/muneeb-mbytes/linux_course/blob/b7_team_kachori/ls_commands/ls-S.csh


ls -lt

l - long listing of the content
t - sort list based on time

ls -lt command will sort the list by displaying recently modified files at top.

The below figure shows the output for ls -lt command, where it will display the file in long listing format with recently modified files at the top.

ls-lt

                                              Figure.12. ls -lt Output

The below GIF shows the whole process from sourcing scripting file till the output.

ls-lt

                                               GIF.11. ls -lt Output GIF

Link to GitHub lab:https://github.com/muneeb-mbytes/linux_course/blob/b7_team_kachori/ls_commands/ls-lt.csh


ls -ltr

l - long listing of the content
t - sorting based on time
r - reverse order

ls -ltr command will sort the list by displaying recently modified files at bottom.

ls-ltr

                                             Figure.13. ls -ltr Output

The below GIF shows the whole process from sourcing scripting file till the output.

ls-ltr

                                               GIF.12. ls -ltr Output GIF

Link to GitHub lab:https://github.com/muneeb-mbytes/linux_course/blob/b7_team_kachori/ls_commands/ls-ltr.csh


ls /

/ - root directory

ls / command to list the contents of the root directory.

ls_root

                                         Figure.14. ls / Output

The below GIF shows the whole process from sourcing scripting file till the output.

ls_root

                                          GIF.13. ls / Output GIF

Link to GitHub lab:https://github.com/muneeb-mbytes/linux_course/blob/b7_team_kachori/ls_commands/ls_root.csh


ls~

~ - home directory

ls ~ command to list the contents of the home directory.

ls_home

                                              Figure.15. ls ~ Output

The below GIF shows the whole process from sourcing scripting file till the output.

ls_home

                                                GIF.14. ls ~ Output GIF

Link to GitHub lab:https://github.com/muneeb-mbytes/linux_course/blob/b7_team_kachori/ls_commands/ls_home.csh


ls --help

To list all ls command options, type ls --help. The system lists all available options.


To learn mkdir command: https://github.com/muneeb-mbytes/linux_course/wiki/04.-mkdir-command