2.3 Using Directories and Listing Files Flashcards
Directories and Files
display hierarchical listing of directory tree
tree
Directories and Files
path type
/home/user/Downloads
absolute
Directories and Files
path type
../Reports
relative
Directories and Files
path type
/var
absolute
Directories and Files
path type
docs
relative
Directories and Files
path type
/
absolute
Directories and Files
Combining long list with human readable file sizes will give us useful suffixes such as M for
megabytes or K for kilobytes
ls -lh
human readable
Directories and Files
The -d option will list directories but not their contents. Combining this with */ will show only
subdirectories and no files.
ls -d */
directories
Directories and Files
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 -lt
Directories and Files
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 -lrt
Directories and Files
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 -lx
Directories and Files
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 -S
size
Directories and Files
ls -R
The -R option will modify the ls command to display a recursive list. What does this mean?
refers to a situation when “something is defined in terms of itself”.
Directories and Files
sort by file extension
-X(eXtension)
Directories and Files
generates a list of all files and directories and indicates size of each
du