- List Files and Folders
- List the Contents of Other Folders
- List Folder Contents Using Wildcards
- View a List of Files in Subfolders
- View a List of Contents in a Single Column
- View Contents As a Comma-Separated List
- View Hidden Files and Folders
- Visually Display a File's Type
- Display Contents in Color
- List Permissions, Ownership, and More
- Reverse the Order Contents Are Listed
- Sort Contents by Date and Time
- Sort Contents by Size
- Express File Sizes in Terms of K, M, and G
- Display the Path of Your Current Directory
- Change to a Different Directory
- Change to Your Home Directory
- Change to Your Previous Directory
- Conclusion
Express File Sizes in Terms of K, M, and G
ls -h
In the previous section, the 15465 on .vimrc’s line means that the file is about 15KB, but it’s not always convenient to mentally translate bytes into the equivalent kilobytes, megabytes, or gigabytes. Most of the time, it’s more convenient to use the -h option (or --human-readable), which makes things easier to understand.
$ ls -laSh ~/ -rw-r--r-- 1 scott scott 100K 2015-10-19 11:44 .xsession-errors -rw------- 1 scott scott 40K 2015-04-20 11:00 .nessusrc -rw-r--r-- 1 scott scott 25K 2015-04-20 11:00 .abbrev_defs -rwxr--r-- 1 scott scott 16K 2015-10-12 15:45 .vimrc -rw------- 1 scott scott 12K 2015-10-19 10:59 .viminfo -rw------- 1 scott scott 8.6K 2015-10-19 08:43 .bash_history [List condensed and edited due to length]
In this example, you see K for kilobytes; if the files were big enough, you’d see M for megabytes or even G for gigabytes. Some of you might be wondering how 40122 bytes for .nessusrc became 40K when you used -h. Remember that 1024 bytes make up a kilobyte, so when you divide 40122 by 1024, you get 39.1816406 kilobytes, which ls -h rounds up to 40K. A megabyte is actually 1,048,576 bytes, and a gigabyte is 1,073,741,824 bytes, so a similar sort of rounding takes place with those as well. If you want exact powers of ten in your divisions (that is, what are referred to as “kibibytes,” “mebibytes,” and so on—see Chapter 6, “Viewing (Mostly Text) Files,” for more), try the --si option.