Skip to content
AI-grafen
DAI developerProgramming· about 45 min· fundamentals that rarely change· verified 2026-09-20· EN

The terminal and the shell

Be able to navigate, run programs and connect commands together in a Unix shell.

Prerequisites

Intuition

The basics:

CommandDoes
pwdwhere am I?
ls -lalist the files, hidden ones included
cd ../datachange directory
cat file.txtshow the contents
less file.txtpage through it (q to quit)
cp a b, mv a b, rm acopy, move, remove
mkdir -p a/bcreate a directory tree
grep -r "pattern" .search in files
find . -name "*.csv"find files

rm does not ask. There is no wastebasket.

Code

# A pipe: send the output of one command to the next
cat data.csv | wc -l                       # the number of lines
grep "ERROR" app.log | head -20            # the first 20 errors

# Redirection
python train.py > output.txt 2>&1          # stdout and stderr to a file
python train.py >> log.txt                 # append instead of overwriting

# A chain: find the ten most common errors in a log
grep "ERROR" app.log | cut -d' ' -f5- | sort | uniq -c | sort -rn | head -10

# Environment variables — this is how you pass secrets to a program
export API_KEY="..."        # only in this terminal
python script.py            # os.environ["API_KEY"] in Python

# Run it in the background and keep the log
nohup python long_job.py > job.log 2>&1 &

The chain above is why the shell is worth learning: six small programs that each do one thing, connected into an analysis that would have taken twenty lines of Python.

Mastery means

  • Navigates and handles files in a shell
  • Connects commands together with pipes and redirection
  • Runs programs with arguments and environment variables

Sign in to do the exercises and build your mastery up.

Sources

All the sources and licences