Skip to content

Navigate the Linux Shell and Work with Files

The shell is a text interface for exploring and managing a Linux filesystem. A few commands—pwd, ls, and cd—help you understand where you are before you work with files. This tutorial uses a practice directory in your home folder so the examples do not alter system files.

Commands are case-sensitive. A path beginning with / starts at the filesystem root; a path beginning with ~ starts in your home directory. When a name contains spaces, put it in quotes.


Step 1: Check Your Current Location

01

Print the Working Directory and List Its Contents

Orientation

Use pwd to print the full path of the current directory. Use ls -lah to show normal and hidden entries, readable sizes, permissions, and ownership. Listing a path such as /etc does not change it.

Terminal window
pwd
ls -lah
ls -lah /etc
❯ View Expected Console Output
/home/sam
drwxr-x--- 8 sam sam 4.0K Oct 4 09:15 .
drwxr-xr-x 1 root root 4.0K Oct 1 08:00 ..

Step 2: Move Between Directories

02

Use Absolute and Relative Paths

Navigation

cd changes the shell’s current directory. Use cd ~ to return to your home folder, cd .. to move up one level, and cd - to return to the previous location. A relative path is interpreted from the current directory.

Terminal window
cd /var/log
pwd
cd -
pwd
cd ~
❯ View Expected Console Output
/var/log
/home/sam
/home/sam

Step 3: Create a Practice Folder and Files

03

Create Directories and Write a Small Text File

File Basics

Create a workspace under your home directory. The -p option makes any missing parent directories and does not complain if they already exist. printf writes the sample text into the file, replacing its contents if the file already exists.

Terminal window
mkdir -p ~/linux-basics-lab/reports
printf 'Daily report\nStatus: ready\n' > ~/linux-basics-lab/reports/status.txt
touch "$HOME/linux-basics-lab/project notes.txt"
❯ View Expected Console Output
The reports directory and status.txt are created under ~/linux-basics-lab.

Step 4: Copy, Rename, and Read a File

04

Inspect Files Before and After a Copy or Move

File Operations

Use cp to make a copy and mv to rename or move an entry. Read a short file with cat; use less for longer files and press q to exit. List the directory after each operation to confirm the result.

Terminal window
cp ~/linux-basics-lab/reports/status.txt ~/linux-basics-lab/status-copy.txt
mv ~/linux-basics-lab/status-copy.txt ~/linux-basics-lab/status-final.txt
cat ~/linux-basics-lab/status-final.txt
ls -lah ~/linux-basics-lab ~/linux-basics-lab/reports
❯ View Expected Console Output
Daily report
Status: ready

Comments