> For the complete documentation index, see [llms.txt](https://olb.gitbook.io/linux-essentials-certification/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://olb.gitbook.io/linux-essentials-certification/2.finding_your_way_on_linux/2.3-directories_and_files_listing.md).

# 2.3 Directory and files listing

**Weight 2**\
Key knowledge areas

* Files, directories
* Hidden files and directories
* Home directories
* Absolute and relative paths

Partial list of the used files, terms and utilities

* Common options for `ls`
* Recursive listings
* `cd`
* `.` and `..`
* `home` and `~`

***

* `cd`
* `pwd` print working directory
* `ls`
  * `ls -a` all files including hidden files
  * `ls -d` only directories and symlink
  * `ls -R` show tree
  * `ls -r` reverse order
  * `ls -l` listing
  * `ls -t` sorted by date
* `mkdir`
* `tree /directory`, `tree -L 1 /directory` only one level
* `~username` equals to `/home/username/`
* **ls -l**\
  **`-rw-r--r-- 1 user staff 3606 Jan 13 2017 report2018.txt`**
  * **-l** : creates a long list. Files and directories will each occupy one line, but additional information about each file and directory will be displayed.
  * **-rw-r—r--** : Type of file and permissions of the file. Note that a regular file will begin with dash, and a directory will start with d.
  * **1** : Number of links to the file.
  * **user staff** : Specifies ownership of the file. user is the owner of the file, and the file is also associated with the staff group.
  * **3606** : Size of the file in bytes.
  * **Jan 13 2017** : Time stamp of the last modification to the file.
  * **report2018.txt** : Name of the file.
* **ls -lh** Combining long list with human readable file sizes
* **ls -d \*/** The -d option will list directories but not their contents. Combining this with \*/ will show only subdirectories and no files.
* **ls -lt** Combines long list with the option to sort by modification time. The files with the most recent changes will be at the top, and files with the oldest changes will be at the bottom. But this order can be reversed with:
* **ls -lrt** Combines long list with sort by (modification) time, combined with -r which reverses the sort. Now files with the most recent changes are at the bottom of the list. In addition to sorting by modification time, files can also be sorted by access time or by status time.
* **ls -lX** Combines long list with the option to sort by file eXtension. This will, for example, group all files ending with .txt together, all files ending with .jpg together, and so on.
* **ls -S** The -S sorts by file size, much in the same way as -t and -X sort by time and extension respectively. The largest files will come first, and smallest last. Note that the contents of subdirectories are not included in the sort.
* **ls -R** The -R option will modify the ls command to display a recursive list.
* **du -sh** Total size of the directory (s:summarize)
