Command to list directories and subdirectories in Linux Ubuntu. Use ls command to list all files in a directory in Linux; list directories and subdirectories. Linux users can also list files recursively with full path using ls command when used with various command arguments.
‘ls’ Command Examples in Linux
ls command is use to lists the files in the current working directory. List information about the FILEs (the current directory by default). Sort entries alphabetically if none of -cftuvSUX nor –sort is specified.
The ls command is used in the following format ls [OPTION]… [FILE]…
The ‘ls’ program lists information about files and directories, not recursively, and omitting files with names beginning with ‘.’. By default ‘ls’ lists just the file name and ‘ls’ operates on the current directory. По умолчанию, the output of the ‘ls’ command is sorted alphabetically.
When ls command is used with no option, it list files and directories with details like file types, размер, modified date and time and permission.
But there are many options that can be used with ls command to get the desired output. Let us see some of those command examples:
It will list the contents of your home directory.
It will list the contents of the root directory.
It will list the contents of the parent directory.
It will list the contents of all subdirectories.
ls -a or ls –all
List all files including hidden file starting with ‘.‘. When used, the command do not ignore file names that start with ‘.’. Another variation of the commands is ls -A or ls –almost-all. This command does not ignore all file names that start with ‘.’; ignore only ‘.’ and ‘..’. The ‘–all’ (‘-a’) option overrides this option.
ls -d or ls –directory
It will list just the names of directories, as with other types of files, rather than listing their contents. This command can also be used to display a list of directories in the current directory. To do so use the ls -d */ команда.
It will list the file sizes in human readable format.
It will display files and directories in reverse order.
It will sort the file list by size, which is it will displays file size in order, big size file will be displayed first.
It will list and sort it by modification time. The output shows the most recently modified files or folders at the top of the list.
It will lists files with permissions, shows hidden files, displays them in a column format, and suppresses group information.
It will list all files containing the file extension .htm or .php
It will list only files that begin with a vowel (a, е, я, , or u).