This tutorial teaches you how to navigate the Linux file system using basic commands like `ls`, `cd`, and `pwd`. You’ll also learn how to move up directories with `cd ..` and identify hidden files using `ls -a`. Each step builds on the previous one, with practical examples and engaging exercises to reinforce your learning.

Beginner30 minutes

Step 1: Step 1: Understanding the Linux File System

The Linux file system is organized in a hierarchical structure, starting from the root directory (/). Directories (folders) and files are organized under this root. Understanding this structure is key to navigating effectively.

- Root Directory (/): The top-level directory.

- Home Directory (~): Your personal directory, typically /home/username.

- Current Directory (.): The directory you're currently in.

- Parent Directory (..): The directory one level above the current one.

Practice Exercise

Open your terminal and type pwd. What does it display? Why is this important?

Show Solution
# The `pwd` command displays the current directory.
# This is important because it helps you know where you are in the file system.
$ pwd
/home/username

Step 2: Step 2: Listing Files and Directories with `ls`

The ls command lists the contents of a directory. By default, it shows files and directories in the current directory.

- Basic Usage: ls

- Options:

- -l: Displays detailed information (permissions, owner, size, etc.).

- -a: Shows hidden files (files starting with a dot .).

$ ls
$ ls -l
$ ls -a

Practice Exercise

Use ls to list the contents of your home directory. Then, use ls -a to identify any hidden files. What do you notice?

Show Solution
# Lists contents of the home directory
$ ls
# Lists all files, including hidden ones
$ ls -a
# Hidden files start with a dot (e.g., .bashrc, .config)

Step 3: Step 3: Changing Directories with `cd`

The cd command changes your current directory.

- Basic Usage: cd

- Special Directories:

- cd ~: Navigates to your home directory.

- cd ..: Moves up one directory level.

- cd -: Returns to the previous directory.

$ cd /home/username/Documents
$ cd ..
$ cd ~

Practice Exercise

Navigate to the /var/log directory. Then, move up one level and list the contents of the /var directory. What do you see?

Show Solution
# Navigate to /var/log
$ cd /var/log
# Move up one level to /var
$ cd ..
# List contents of /var
$ ls
# You should see directories like 'log', 'lib', 'cache', etc.

Step 4: Step 4: Using `cd ..` to Navigate Up Directories

The cd .. command moves you up one directory level. This is useful for backtracking or navigating to a parent directory.

- Example: If you're in /home/username/Documents, running cd .. takes you to /home/username.

$ cd /home/username/Documents
$ cd ..

Practice Exercise

Start in your home directory. Navigate to a subdirectory (e.g., Documents), then use cd .. to return to the home directory. Repeat this process for another subdirectory (e.g., Downloads).

Show Solution
# Start in home directory
$ cd ~
# Navigate to Documents
$ cd Documents
# Move back to home directory
$ cd ..
# Navigate to Downloads
$ cd Downloads
# Move back to home directory
$ cd ..

Step 5: Step 5: Identifying Hidden Files with `ls -a`

Hidden files in Linux start with a dot (.). These files are often configuration files or system files. Use ls -a to view them.

- Example: .bashrc, .config, .ssh.

$ ls -a

Practice Exercise

Navigate to your home directory and use ls -a to list all files. Identify at least three hidden files and research their purpose. What do they do?

Show Solution
# Navigate to home directory
$ cd ~
# List all files, including hidden ones
$ ls -a
# Example hidden files:
# .bashrc: Configures the Bash shell
# .ssh: Stores SSH keys
# .config: Contains application configurations

Step 6: Step 6: Combining Commands for Efficient Navigation

You can combine commands to navigate and inspect the file system efficiently.

- Example: cd .. && ls moves up one directory and lists its contents.

$ cd .. && ls

Practice Exercise

Navigate to /usr/bin, list its contents, then move up to /usr and list its contents. What differences do you notice?

Show Solution
# Navigate to /usr/bin
$ cd /usr/bin
# List contents
$ ls
# Move up to /usr
$ cd ..
# List contents
$ ls
# /usr/bin contains executable files, while /usr contains directories like 'lib', 'share', etc.

Step 7: Step 7: Real-World Scenario - Organizing Files

Imagine you're organizing project files. You need to navigate between directories, list files, and identify hidden configuration files.

- Task: Create a directory structure for a project and use ls, cd, and pwd to navigate and inspect it.

$ mkdir -p Projects/MyProject/{src,config,logs}
$ cd Projects/MyProject
$ ls

Practice Exercise

Create a directory structure for a project with src, config, and logs directories. Navigate to each directory, list its contents, and identify any hidden files.

Show Solution
# Create project structure
$ mkdir -p Projects/MyProject/{src,config,logs}
# Navigate to project directory
$ cd Projects/MyProject
# List contents
$ ls
# Navigate to src
$ cd src
# List contents
$ ls -a
# Repeat for config and logs

Step 8: Step 8: Advanced Challenge - Scripting Navigation

Write a simple script to automate navigation tasks. For example, create a script that navigates to a directory, lists its contents, and moves up one level.

#!/bin/bash
cd /home/username/Documents
ls
cd ..

Practice Exercise

Write a Bash script that navigates to a directory of your choice, lists its contents (including hidden files), and then moves up one level. Save the script and run it.

Show Solution
# Create a script
$ nano navigate.sh
# Add the following content:
#!/bin/bash
cd /home/username/Documents
ls -a
cd ..
# Save and exit
# Make the script executable
$ chmod +x navigate.sh
# Run the script
$ ./navigate.sh

Sign in to take Cornell notes on this lesson — they save automatically and stay with your account.

Sign in

Click to access the login or register cheese