The most effective way to learn Linux commands is not to memorize a list but to work through exercises on a real system, starting with navigation and file inspection, then moving to text processing, permissions, processes, and piping—because each layer depends on the one before it. This guide gives you a structured exercise sequence, explains why each drill matters, and points out the distinctions (absolute versus relative paths, > versus >>, soft versus hard links) that cause most beginner confusion. It assumes a Bash shell on a typical Linux distribution; almost everything here also works on macOS and WSL, with minor differences noted.
The single most important piece of setup advice: practice in a scratch directory or a disposable virtual machine. Many exercises below deliberately delete, overwrite, and rename files. If you run them in your home directory, you will eventually destroy something you care about.
Before You Start: The Mental Model
Linux commands follow a simple grammar: command [options] [arguments]. Options usually begin with - (short) or -- (long), and arguments are the things the command acts on. Almost every command has a manual page you can read with man command, and most support --help for a quick summary. Two habits make everything else easier:
Tab completion. Pressing Tab completes file names and commands; pressing it twice lists candidates. This reduces typing errors dramatically and teaches you what exists. Reading error messages. No such file or directory almost always means a path problem, not a broken command.
Create your workspace first:
The -p flag creates parent directories as needed and does not complain if they already exist—a small but instructive detail.
Exercise Set 1: Navigation and Orientation
The goal here is to make paths instinctive. Beginners often confuse where they are with where a file is; these drills separate the two.
Exercise 1.1 — Find yourself. Run pwd, then cd /tmp, then pwd again, then cd -. The cd - command returns you to the previous directory, which is faster than retyping a long path.
Exercise 1.2 — Relative versus absolute. From ~/linux-practice, run cd docs (relative), then cd ~/linux-practice/docs (absolute), then cd ../logs (relative, going up one level). Confirm each with pwd. The distinction matters because scripts should generally use absolute paths or paths anchored to a known variable, while interactive use favors relative paths for speed.
Exercise 1.3 — List intelligently. Run ls, then ls -l, then ls -la, then ls -lh. Compare the outputs. -l gives the long format (permissions, owner, size, date); -a includes hidden files beginning with a dot; -h makes sizes human-readable. Notice that . and .. appear with -a—they are real directory entries, which is why cd .. works.
Exercise 1.4 — Inspect without opening. Use file docs and file /etc/hosts. The file command guesses content type from the file's bytes rather than its extension, a habit that pays off constantly on Linux, where extensions are conventions rather than requirements.
A compact reference for the flags you will use most:
| Flag pattern | Typical meaning | Example |
|---|---|---|
| -l | long listing | ls -l |
| -a | include hidden | ls -a |
| -h | human-readable | du -h |
| -r / -R | recursive (varies!) | cp -r, ls -R |
| -f | force | rm -f |
| -i | interactive/confirm | rm -i |
Note the trap: -r means "recursive" for cp and rm, but for ls it means "reverse order" while -R means recursive. Always check man when a flag's meaning seems off.
Exercise Set 2: Creating, Copying, Moving, and Deleting
Exercise 2.1 — Build a file tree. Inside ~/linux-practice, run:
The touch command creates empty files (or updates timestamps on existing ones). The distinction between > and >> is one of the most consequential in the shell: > truncates and overwrites, while >> appends. Run the two echo lines again with > on the second and watch the first line vanish—then restore it. This is the classic way people accidentally destroy log files.
Exercise 2.2 — Copy versus move. Run cp docs/notes.txt backup/ and then mv docs/todo.txt backup/. Check both locations with ls. cp leaves the original; mv removes it. Then try cp -r docs backup/ to copy a whole directory, and observe that without -r, cp refuses to copy directories—a safety feature, since recursive copies can be expensive.
Exercise 2.3 — Rename with mv. There is no rename command in the base toolkit; renaming is moving. Run mv backup/todo.txt backup/tasks.txt and confirm.
Exercise 2.4 — Delete carefully. Create a throwaway file, then run rm -i on it and answer the prompt. Compare with rm -f. The -i flag asks for confirmation; -f forces deletion without asking. There is no recycle bin for rm; deleted files are gone unless you have backups or specialized recovery tools. Never run rm -rf with a variable you have not checked—an empty variable combined with a slash is a well-known way to erase a system.
Exercise 2.5 — Hard and soft links. This is the concept most often skipped and most often tested:
The -i flag to ls shows inode numbers. The hard link shares the same inode as the original, so editing either changes both, and deleting the original leaves the data intact through the link. The soft (symbolic) link has its own inode and merely points at a path; if the target is deleted, the link dangles. Hard links cannot cross filesystems and generally cannot point to directories; soft links can do both. That single distinction explains most real-world link behavior.
Exercise Set 3: Reading and Searching Text
Exercise 3.1 — View files three ways. Run cat docs/notes.txt, then less docs/notes.txt (press q to quit, / to search inside), then head -n 5 logs/app.log and tail -n 5 logs/app.log. Use cat for short files and less for anything long; cat on a large file floods your terminal and can be hard to interrupt.
Exercise 3.2 — Follow a growing file. In one terminal, run tail -f logs/app.log. In another, append a line with echo "new event" >> logs/app.log and watch it appear. This is how you watch live logs in practice. Press Ctrl+C to stop.
Exercise 3.3 — Search with grep. Populate a file with several lines and search it:
The flags matter: -i ignores case, -c counts matching lines, and -v inverts the match (shows non-matching lines). Add -n to print line numbers and -r to search recursively through a directory.
Exercise 3.4 — Find files. Run find ~/linux-practice -name "*.txt" and then find ~/linux-practice -type d. The find command walks the filesystem and filters by name, type, size, modification time, and more. It is more precise than ls for location tasks, and unlike locate it does not depend on a prebuilt index.
Exercise 3.5 — Count and summarize. Run wc -l logs/app.log (line count) and wc -w docs/notes.txt (word count). Then try sort logs/mixed.log | uniq -c. Notice that uniq only collapses adjacent duplicates, which is why sort almost always precedes it—a pairing worth memorizing.
Exercise Set 4: Pipes and Redirection
Pipes are where Linux starts to feel like a language rather than a list of tools. The pipe | sends the output of one command into the input of the next; redirection > and >> send it to files; < reads from a file; and 2> redirects standard error.
Exercise 4.1 — Chain a pipeline. Run:
Then simplify it to grep -c error logs/mixed.log and compare. The pipeline works but spawns extra processes; the direct form is cleaner. Knowing both helps you recognize when a pipeline is unnecessary.
Exercise 4.2 — Sort and deduplicate. Create a file with repeated names, then run sort names.txt | uniq and sort names.txt | uniq -c. Then try sort -r for reverse order and sort -n on a file of numbers—-n sorts numerically, so 10 comes after 9 instead of before it. Lexical sorting (the default) is a frequent source of surprise.
Exercise 4.3 — Separate standard output from standard error. Run a command that produces both:
Inspect both files. The shell numbers streams: 0 is standard input, 1 is standard output, 2 is standard error. 2>&1 merges error into output, and &> does the same as a Bash shorthand. Redirecting errors separately is essential when writing scripts that should log failures without polluting normal output.
Exercise 4.4 — Use tee. Run echo "hello" | tee docs/copy.txt and confirm the text appears both on screen and in the file. tee splits a stream, which is useful when you want to watch output and save it simultaneously.
Exercise 4.5 — Extract columns. With a space- or colon-separated file, run cut -d: -f1 /etc/passwd to print the first colon-delimited field. Substitute awk -F: '{print $1}' and awk '{print $2}' for whitespace-delimited data. The three tools—cut, awk, sed—form the classic text-processing trio; start with cut and awk printing fields, and add sed substitutions (sed 's/old/new/g') once field extraction is comfortable.
Exercise Set 5: Permissions
Permissions confuse people because the notation packs three ideas into one string. Read -rwxr-xr-- as: file type (- regular file, d directory, l symlink), then owner permissions, group permissions, and others' permissions, each in rwx order.
Exercise 5.1 — Read the mode. Run ls -l docs/notes.txt and identify each part. Then run stat docs/notes.txt for the numeric mode.
Exercise 5.2 — Change permissions with symbolic notation. Run chmod u+x docs/notes.txt, then chmod g-w docs/notes.txt, then chmod o-r docs/notes.txt, checking with ls -l after each. Symbolic notation uses u (user/owner), g (group), o (others), and a (all), with +, -, and = to add, remove, or set.
Exercise 5.3 — Change permissions with octal notation. Run chmod 644 docs/notes.txt and chmod 755 backup. The digits encode read (4), write (2), and execute (1) summed per category, so 6 = read+write, 5 = read+execute, and 7 = all three. Directories need execute permission to be entered—a detail that explains why chmod 644 somedirectory makes it unusable.
Exercise 5.4 — Ownership. Run ls -l and note the owner and group columns. On a system where you have sudo, try sudo chown root docs/notes.txt and then change it back with sudo chown $USER docs/notes.txt. The $USER variable expands to your username; the chgrp command changes group separately.
Exercise 5.5 — The sticky bit and setuid, conceptually. Run ls -ld /tmp and notice the trailing t. That sticky bit on /tmp means only a file's owner (or root) can delete it inside a shared directory—a safety rule rather than a permission on the file itself.
Exercise Set 6: Processes and Jobs
Exercise 6.1 — See what is running. Run ps aux | head -n 10 and then top (press q to quit). ps gives a snapshot; top updates live. The ps aux combination shows all processes with user-oriented detail.
Exercise 6.2 — Background a job. Run sleep 60 &, then jobs, then fg. The ampersand puts the command in the background; jobs lists background jobs; fg brings one back to the foreground. Then try sleep 300 &, find its PID with jobs -l or ps, and stop it with kill PID. The kill command sends signals; the default is SIGTERM (15), a polite request to exit, while kill -9 sends SIGKILL, which cannot be caught and should be a last resort.
Exercise 6.3 — Watch a pattern. Run watch -n 2 date and observe the refresh, then quit with Ctrl+C. watch re-runs a command repeatedly, which is handy for monitoring.
Exercise Set 7: A Capstone Pipeline
Combine everything into one realistic task. Suppose you have a log file and want the five most frequent error messages:
Trace each stage out loud: filter for errors, strip the error: prefix by taking the second colon-delimited field, sort so duplicates are adjacent, count them, sort by count in descending numeric order, and show the top five. If you can explain every pipe, you have the practical core of command-line fluency.
Then extend it: redirect the output to a file with >, append a timestamp with date, and check the exit status with echo $?. An exit status of 0 means success; anything else is a failure code. This is how scripts make decisions, and it is a habit worth forming early.
Common Pitfalls and How the Exercises Expose Them
| Mistake | Why it happens | Exercise that teaches it |
|---|---|---|
| Overwriting a log with > | Redirection truncates by default | 2.1 |
| rm -rf $DIR/ with empty $DIR | Variable expanded to nothing | 2.4 |
| Assuming -r means recursive everywhere | Flag meanings vary per command | 1.4 / legend table |
| Sorting numbers as text | Default sort is lexical | 4.2 |
| uniq without sort | Only adjacent duplicates collapse | 3.5 |
| Expecting a recycle bin | rm is permanent | 2.4 |
| Deleting via a soft link vs. the target | Links point to paths, not data | 2.5 |
Two more distinctions deserve mention. First, command -h and --help are not universal; when both fail, man is the fallback. Second, quoting matters: rm "file with spaces.txt" works, while unquoted paths split at spaces and cause the command to act on the wrong files. Get into the habit of quoting any path you did not type by hand, and use "$VARIABLE" in scripts so an empty variable expands to an empty argument rather than nothing at all.
Frequently Confused Pairs, Briefly
versus >>: overwrite versus append. Hard link versus soft link: same inode versus pointer to a path. cp versus mv: duplicate versus relocate (and rename). grep -c versus wc -l: grep -c counts matching lines directly; wc -l counts lines in whatever it receives, so grep error file | wc -l counts matches indirectly. kill versus kill -9: polite signal versus forced termination. find versus locate: live traversal versus indexed lookup.
How to Keep Practicing
The exercises above take a few focused hours. To retain them, repeat the capstone pipeline from memory a week later, then modify it: count warnings instead of errors, search two files instead of one with grep -r, and save the output with a dated filename. Each variation forces you to recall a flag or a redirection rule rather than copy it. For deeper reference, the man pages and the Bash manual are the authoritative sources, and every exercise here can be verified directly on your own system—which is the whole advantage of learning commands by doing rather than by reading.