CMD

​screencapture (capture images from screen)

1
# Take screenshot & save it to Desktop with current date as name
2
screencapture -ixoa -t jpg ~/"Desktop/$(date).jpg"
Copied!

​docker (run processes in isolated containers)

1
# Delete all containers
2
for i in $(docker ps -a -q); do docker rm $i; done
3
​
4
# List all containers
5
docker ps -a
6
​
7
# Remove a container after it’s stopped
8
docker run --rm [...]
Copied!

​kubectl (run commands against Kubernetes clusters)

1
# Get info on pods in use. Has info on why they failed if they did.
2
kubectl describe pods
3
​
4
# Get services across all namespaces
5
kubectl get svc --all-namespaces
6
​
7
# Port forward the <pod> from 5432 to localhost 5300 port
8
kubectl port-forward <pod> 5300:5432
Copied!
​nix-env (manipulate or query Nix user environments)
1
# See installed packages
2
nix-env -q
3
​
4
# Install packages
5
nix-env -iA
Copied!
​basename (strip directory and suffix from filenames)
1
basename "/Users/nikivi/Documents/books/Thinking, fast and slow.pdf" # => Thinking, fast and slow.pdf
Copied!
​chmod (change file mode bits)
1
# All users can read and write but cannot execute
2
chmod 666
3
​
4
# All actions for all users
5
chmod 777
6
​
7
# Only owner can do all actions; group and other users are allowed only to read
8
chmod 744
Copied!
​tail (output the last part of files) https://www.explainshell.com/explain/tail​
1
# Shows the last 10 lines of file
2
tail /etc/passwd
3
​
4
# -n option allows to change the number of lines to display
5
# where n is the number of lines you want to see
6
# ie
7
tail -5 /etc/passwd
8
​
9
# Use tail +n to print lines starting at line n
Copied!
​playgo (send .go file to the Go Playground)
1
# Open Go playground of file in browser
2
playgo <file>
Copied!
​tr (translate or delete characters)
1
# Convert all input to upper case
2
ls | tr a-z a-z
3
​
4
# Take the output and put into a single line
5
ls | tr "\n" " "
6
​
7
# Get rid of all numbers
8
ls -lt | tr -d 0-9
Copied!
​diff (compare files line by line)
1
# Compare file1 with file2
2
diff file1 file2
Copied!
​find (walk a file hierarchy)
1
# Will search in current directory (.) for the file 'hello_world.py'
2
# and will return the path to the file
3
find . -name 'hello_world.py'
4
​
5
# You can also search multiple directories
6
# will search both Documents and Desktop folders for the file
7
find Documents Desktop -name 'hello_world.py'
Copied!
​grep (file pattern searcher)
1
# Print lines from a file or input stream that match an expression
2
​
3
# -i = case insensitive search
4
​
5
# -v = return all lines that do not contain {}
6
grep -v {} story.txt
Copied!
​man (open manual pages)
1
# Search for manual page by keyword
2
man -k keyword
3
​
4
# ie if you are looking for command to sort something, run
5
# output will include man page name, man section and quick description
6
man -k sort
7
​
8
# **Online manual sections**
9
​
10
# (1) = user commands
11
# (2) = system calls
12
# (3) = higher-level unix programming library documentation
13
# (4) = device interface and driver information
14
# (5) = file descriptions (system configuration files)
15
# (6) = games
16
# (7) = file formats, conventions, and encodings (ASCII, suffixes, and so on)
17
# (8) = system commands and servers
18
​
19
# Open manual page of passwd on section 5
20
man 5 passwd
21
​
22
# I can often get information about options of some command using either --help or -h flags
23
# ie
24
vim --help # vim -h would also work
Copied!
​sort (put the lines of a text file in alphanumeric order)
1
# Will process the results of ps aux command with grep
2
# and will then sort the output with 'sort' command
3
ps aux | grep bash | sort
4
​
5
# -n option sorts in numerical order
6
# -r option reverses the order of the sort
Copied!
PlistBuddy (read and write values to plists)
1
# Change version of Alfred workflow info.plist
2
/usr/libexec/PlistBuddy -c "Set :version \"X.Y.Z\"" info.plist
Copied!
​kill (send a signal to a process)
1
# Force quit the process with id 1456
2
kill -9 1456
3
​
4
# Stop process 1456
5
kill -STOP 1456
Copied!
​head (output the first part of files)
1
# Shows the first 10 lines of file
2
head /etc/passwd
3
​
4
# -n option allows to change the number of lines to display
5
# where n is the number of lines you want to see
6
# ie
7
head -5 /etc/passwd
Copied!
tar (manipulate tape archives)
1
# Extract tar files. -x = 'extract'. -v = verbose. -f = point to tar fle
2
tar -xvf some_file.tar.gz
Copied!
env (set environment and execute command, or print environment)
1
# View enviroment variables
2
env
3
​
4
# Variables to know
5
$HOME # Expands to the path of my home folder
6
$PS1 # Represents my command prompt line
7
​
8
# I can thus change the way my command prompt looks like this
9
PS1="\w >"
10
​
11
$PATH # Lists all the directories that can be executable with commands
12
​
13
# Add directory /Users/nikivi/bin to the path
14
export PATH=/Users/nikivi/bin:$PATH
15
​
16
# If you put executables there, they will be available
17
​
18
# Exported variables get passed on to child processes. Not-exported variables do not.
Copied!
cat (concatenate and print files)
1
# Print what is in file1 and file2 to screen
2
cat file1 file2
Copied!
​ngrok (expose your localhost to the web)
1
# Creates a shareable link of my local server on port 3000
2
ngrok http 3000
Copied!
rmdir (remove empty directories)
1
# Remove directory
2
rmdir dir
3
​
4
# Remove non empty directores
5
rm -rf dir
6
​
7
# Don't use -rf flags with globs such as star (*)
8
# Best to double check commands before running
Copied!
​mediumexporter (export medium.com articles to markdown)
1
# i.e.
2
mediumexporter https://medium.com/@nikitavoloboev/karabiner-god-mode-7407a5ddc8f6 > medium_post.md
Copied!
file (determine file type)
1
# See type of file
2
file <file>
Copied!
time (time command execution)
1
# Time how long command took to run
2
time <cmd>
Copied!
Last modified 1yr ago