Listing Directory Contents in Linux
- Lists the contents of the current directory or a specified directory Usage
- ls [options] [files_or_dirs]
- 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.
ls -a includes so-called “hidden” files and directories whose names begin with a dot:
amar@amar-pc:/$ ls -a
in above image .test2 is hidden folder.
ls lists another file or directory if given as an argument:
amar@amar-pc:~/Desktop$ ls /
Use ls -l for a more detailed “long” listing:
amar@amar-pc:~/Desktop$ ls -l /usr
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
The ls command has many other options. All options can be used in combination with other ls options.