The terminal commands worth learning first

CS Fundamentals 2 min read
Short answer

Learn cd, ls, pwd, mkdir, cp, mv, rm, cat, grep, find, and pipes. Between them they handle almost everything you will do in a shell.

bash
pwd                    # where am I
ls -la                 # list everything, including hidden files
cd projects/site       # move into a directory
cd ..                  # up one level
cd -                   # back to the previous directory

#Files

bash
mkdir -p a/b/c         # create nested directories
cp file.txt backup.txt
cp -r src/ dist/       # -r for directories
mv old.txt new.txt     # rename, or move
rm file.txt
rm -r folder/
touch newfile.txt

#Reading

bash
cat file.txt           # whole file
head -20 file.txt      # first 20 lines
tail -f app.log        # follow a log as it is written
less file.txt          # scroll; q to quit
wc -l file.txt         # count lines

#Searching

bash
grep "error" app.log
grep -ri "todo" src/        # recursive, case-insensitive
find . -name "*.test.js"
find . -type f -mtime -1    # modified in the last day

#Pipes and redirection

bash
cat access.log | grep 404 | wc -l      # count 404s
ls -la > listing.txt                   # write, overwriting
echo "line" >> notes.txt               # append
command 2>&1 | tee output.txt          # capture stdout and stderr, and show them

Piping one small tool into another is the whole design philosophy of the shell.

#Time savers

  • Tab completes paths and commands. Use it constantly.
  • Ctrl+R searches your command history.
  • Ctrl+C stops a running command; Ctrl+D ends input.
  • !! repeats the last command — sudo !! is the classic.