How to use the ls command in Linux

Listing Directory Contents in Linux

  • Lists the contents of the current directory or a specified directory Usage
    • ls [options] [files_or_dirs]
  • Example:
    • ls -a (include hidden files)
    • ls -l (display extra information)
    • ls -R (recourse through directories)
    • ls -ld (directory and symlink information)

Listing directory contents with ls

ls without arguments lists the file and directory names in the current directory.

amar@amar-pc:/$ ls
How to use the ls command in Linux

ls -a includes so-called “hidden” files and directories whose names begin with a dot:

amar@amar-pc:/$ ls -a
How to use the ls command in Linux

in above image .test2 is hidden folder.

ls lists another file or directory if given as an argument:

amar@amar-pc:~/Desktop$ ls /
How to use the ls command in Linux

Use ls -l for a more detailed “long” listing:

amar@amar-pc:~/Desktop$ ls -l /usr
How to use the ls command in Linux

ls -R recurses through subdirectories, listing their contents too. ls -d lists directory names, not their contents. it has no effect when file names are passed as arguments. This option is also useful with -l:

amar@amar-pc:~/Desktop$ ls -ld /usr
How to use the ls command in Linux

The ls command has many other options. All options can be used in combination with other ls options.

Leave a Comment

%d bloggers like this: