Google News
logo
Unix - Interview Questions
How to list directories in UNIX?
Command ls can be used to list directories in command prompt. Also, we can also use a variety of ls commands like:

ls -a In Linux, hidden files start with. (dot) Symbol and they are not visible in the regular directory. The (ls -a) command will enlist the whole list of the current directory including the hidden files.
ls -l It will show the list in a long list format.
ls -lh This command will show you the file sizes in human readable format. Size of the file is tough to read when displayed regarding a byte. The (ls -lh)command will give you the data regarding Mb, Gb, Tb, etc.
ls -lhS If you want to display your files in descending order (highest at the top) according to their size, then you can use (ls -lhS) command.
ls -l - -block-size=[SIZE] It is used to display the files in a specific size format. Here, in [SIZE] you can assign size according to your requirement.
ls -d */ It is used to display only sub directories.
ls -g or ls -lG With this, you can exclude column of group information and owner.
ls -n It is used to print group ID and owner ID instead of their names.
ls --color=[Value] This command is used to print list as colored or discolored.
ls -li This command prints the index number if the file in the first column.
ls -p It is used to identify the directory easily by marking the directories with a slash (/) line sign.
ls -R It will display the content of the sub-directories also.
ls -lX It will group the files with the same extensions together in the list.
ls -lt It will sort the list by displaying a recently modified file at the top.
ls ~ It gives the contents of the home directory.
ls ../ It gives the contents of the parent directory.
ls --version It checks the version of ls command.
Advertisement