Free Ebook cover Linux Command Line for Beginners: Navigate, Search, and Automate Simple Tasks

Linux Command Line for Beginners: Navigate, Search, and Automate Simple Tasks

New course

10 pages

Navigating the Linux File System with cd, ls, and pwd

Capítulo 2

Estimated reading time: 5 minutes

+ Exercise

Absolute vs. Relative Paths

When you move around the Linux file system, you always refer to locations using paths. A path is a route to a file or directory.

Absolute paths

An absolute path starts from the root directory / and fully specifies the location, regardless of where you currently are.

/home/alex/Documents
/var/log
/etc/ssh/sshd_config

Absolute paths are unambiguous: they always point to the same place.

Relative paths

A relative path is interpreted from your current working directory (your “current location”). It does not start with /.

Documents
projects/app
../Downloads

Relative paths are convenient for short navigation when you are already near the target directory.

Continue in our app.

You can listen to the audiobook with the screen off, receive a free certificate for this course, and also have access to 5,000 other free online courses.

Or continue reading below...
Download App

Download the app

Special Path Shortcuts: ., .., and ~

Linux provides a few special path components that make navigation faster.

. (current directory)

. refers to the directory you are currently in. It is often used when you need to explicitly say “from here”.

ls .

.. (parent directory)

.. refers to the parent of the current directory (one level up).

cd ..

You can chain it to go up multiple levels.

cd ../..

~ (home directory)

~ expands to your home directory (for example, /home/alex). It works anywhere in a path.

cd ~
cd ~/Downloads

This is especially useful when you want to jump back to a known location without typing the full absolute path.

Confirming Your Location with pwd

pwd prints your current working directory as an absolute path. Use it whenever you are unsure where you are before running commands that create, move, or delete files.

pwd

Example output might look like this:

/home/alex/projects

Moving Around with cd

cd changes your current directory. Think of it as “teleporting” your shell to a different folder so that relative paths are interpreted from there.

Common cd patterns

  • Go to an absolute location:

    cd /etc
  • Go to a relative location:

    cd projects
  • Go up one directory:

    cd ..
  • Go to your home directory (two common ways):

    cd
    cd ~

After any cd, run pwd to confirm you landed where you expected.

Listing Contents with ls

ls lists files and directories. On its own, it shows a simple list of names.

ls

You can also list a specific directory without moving into it.

ls /var
ls ~/Downloads

Useful ls flags

ls -l (long listing)

-l shows detailed metadata for each item: permissions, link count, owner, group, size, timestamp, and name.

ls -l

ls -a (include hidden files)

Files starting with a dot (like .bashrc) are hidden by default. Use -a to include them.

ls -a

Note that . and .. will also appear in this listing because they are real directory entries.

ls -h (human-readable sizes)

-h is typically used with -l to show sizes in KB/MB/GB rather than raw bytes.

ls -lh

Combining flags

You can combine flags to get a detailed view including hidden files with readable sizes.

ls -lah

Interpreting File Metadata from ls -l

A long listing looks like this:

-rw-r--r-- 1 alex staff  2480 Jan 12 09:41 notes.txt
 drwxr-xr-x 2 alex staff  4096 Jan 15 14:03 scripts

Read the columns from left to right:

  • File type and permissions (first field, e.g., -rw-r--r-- or drwxr-xr-x):

    • The first character indicates type: - for a regular file, d for a directory.

    • The remaining characters are permissions in three groups: owner, group, others.

  • Link count (e.g., 1 or 2): how many directory entries point to this file/directory.

  • Owner (e.g., alex): the user who owns the file.

  • Group (e.g., staff): the group associated with the file.

  • Size (e.g., 2480 or 4096): file size in bytes (or human-readable units if you used -h).

  • Timestamp (e.g., Jan 12 09:41): typically the last modification time.

  • Name (e.g., notes.txt or scripts): the file or directory name.

Quick permission reading practice

Take drwxr-xr-x:

  • d means it is a directory.

  • rwx (owner) means the owner can read, write, and enter the directory.

  • r-x (group) means group members can read and enter, but not write.

  • r-x (others) means everyone else can read and enter, but not write.

For a regular file like -rw-r--r--, “enter” does not apply; instead, the execute bit controls whether the file can be run as a program/script.

Mini-Lab: Navigate a Folder Tree and Capture Listings

In this mini-lab, you will move through a provided folder tree, list hidden files, and save a long listing for review. The commands below assume you have a lab directory named nav-lab in your home directory. If your instructor provided a different name or location, adjust the paths accordingly.

1) Start in your home directory and verify location

cd ~
pwd

2) Inspect the top level of the lab folder

ls nav-lab
ls -l nav-lab

Without changing directories, you just confirmed what is inside nav-lab and saw metadata with -l.

3) Enter the lab folder and confirm where you are

cd nav-lab
pwd

4) Practice relative navigation with . and ..

ls .
ls ..

ls . lists the current directory; ls .. lists the parent directory (likely your home directory).

5) Move down into a subdirectory, then back up

Choose a subdirectory name you saw in step 2 (example: projects).

cd projects
pwd
cd ..
pwd

6) List hidden files

From inside nav-lab, run:

ls -a

Look for dotfiles such as .config, .notes, or similar items included in the lab.

7) Create a long listing with readable sizes and save it for review

Capture a detailed listing (including hidden files) into a text file named listing.txt inside the lab directory:

ls -lah > listing.txt

Now verify that the file exists and inspect its metadata:

ls -l listing.txt

If you want to confirm the lab captured what you expected, list the directory again and ensure listing.txt appears.

ls

Now answer the exercise about the content:

Which command both includes hidden files and shows detailed listings with human-readable sizes for the current directory?

You are right! Congratulations, now go to the next page

You missed! Try again.

ls -lah combines -l (long listing), -a (include hidden files), and -h (human-readable sizes).

Next chapter

Creating, Copying, Moving, and Removing Files and Folders

Arrow Right Icon
Download the app to earn free Certification and listen to the courses in the background, even with the screen off.