Lesson 2 of 23
Lesson Progress: 0%
In the previous lesson you learned the basics of ls. Now it is time to discover more powerful flags that make ls even more useful. The -hflag shows file sizes in a format that is easy to read, like "4.0K" instead of a large number of bytes. The -t flag sorts files by when they were last changed, putting the newest ones first. You can combine flags like -ltr to see files in long format sorted oldest first. The -d flag with a pattern like */ lists only folders, and the wildcard *.txt matches every file that ends with .txt. Finally, -F adds a trailing slash to folder names so you can tell folders apart from files at a glance. Each of these options builds on what you already know and helps you work faster in the shell.
-h flag stands for "human-readable" and works together with -l.-h, file sizes are shown in bytes, like 4096.-lh, sizes are shown in a compact format like 4.0K or 1.2M, which is much easier to read.ls -lh to see the sizes of your files in human-readable format.-h only works when -l is also used, because -l is what shows the size column.-a, -l, and -h into a single flag called -lah..bashrc will appear alongside regular files and folders.-lah, -alh, and -hla all do the same thing.-t flag tells ls to sort the results by modification time instead of by name.-lt, the long format output shows different timestamps so you can see which files are newer.ls -lt to see your files sorted newest first.-r to -lt reverses the sort order: -ltr shows oldest files first.-rflag means "reverse" and can be added to any sort flag.-ltr, the file that was changed longest ago appears at the top.ls -ltr to view your files sorted from oldest to newest.-dflag means "list directories themselves, not their contents."*/, the trailing slash tells the shell to match only directories.ls -d */ shows a list of every folder in the current directory without opening them.ls -d */ to see all the folders in your current directory listed on one line.*.txt matches any file that ends with .txt, no matter what comes before the dot.*stands for "any sequence of characters."ls *.txt, only files with the .txt extension are shown, and all other files are hidden from the output.ls *.txt to see which text files exist in your current directory.-F flag adds a special character to the end of each name to show what kind of item it is./ is added after folder names, like Documents/.ls -F to see folders marked with a trailing slash in your current directory.Test Incomplete
~$ ls -lh~$ ls -lah~$ ls -lt~$ ls -ltr~$ ls -d */
ls a~$ ls *.txt~$ ls -F