# Delete all containers
for i in $(docker ps -a -q); do docker rm $i; done
# List all containers
docker ps -a
# Remove a container after it’s stopped
docker run --rm [...]
kubectl (run commands against Kubernetes clusters)
# Get info on pods in use. Has info on why they failed if they did.
kubectl describe pods
# Get services across all namespaces
kubectl get svc --all-namespaces
# Port forward the <pod> from 5432 to localhost 5300 port
kubectl port-forward <pod> 5300:5432
nix-env (manipulate or query Nix user environments)
# All users can read and write but cannot execute
chmod 666
# All actions for all users
chmod 777
# Only owner can do all actions; group and other users are allowed only to read
chmod 744
# Shows the last 10 lines of file
tail /etc/passwd
# -n option allows to change the number of lines to display
# where n is the number of lines you want to see
# ie
tail -5 /etc/passwd
# Use tail +n to print lines starting at line n
# Convert all input to upper case
ls | tr a-z a-z
# Take the output and put into a single line
ls | tr "\n" " "
# Get rid of all numbers
ls -lt | tr -d 0-9
# Will search in current directory (.) for the file 'hello_world.py'
# and will return the path to the file
find . -name 'hello_world.py'
# You can also search multiple directories
# will search both Documents and Desktop folders for the file
find Documents Desktop -name 'hello_world.py'
# Print lines from a file or input stream that match an expression
# -i = case insensitive search
# -v = return all lines that do not contain {}
grep -v {} story.txt
# Search for manual page by keyword
man -k keyword
# ie if you are looking for command to sort something, run
# output will include man page name, man section and quick description
man -k sort
# **Online manual sections**
# (1) = user commands
# (2) = system calls
# (3) = higher-level unix programming library documentation
# (4) = device interface and driver information
# (5) = file descriptions (system configuration files)
# (6) = games
# (7) = file formats, conventions, and encodings (ASCII, suffixes, and so on)
# (8) = system commands and servers
# Open manual page of passwd on section 5
man 5 passwd
# I can often get information about options of some command using either --help or -h flags
# ie
vim --help # vim -h would also work
sort (put the lines of a text file in alphanumeric order)
# Will process the results of ps aux command with grep
# and will then sort the output with 'sort' command
ps aux | grep bash | sort
# -n option sorts in numerical order
# -r option reverses the order of the sort
PlistBuddy (read and write values to plists)
# Change version of Alfred workflow info.plist
/usr/libexec/PlistBuddy -c "Set :version \"X.Y.Z\"" info.plist
# Shows the first 10 lines of file
head /etc/passwd
# -n option allows to change the number of lines to display
# where n is the number of lines you want to see
# ie
head -5 /etc/passwd
tar (manipulate tape archives)
# Extract tar files. -x = 'extract'. -v = verbose. -f = point to tar fle
tar -xvf some_file.tar.gz
env (set environment and execute command, or print environment)
# View enviroment variables
env
# Variables to know
$HOME # Expands to the path of my home folder
$PS1 # Represents my command prompt line
# I can thus change the way my command prompt looks like this
PS1="\w >"
$PATH # Lists all the directories that can be executable with commands
# Add directory /Users/nikivi/bin to the path
export PATH=/Users/nikivi/bin:$PATH
# If you put executables there, they will be available
# Exported variables get passed on to child processes. Not-exported variables do not.
cat (concatenate and print files)
# Print what is in file1 and file2 to screen
cat file1 file2
# Creates a shareable link of my local server on port 3000
ngrok http 3000
rmdir (remove empty directories)
# Remove directory
rmdir dir
# Remove non empty directores
rm -rf dir
# Don't use -rf flags with globs such as star (*)
# Best to double check commands before running