Listing Files
Listing files means showing the names in a directory with extra facts about each one. Ls can show those facts in rows and columns.
Hidden files too
Ls -a shows the hidden note in the practice directory.
$ ls -a ~/practiceOne row for each name
Ls -l shows one row for each name.
$ ls -l ~/practiceSizes and largest first
Ls -lh shows sizes in short form. Ls -S lists the largest first.
$ ls -lh ~/practice/notes
$ ls -S ~/practice/dataNewest first
Ls -t lists the newest names first.
$ ls -t ~/practiceExample
$ stat ~/practice/notes/shopping.txt
$ file ~/practice/notes/shopping.txtKey points
- A hidden file is a file whose name starts with a dot.
- Ls hides hidden files unless -a follows it.
- A column is one upright list of facts.
- Use ls -l to show one row for each name, with facts in columns.
- Use ls -a to show hidden files too.
- Use ls -lh to show sizes in a short form.
- Use ls -t to list the newest names first.
- Use ls -S to list the largest first.
- Use stat to print the facts about one file.
- Use file to print the kind of a file.
- The letters and numbers in an ls -l row gain their meaning in a later lesson.
In this example, two lines ask two facts. The first line prints the facts about shopping.txt. The second line prints its kind, ASCII text. The size in the stat listing is 36, and it matches the size in the ls -lh listing.
Note
The names, sizes, and dates in a listing change with each machine, so yours will differ from the ones shown here.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
What does ls -a show that plain ls does not show?