Ls


From Linuxconfig.org

Jump to: navigation, search

.. back to the list of Linux Commands

Name

ls - list directory contents

Synopsis - man page

ls [OPTION]... [FILE]...

Frequently used options

-l    use a long listing format
-a, --all
      do not ignore entries starting with
-t    sort by modification time
-r, --reverse
      reverse order while sorting
-h, --human-readable
      with -l, print sizes in human readable format (e.g., 1K 234M 2G)

Examples

ls command without any options displays content of the current directory:

ls

Image:ls1.gif

To see all files and directories including hidden files and directories the "-a" option can be used:

ls -a

Image:ls2.gif

Please note that "." is current directory and ".." is parent directory.

Sometimes we want to also see size, who is an owner and what are permissions for given files and directories. To do that we can use "-l" option:

ls -l

Image:ls3.gif

ls -l .file1

Image:ls4.gif

Its also possible to combine options together. So if we would like to see long listing format and also include hidden files and directories we would issue a command:

ls -al

Image:ls5.gif

ls command is also able to sort output by time of creation.

ls -lt

Image:ls6.gif

In the example above the newest files/directories is on the top and the oldest files/directories are on the bottom of ls output. We can reverse this output with "-r" option:

ls -ltr

Image:ls7.gif

Last very useful option is -h. This option shows size of the file in human readable format however it can be used only with the combination of "-l" option:

ls -lh file3

Image:ls8.gif

.. back to the list of Linux Commands

Personal tools
Linux Commands