What other options does ls have?

QuestionsQuestions8 SkillsProDec, 15 2025
0163

That's a great question! The ls command is quite powerful and has many options (also called flags or arguments) to modify its behavior. Here are some of the most commonly used and useful ones:

  • -l (long format): This is one of the most frequently used options. It displays files and directories in a long, detailed format, including information like permissions, number of hard links, owner, group, file size, and last modification date.

    ls -l
  • -a (all): This option shows all files, including hidden files (those starting with a .). By default, ls does not show hidden files.

    ls -a
  • -h (human-readable): When used with -l, this option displays file sizes in human-readable format (e.g., 1K, 234M, 2G) instead of bytes. It makes the output much easier to read.

    ls -lh
  • -R (recursive): This option lists the contents of directories recursively, meaning it will list the contents of subdirectories as well. Be cautious with this in a large directory, as the output can be very long!

    ls -R
  • -t (time sort): Sorts the output by modification time, with the newest files listed first.

    ls -t
  • -r (reverse): Reverses the order of the sort. Often used with -t to list oldest files first.

    ls -rt
  • -d (directory): When ls is given a directory name, it usually lists the contents of that directory. The -d option makes ls list the directory itself rather than its contents. This is especially useful when combined with -l to see details about the directory.

    ls -ld .
    ls -ld /home/labex/project
  • --color=auto: This is often enabled by default. It displays output in color, making it easier to distinguish between different file types (directories, executable files, etc.).

There are many more options, and you can combine them to get exactly the information you need. For example, ls -lah is a very common combination to see all files in a human-readable long format.

If you ever want to see the full list of options, you can consult the ls manual page by typing:

man ls

You can press q to exit the manual page.

Do any of these options sound particularly interesting to try out?

0 Comments

no data
Be the first to share your comment!