Navigate the Linux Shell and Work with Files: A Beginner Guide
Before you begin
- Applies to:Linux terminal basics for navigating directories and working with files.
- Where to start:Open a terminal under your regular account. Start in the practice directory under your home folder.
- What you need:Have write access to your home directory so you can create and edit the sample files.
Guide tools
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.
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❯ Illustrative Output (Results Vary)
/home/samdrwxr-x--- 8 sam sam 4.0K Oct 4 09:15 .drwxr-xr-x 1 root root 4.0K Oct 1 08:00 ..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/log && pwd && cd - && pwd && cd ~ && pwd❯ Illustrative Output (Results Vary)
/var/log/home/sam/home/samCreate 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"❯ Illustrative Output (Results Vary)
The reports directory and status.txt are created under ~/linux-basics-lab.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❯ Illustrative Output (Results Vary)
Daily reportStatus: readyYour feedback keeps these production procedures accurate and battle-tested.