Works in Bash and, for the most part, zsh. <file> and <dir> are placeholders.
Move around
_10pwd # where am I_10ls -la # list, including hidden_10cd <dir> # go there_10cd - # back to the last folder_10cd ~ # home
Files and folders
_10mkdir -p a/b/c # make nested folders_10touch notes.txt # new empty file_10cp -r src backup # copy a folder_10mv old.txt new.txt # move or rename_10rm -r <dir> # delete, no undo_10ln -s target link # symbolic link
Read files
_10cat <file> # print it all_10less <file> # page through, q to quit_10head -n 20 <file> # first 20 lines_10tail -f app.log # follow new lines_10wc -l <file> # count lines
Find things
_10find . -name "*.ts" # by name_10find . -type f -mtime -1 # changed today_10grep -rn "TODO" src # search text_10grep -ri "error" app.log # ignore case_10which node # where a command is
Pipes and redirects
_10cmd > out.txt # write, replacing_10cmd >> out.txt # append_10cmd 2> err.txt # errors only_10cmd > all.txt 2>&1 # output and errors_10cmd1 | cmd2 # feed output onward_10sort data | uniq -c | sort -rn | head
Variables
_10name="Ann" # no spaces around =_10echo "Hi $name" # always quote_10today=$(date +%F) # command output_10echo "${name:-guest}" # default value_10export PORT=3000 # visible to children
Conditions
_10if [[ -f "$file" ]]; then_10 echo "exists"_10elif [[ -d "$file" ]]; then_10 echo "is a folder"_10else_10 echo "missing"_10fi_10[[ -z "$var" ]] && echo "empty"
Loops
_10for f in *.txt; do_10 echo "$f"_10done_10_10for i in {1..5}; do echo "$i"; done_10_10while read -r line; do_10 echo "$line"_10done < list.txt
Script boilerplate
_10#!/usr/bin/env bash_10set -euo pipefail # stop on errors_10_10main() {_10 local target="${1:?usage: run.sh <target>}"_10 echo "Building $target"_10}_10_10main "$@"
Make it runnable with chmod +x run.sh.
Processes
_10cmd & # run in background_10jobs # list background jobs_10ps aux | grep node # find a process_10kill <pid> # ask it to stop_10lsof -i :3000 # what is using a port