LESSON · 1 OF 6

Listing a folder

Listing a folder

ls prints what's inside a folder. Given no arguments, it lists your current folder. Given a path, it lists that folder.

bash
ls              # current folder
ls /etc         # specifically /etc

On a fresh machine your home folder can look empty, because its only files are hidden (their names start with a dot). A populated folder like /etc shows the difference right away.

The plain output shows names only. Useful, but not the whole picture. Add -l (lowercase L, for "long") and every entry expands into a row with metadata:

bash
ls -l /etc

A single row looks like this:

drwxr-xr-x  2 root root   4096 Feb 10 14:22 nginx

Seven columns worth reading:

  1. d says this is a directory. A - in that position means a regular file.
  2. rwxr-xr-x is the permissions preview. You'll unpack this in a later topic.
  3. 2 is the link count. Ignore it for now.
  4. root is the owner.
  5. root is the group.
  6. 4096 is the size in bytes.
  7. The date and time (in the example, Feb 10 at 14:22) show when the file was last modified.
  8. nginx is the name.

For now, focus on the first character (file or folder?) and the last few columns (size, date, name). The rest becomes useful once you learn about permissions and ownership.

Spin up a fresh environment and practice live.
linux-devops-basic · fresh machine · ready in under a minute