• Home
  • Python
    • Introduction to Python
    • Python Developer
  • JavaScript
    • Introduction to JavaScript
    • JavaScript Developer
  • React.js
    • Introduction to React
    • React Developer
  • TypeScript
    • Introduction to TypeScript
    • TypeScript Developer
  • Linux Shell
    • Introduction to the Linux Shell
    • Linux Shell Developer
  • C++
    • Introduction to C++
    • C++ Developer
  • C Language
    • Introduction to C
    • C Developer
  • Rust
    • Introduction to Rust
    • Rust Developer
  • Zig
    • Introduction to Zig
    • Zig Developer
  • Interactive Training
  • Pricing
  • Brainstorm
STEMTrainingGrounds
  • Courses
    • Home
    • Python
      • Introduction to Python
      • Python Developer
    • JavaScript
      • Introduction to JavaScript
      • JavaScript Developer
    • React
      • Introduction to React
      • React Developer
    • TypeScript
      • Introduction to TypeScript
      • TypeScript Developer
    • Linux Shell
      • Introduction to the Linux Shell
      • Linux Shell Developer
    • C++
      • Introduction to C++
      • C++ Developer
    • C Language
      • Introduction to C
      • C Developer
    • Rust
      • Introduction to Rust
      • Rust Developer
    • Zig
      • Introduction to Zig
      • Zig Developer
  • Interactive Training
  • Pricing
  • Navigate
    • Home
    • Reading Grounds
    • Brainstorm

Quick Links

  • About Us
  • Pricing
  • Partnership
  • Brainstorm
  • Terms
  • Privacy
  • Refunds

Courses

  • Python
    • Introduction to Python
    • Python Developer
  • JavaScript
    • Introduction to JavaScript
    • JavaScript Developer
  • React
    • Introduction to React
    • React Developer
  • TypeScript
    • Introduction to TypeScript
    • TypeScript Developer
  • Linux Shell
    • Introduction to the Linux Shell
    • Linux Shell Developer
  • C++
    • Introduction to C++
    • C++ Developer
  • C Language
    • Introduction to C
    • C Developer
  • Rust
    • Introduction to Rust
    • Rust Developer

Newsletter

Subscribe to our free monthly newsletter, for a quick update on Python, JavaScript, and React news

© 2025 - 2026 STEMTrainingGrounds. All Rights Reserved.

Introduction to the Linux Shell -

Lesson 2 of 23

Lesson Progress: 0%

Lesson Progress: 0%
Lesson Incomplete
← Previous: Linux ls command I
Lesson 2 of 23
Next: Linux cd command →

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.

  • The -h flag stands for "human-readable" and works together with -l.
  • Without -h, file sizes are shown in bytes, like 4096.
  • With -lh, sizes are shown in a compact format like 4.0K or 1.2M, which is much easier to read.
  • Type ls -lh to see the sizes of your files in human-readable format.
  • The -h only works when -l is also used, because -l is what shows the size column.
  • You can combine -a, -l, and -h into a single flag called -lah.
  • This shows all files (including hidden ones) in long format with human-readable sizes.
  • Hidden files like .bashrc will appear alongside regular files and folders.
  • The order of the letters does not matter: -lah, -alh, and -hla all do the same thing.
  • Combining multiple flags is a powerful way to get exactly the view you want with minimal typing.
  • The -t flag tells ls to sort the results by modification time instead of by name.
  • Files and folders that were changed most recently appear at the top of the list.
  • This is useful when you want to find the file you just edited or the newest download.
  • When you use -lt, the long format output shows different timestamps so you can see which files are newer.
  • Type ls -lt to see your files sorted newest first.
  • Adding -r to -lt reverses the sort order: -ltr shows oldest files first.
  • The -rflag means "reverse" and can be added to any sort flag.
  • This is helpful when you want to see which file has not been touched in the longest time.
  • With -ltr, the file that was changed longest ago appears at the top.
  • Try ls -ltr to view your files sorted from oldest to newest.
  • The -dflag means "list directories themselves, not their contents."
  • When you write */, the trailing slash tells the shell to match only directories.
  • Together, ls -d */ shows a list of every folder in the current directory without opening them.
  • This is a quick way to see only the folders when they are mixed in with many files.
  • Type ls -d */ to see all the folders in your current directory listed on one line.
  • The pattern *.txt matches any file that ends with .txt, no matter what comes before the dot.
  • The asterisk *stands for "any sequence of characters."
  • When you run ls *.txt, only files with the .txt extension are shown, and all other files are hidden from the output.
  • This is useful when a folder contains many different kinds of files and you only want to see the text files.
  • Try ls *.txt to see which text files exist in your current directory.
  • The -F flag adds a special character to the end of each name to show what kind of item it is.
  • A slash / is added after folder names, like Documents/.
  • Regular files do not get any extra character, so you can easily tell them apart from folders.
  • This flag is sometimes called "classify" because it classifies each item by its type.
  • Type ls -F to see folders marked with a trailing slash in your current directory.

Test Incomplete

What does the -h flag do when combined with ls -l?

Question #

1/15

Score

0/0 - 0.0 %

Task Incomplete
Example
~$ ls -lh
  • Run ls -lh for human-readable sizes
Linux Shell
~$
Task Incomplete
Example
~$ ls -lah
  • Run ls -lah to see everything
Linux Shell
~$
Task Incomplete
Example
~$ ls -lt
  • Run ls -lt sorted by modification time
Linux Shell
~$
Task Incomplete
Example
~$ ls -ltr
  • Run ls -ltr sorted oldest first
Linux Shell
~$
Task Incomplete
Example
~$ ls -d */
ls a
  • Run ls -d */ to show only directories
  • Run ls -a to see all files
Linux Shell
~$
Task Incomplete
Example
~$ ls *.txt
  • Run ls *.txt to match .txt files
Linux Shell
~$
Task Incomplete
Example
~$ ls -F
  • Run ls -F to see file type indicators
Linux Shell
~$