Tutorial by Examples

The ls command lists the contents of a specified directory, excluding dotfiles. If no directory is specified then, by default, the contents of the current directory are listed. Listed files are sorted alphabetically, by default, and aligned in columns if they don’t fit on one line. $ ls apt conf...
The ls command's -l option prints a specified directory's contents in a long listing format. If no directory is specified then, by default, the contents of the current directory are listed. ls -l /etc Example Output: total 1204 drwxr-xr-x 3 root root 4096 Apr 21 03:44 acpi -rw-r--r-- 1 r...
The ls command's -S option sorts the files in descending order of file size. $ ls -l -S ./Fruits total 444 -rw-rw-rw- 1 root root 295303 Jul 28 19:19 apples.jpg -rw-rw-rw- 1 root root 102283 Jul 28 19:19 kiwis.jpg -rw-rw-rw- 1 root root 50197 Jul 28 19:19 bananas.jpg When used with the -r o...
Use the Bash shell's filename expansion and brace expansion capabilities to obtain the filenames: # display the files and directories that are in the current directory printf "%s\n" * # display only the directories in the current directory printf "%s\n" */ # display only...
The following will list up to ten of the most recently modified files in the current directory, using a long listing format (-l) and sorted by time (-t). ls -lt | head
A dotfile is a file whose names begin with a .. These are normally hidden by ls and not listed unless requested. For example the following output of ls: $ ls bin pki The -a or --all option will list all files, including dotfiles. $ ls -a . .ansible .bash_logout .bashrc .lesshst ...
The tree command lists the contents of a specified directory in a tree-like format. If no directory is specified then, by default, the contents of the current directory are listed. Example Output: $ tree /tmp /tmp ├── 5037 ├── adb.log └── evince-20965    └── image.FPWTJY.png Use the tree ...

Page 1 of 1