or, the “the wisdom of the tee” part.
cd, ls, rm, mv, vim&, >, top, ps, kill, killall, which, locate, fgcurl, whois, traceroute, ping, lsof, scpzxlearning how to use the terminal of your computer is a console without any buttons. you are expected almost to know which “buttons” are hidden there below the surface. no one ever gave me a primer and it was painful to learn over time through trial and error what those hidden commands are. here’s a compilation of some useful commands to get you through most basic functions and some more interesting ones.
btw, god help you if you need to write shell scripts. ugh, i think they’re the worst syntactically. my tendency is to write node or python scripts instead because at least they make bore sense to me.
cd [name] — change directory~ is shorthand for your home directory.. is shorthand for the parent directory. is shorthand for the current directory- is shorthand for the previous directory you were in (like your browser’s “back” button)cd .. will take you to the parent directoryls — list contents of the directory you’re inls -lah is useful to list hidden files as wellrm [file] — remove a filerm -r [file] — remove a directorymv \[origin\] [destination] — move a file somewhere elseclear — also, clears screenvim [file] — edit a filei to go to insert modeesc to go back to command-mode/ to search in the file:w (in command mode) to save:q (in command mode) to quitthis is a pet peeve of mine that no one ever taught me these super handy shortcuts and i didn’t know about them for many years.
[ctrl] + a — go to beginning of the line [ctrl] + e — go to the end of the line [ctrl] + c — kill the currently running program [ctrl] + k — clear screen [ctrl] + z — pause the currently running program
| — the “pipe”. pass the output from one process to another, e.g. history | grep cdhistory — see the list of commands you’ve tried in the pastgrep [pattern] * — search the files in the current directory for the patternripgrep, you can install via brew install ripgrepgrep [pattern] * -rsiI — search recursively, case-insensitive, ignoring binary fileshistory | grep [pattern] — find relevant commands in your history you’ve used beforecat [file] — output the contents of a fileless [file] — scroll through the contents of a file (space to page through, q to quit)man [command] — show help file for a command, [cmd] -h or [cmd] --help also can workfind . -name '[file]' — find a file by a specific namefd, you can install via brew install fddf -h — show local hard disk spacedu -sch * |sort -hr — show the biggest files under a particular subdirectorydust, you can install via brew install dustsudo [command] — run command with elevated privilegestail -f [file] — see real-time updates to a file, used especially with a log file on a servertouch [file] — creates file if doesn’t exist, or updates its timestampalias [shortcut]='[command to run]' — take a long command that’s hard to remember and create a shortcut for it, e.g. alias v='ls -lah'sh — open up another shell (zsh if you’re using that)exit — to exit the shell[cmd] & — adding the ampersand at the end of a command will run it in the background[cmd] > output.txt — adding a > will save output of the program to a particular filetop — find out what’s current running on your machineps aux — see the processes currently running on your machineps aux | grep [name] — super common way to find the process you’re looking forkill [process id] — you can grab a process id from the ps aux list and kill itkillall [name] — kill process(es) matching the namewhich [command] — find out the directory where a program liveslocate [pattern] — find files on your local machine matching the pattern (macOS only)fg — start a paused program again (via [ctrl] + z), or, use bg to run it in the backgroundcurl -O [url] — retrieve a webpage and save it diskwhois [domain] — find out info about a particular websitetraceroute [domain] — show computer hops from router to router to a destinationping [domain] — simple test to see if a website is up or notping6 [domain] — same as above, but for IPv6lsof -i :[port] — see which process is using which port.lsof -t -i tcp:[port] | xargs kill -9 — to easily kill whatever’s on a port.scp username@remotehost:/path/to/file /path/to/save/locally — copy a file from a remote serverssh-keygen -t rsa -b 4096 -C "[example@email.com]" — generate SSH keyssh-add -K ~/.ssh/id_rsa — add password to your keychain to save timetar -czvf \[name\] [file] — compress a file/directory into an archivetar -xzvf [file] — uncompress an archivegrep [pattern] * -rsiIl | xargs sed -i '' s/[pattern]/[replacewith]/g —sudo chown -R $USER:$USER file — transfer ownership of a directory and its files to yourselfjq '[selector]' < example.json — if your server logs are in JSON format you can query them using the jq commandfc — fix command. open up the last command you tried to run in an editor.<( somecommand ) — treat a command output as a file. e.g. try diff <(ls) <(ls -a)cmatrix — make it look like you’re doing something important 😉shellcheck — check your shell script for errors before running it.zx — a handy JS tool around shell scripting that makes running multiple commands a little more intuitive for those of us that don’t live on the command line day-to-day (i.e. most of us).