Linux Labs

First steps / Stage 5 of 15

Navigation and paths

Not running Starting usually ~20 s
Leave the lesson

Step 4 of 8 · on a machine · 4 min

See what is in a directory

Your home directory holds more files than ls shows: some names are hidden. One option shows every name, another shows details about each.

ls lists a directory's contents: with no path, the current one; with a path, the one you name. Names that start with a dot are left out by ls — these are hidden names. Settings files are usually named this way, such as .bashrc in your home directory. You can read a hidden file like any other.

The -a option shows every name, including . and ... The -l option prints a detailed list: type, permissions, owner, size, and modification time. Options can be joined: -la does both at once.

bash
ls ~
ls -a ~
ls -la ~

The dot names — .bashrc, .profile — appear only in the second and third output. In the third, each name gets its own line. The first line, total, is the disk space these files take up. After it, the first character of a line is the type: d for a directory, - for a regular file. A separate lesson covers permissions and owners.

Check yourself 1 question

A colleague says the project directory holds .env, but ls shows only site.conf there. Which command do you use to check whether .env is there?

  • pwd prints the path of the current directory. ls lists the names in a directory, and hidden ones with -a.

  • The dot is the same current directory, so ls . shows the same list, without hidden names.

  • -l adds details to the same names and does not show hidden ones. The -a option lists every name.

ls without options leaves out names that start with a dot, so .env is not in the list. ls -a lists every name, .env included, if the file is there.

Key points

  • ls -a shows hidden names too — the ones that start with a dot.
  • In ls -l, the first character of a line is the type: d for a directory, - for a file.
Ubuntu 24.04
Loading…