Linux for Developers Course
Linux for Developers
/
Beginner

ls

Definition

List. A command used to list the files and subdirectories contained within the current directory or a specifically named directory.

Explain Like I'm New

Turning on the lights to see what is in the room. It prints out all the file names.

Real World Example

Typing `ls -la` is the most common usage. It lists every single file, including hidden ones (the `-a`), and formats them in a long list (the `-l`) showing file sizes, dates, and permissions.

Common Use Cases

  • •Viewing directory contents
  • •Checking file permissions

Important `ls` Command Flags

FlagCommandDescription
-l`ls -l`Long format. Displays detailed information including permissions, owner, size, and modification date.
-a`ls -a`All. Shows all files, including hidden files (files starting with a dot `.`).
-h`ls -lh`Human-readable. Converts file sizes from bytes into easily readable formats like KB, MB, and GB. (Usually combined with -l).
-t`ls -lt`Time sort. Sorts the output by modification time, newest first.
-R`ls -R`Recursive. Lists the contents of all subdirectories recursively.

Interview Questions

basic

  • How do you show 'Hidden' files using the `ls` command?

intermediate

  • In the output of `ls -l`, what does it mean if a line starts with a `d` (e.g., `drwxr-xr-x`)?

Flash Cards

Question

Show hidden files?

Click to reveal answer
Answer

Use the `-a` (all) flag: `ls -a`.

Question

What does 'd' mean?

Click to reveal answer
Answer

It means the item is a 'Directory' (folder), not a regular file.