Linux Basics · Lesson 5 · 10 min

Look around: pwd & ls

Whenever you land on a new machine, your first two questions are always the same: “Where am I?” and “What's here?” Two tiny commands answer them.

You will learn

  • pwd: print the folder you're in
  • ls, ls -l, ls -a: list what's there, with details, including hidden files
  • How to read the columns of ls -l, and a small difference Rocky has

pwd: where am I?

pwd stands for print working directory. (“Directory” is the Linux word for folder.) It prints your exact location:

Same on both
pwd
/home/student

That's your home folder. Every user gets one at /home/USERNAME, and it's where you land when you log in. Remember that ~ in the prompt means the same thing.

ls: what's here?

ls lists the contents of a folder. Folders are usually shown in blue.

Same on both
ls            # what's in the folder I'm in?
ls /etc       # what's in /etc? (you don't have to go there first)
ls -l         # long format: more details
ls -a         # all: include hidden files
ls -la        # both at once
ls -lh        # sizes like 4.0K and 2.1M instead of bytes

Hidden files

Any file or folder whose name starts with a dot (.bashrc, .ssh) is hidden. Plain ls skips it and ls -a shows it. Linux hides settings files this way so they don't clutter your view. They aren't secret or protected, just tidied away.

With -a you'll also see two strange entries: . means “this folder” and .. means “the folder above.” You'll use .. constantly in the next lesson.

Reading ls -l

Long format looks intimidating, but it's just a table without a header row:

-rw-r--r--permissions1studentownerstudent332size (bytes)Sep 27 09:00last changedreadme.txtname
Spot the difference
Rocky / RHEL
-rw-r--r--. 1 student student 332 readme.txt

See the dot after the permissions? It means the file has an SELinux security label. SELinux is an extra security guard that's switched on in the RHEL family.

Ubuntu / Debian
-rw-r--r-- 1 student student 332 readme.txt

No dot. Ubuntu uses a different security guard, AppArmor, which doesn't show up in ls.

There's also a handy shortcut, ll. On Rocky it means ls -l. On Ubuntu it means ls -alF, which also shows hidden files and puts a / after folder names.

Try it

Quick check

1. Why doesn't ls show .bashrc?

2. In ls -l output, a line starts with d. What is it?

3. On Rocky, what does the . at the end of -rw-r--r--. mean?

Finished the missions and the quiz? Mark it done to track your progress.