What are other options for the `ls` command?

QuestionsQuestions8 SkillsProDec, 17 2025
0139

Hi there! That's a fantastic question, Labby here to help!

You've already explored some of the most common and useful options for the ls command in this step (-l, -a, -la, -R). These are fundamental for understanding your file system.

The ls command is incredibly versatile and has many other options to customize its output. Here are a few more commonly used ones:

  1. -h (human-readable): When used with -l, it displays file sizes in human-readable formats (e.g., K, M, G instead of bytes), which is much easier to understand.

    ls -lh

    You might see output like:

    total 20K
    drwx------ 1 labex labex 90 Dec 17 00:13 .
    ...
    -rw------- 1 labex labex 31 Jun  4 03:13 .bash_history

    Notice 20K and 31 (bytes) become more readable.

  2. -t (sort by modification time): Lists files by modification time, with the newest files first.

    ls -lt

    This is great for seeing what files were recently changed.

  3. -r (reverse order): Reverses the sorting order. So, if you combine it with -t, it will list the oldest files first.

    ls -ltr

    This would show the oldest files at the top.

  4. -S (sort by size): Sorts files by size, with the largest files first.

    ls -lS

    Useful for finding large files quickly.

  5. -d (list directories themselves, not their contents): When you ls -l a directory, it usually lists its contents. With -d, it lists information about the directory itself.

    ls -ld project

    Output:

    drwxr-xr-x 2 labex labex 6 Aug 27  2024 project

    Compare this to ls -l project, which would show:

    total 0

    (because the project directory is empty in this step).

  6. --color=auto (colorized output): Most modern systems (including LabEx VMs) have this enabled by default, but it explicitly tells ls to use colors to differentiate between file types (directories, executable files, etc.).

    ls --color=auto

You can combine many of these options, for example, ls -lahrt would give you a long listing of all files, sorted by modification time (oldest first, because of r), with human-readable sizes.

The best way to see all possible options and a detailed explanation for each is to check the man (manual) page for ls:

man ls

Just type q to quit the man page.

Don't hesitate to experiment with these! Understanding ls options gives you powerful control over viewing your file system. Keep up the excellent work!

0 Comments

no data
Be the first to share your comment!