Skip to content
5 min read·Lesson 2 of 10

Command-Line Essentials

Navigation, file operations, permissions, processes, and the small set of commands that cover 90% of daily shell work.

Productivity at the shell is mostly muscle memory built on a small vocabulary of commands. This lesson covers the ones you'll use every day.

Where Am I, What's Here

pwd                # print working directory
ls                 # list files
ls -la             # long format, including hidden
ls -lh             # human-readable sizes
cd /var/log        # change directory
cd ~               # home directory
cd -               # previous directory
tree -L 2          # directory tree (if installed)

File Operations

cp source dest                 # copy
cp -r src/ dest/               # recursive
mv old new                     # move or rename
rm file                        # delete file
rm -rf dir                     # delete directory recursively (DANGER)
mkdir -p a/b/c                 # create nested directories
touch file                     # create empty file or update mtime
ln -s /path/to/target link     # symbolic link

Warning: rm -rf with the wrong path has caused real outages. Verify the path before pressing Enter, especially with variables: rm -rf "$DIR/" when $DIR is empty becomes rm -rf /.

Reading Files

cat file               # whole file to stdout
less file              # paged viewer; q to quit, / to search
head -n 20 file        # first 20 lines
tail -n 50 file        # last 50 lines
tail -f /var/log/app.log   # follow appending log
wc -l file             # line count

Finding Things

find . -name "*.log"               # by name
find /var -type f -mtime -1        # files modified in last 24h
find . -size +100M                 # files larger than 100MB
find . -name "*.tmp" -delete       # match and delete

grep "error" app.log               # match lines
grep -i "error" app.log            # case-insensitive
grep -r "TODO" src/                # recursive
grep -n "fn main" src/main.rs      # show line numbers
grep -v "DEBUG" app.log            # invert: lines NOT matching

ripgrep (rg) is a faster, smarter alternative — install it where you can.

Permissions

ls -l
-rwxr-xr--  1 alice users  1234 Jan 15  script.sh

The 10 characters break down as: type (- file, d directory, l symlink), then three triples — owner, group, others — each rwx.

OctalSymbolicMeaning
4rread
2wwrite
1xexecute
755rwxr-xr-xtypical script
644rw-r--r--typical file
700rwx------private executable
600rw-------private file (e.g. SSH key)
chmod 755 script.sh
chmod +x script.sh         # add execute for all
chown alice:users file     # change owner and group
sudo chown -R www-data /var/www/site

Processes

ps aux                     # all processes
ps -ef | grep nginx        # find process
top                        # live process view
htop                       # nicer; install if available
kill 12345                 # send TERM to PID
kill -9 12345              # send KILL (last resort)
pkill nginx                # by name
killall -SIGTERM worker
jobs                       # background jobs in this shell
fg %1                      # bring job 1 to foreground
bg %1                      # resume job 1 in background
nohup long-job &           # detach from shell
disown

The Two Most Important Productivity Tricks

  • Tab completion — press Tab once to complete; twice to list candidates. Works for commands, paths, branches in git, kubectl resources, etc.
  • Reverse history search — Ctrl-R, then start typing. Bash searches your history; Enter runs, arrow keys edit. This single shortcut replaces most of your typing.

Other Daily Commands

df -h                  # disk space, human-readable
du -sh *               # size of each item in cwd
free -h                # memory
uname -a               # OS info
uptime                 # how long the box has been up
who / w                # who is logged in
date                   # current date/time
date -u +%Y-%m-%dT%H:%M:%SZ   # ISO 8601 UTC

curl -sSL https://example.com   # HTTP get
wget -O file.tar.gz https://example.com/x.tgz   # download

tar -czf out.tgz dir/   # create gzip tarball
tar -xzf out.tgz        # extract

ssh user@host
scp file user@host:/tmp/
rsync -avz src/ user@host:/dest/

Help

man ls           # full manual
ls --help        # quick usage
type ls          # is it a command, alias, or function?
which python     # path to executable
apropos backup   # search man pages

The tldr tool (tldr ls) gives short, example-driven help — install it.

Cert Mapping

CertScope
RHCSA / LFCSAll of the above is on the exam
AWS SAAEC2 troubleshooting from SSM Session Manager
Kubernetes (CKA / KCNA)kubectl exec into containers; same commands inside

With the basics in hand, the next lesson moves to the heart of scripting: variables and the quoting rules that make or break Bash scripts.

Key Takeaways

  • A small set of commands (cd, ls, cp, mv, rm, find, ps, grep, less) covers most daily tasks.
  • Tab completion and history (Ctrl-R) are the two largest productivity multipliers.
  • Permissions are octal triples for owner, group, and others.
  • Processes are managed with ps, kill, jobs, fg, bg, and signals.
  • man and --help are your first stop, every time.

Test your knowledge

Try exam-style practice questions to reinforce what you've learned.

Practice Questions →