Updated September 27, 2026 · By Ryan Bold
Linux commands become easier to remember when they solve one small task. This guide uses a practice directory to show how to create, inspect, search and copy files, then introduces read-only commands for checking the machine. The examples target a typical GNU/Linux shell; options can differ on macOS or minimal BusyBox systems.
Build a practice folder
practice_dir=$(mktemp -d "$HOME/farsivid-practice.XXXXXX") || exit
cd "$practice_dir" || exit
pwd
printf 'alphanbetanalphan' > sample.txt
ls -lh
pwd prints your working directory. Check that it is the new farsivid-practice. directory with its unique suffix. mktemp -d avoids overwriting a previous exercise. The redirection operator > creates or overwrites a file; use these examples only inside this practice directory. >> appends instead. Quoting paths keeps spaces from splitting one filename into multiple arguments.
Inspect and summarize the file
cat sample.txt
head -n 2 sample.txt
tail -n 1 sample.txt
wc -l sample.txt
sort sample.txt | uniq -c
grep -n 'beta' sample.txt
Expected results: three lines in the file, two occurrences of alpha, one of beta, and a match for beta on line 2. The pipe sends one program’s output into the next. uniq combines adjacent repeats, which is why the example sorts first. This is a small but useful distinction when you summarize log messages.
Use less sample.txt for a longer file: type /beta to search and q to quit. These keys belong to the pager, not the shell.
Copy, compare and find
cp -i sample.txt sample-copy.txt
diff -u sample.txt sample-copy.txt
find . -maxdepth 1 -type f -name '*.txt'
stat sample.txt
An empty diff result means the two files have no line differences. cp -i asks before overwriting an existing destination. The quoted wildcard in find is interpreted by find itself. stat shows metadata, including size and timestamps; it does not explain who changed the contents or why.
Check a system without changing it
| Question | Command | How to interpret it |
|---|---|---|
| How full are mounted filesystems? | df -h |
Compare the filesystem and mount point, not just the largest percentage. |
| How large is this directory? | du -sh . |
Summarizes files you can access under the current directory. |
| What memory is available? | free -h |
Available memory is more useful than judging cached memory as wasted. |
| What processes are running? | ps aux |
A snapshot; use top for changing activity and q to exit. |
| What network addresses exist? | ip -brief address |
Shows interfaces and addresses without changing routing. |
Turn the sample into a result you can predict
Try to predict each result before executing the command. With the three-line sample, grep -n 'beta' sample.txt should print 2:beta. The numeric output of wc -l < sample.txt should be 3. Sorting before uniq -c produces counts of two for alpha and one for beta; spacing around the counts can vary.
Now search for a word that is absent:
grep -n 'gamma' sample.txt
printf 'grep exit status: %sn' "$?"
The expected status is 1 for no matching line. That differs from status 2, which indicates an error. Run the status-printing command immediately: another command would replace the status you meant to inspect. GNU documents this distinction in its grep exit-status reference.
A blank result is therefore not always a broken command. For diff, no output with status 0 means the files match; for this grep search, no output with status 1 means the requested text was absent. Learning the program’s result contract is more useful than memorizing a long list of commands.
Learn the installed command’s options
Try man cp, man find or ls --help. The manual installed with your distribution is the best match for its packaged version. GNU also maintains the Coreutils project documentation for many of the file tools used here.
Commands such as rm, chmod, chown and sudo deserve separate attention because they delete data, alter permissions or run with additional authority. You do not need them for this exercise. Finish by reopening sample.txt and explaining each command’s result in your own words before adapting the workflow to real files. For a package-installation example that uses the same verify-before-changing approach, see installing Zoom from its official DEB package.
Command verification record
On September 8, 2026, the grep match and no-match cases, line count, sorted duplicate counts, and copy/diff example were executed in an isolated temporary folder on Ubuntu 24.04.4 LTS with GNU Coreutils 9.4 and GNU grep 3.11. They produced the results described above. This checks the small file exercise; it does not test every distribution, interactive pager or system-inspection command.