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
Print the Working Directory and List Its Contents
OrientationUse 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.
pwdls -lahls -lah /etc❯ View Expected Console Output
/home/samdrwxr-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
Use Absolute and Relative Paths
Navigationcd 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.
cd /var/logpwdcd -pwdcd ~❯ View Expected Console Output
/var/log/home/sam/home/samStep 3: Create a Practice Folder and Files
Create Directories and Write a Small Text File
File BasicsCreate 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.
mkdir -p ~/linux-basics-lab/reportsprintf 'Daily report\nStatus: ready\n' > ~/linux-basics-lab/reports/status.txttouch "$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
Inspect Files Before and After a Copy or Move
File OperationsUse 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.
cp ~/linux-basics-lab/reports/status.txt ~/linux-basics-lab/status-copy.txtmv ~/linux-basics-lab/status-copy.txt ~/linux-basics-lab/status-final.txtcat ~/linux-basics-lab/status-final.txtls -lah ~/linux-basics-lab ~/linux-basics-lab/reports❯ View Expected Console Output
Daily reportStatus: ready