Useful Linux Terminal
Shortcut Keys
ctrl + R
= reverse search through historyctrl + L
= clear screenctrl + U
= clear linectrl + W/K
= clear before/after cursorctrl + A/E
= jump to begin/end of lineesc + .
= argument of the last commandctrl + X + E
= open current line in text editor
Commands
Find and replace in a previous command
Replace a string in the last matching command:
^find^replace
ex:
ssh 192.168.0.7
# do stuff on that server, now move on to the next...
^.7^.8
Return to previous directory
cd -
Re-run previous command with sudo
sudo !!
Refer to last string of previous command
You can use $_
to refer to the last string/argument. ex:
touch /path/to/file
nano $_
Create directories from list
xargs mkdir -p < list.txt
Combine multiple files into one
find . -name '*.txt' -exec cat {} + >> ../combined.txt
List processes with ports open
sudo netstat -tulnp
Human readable CSV output
Input doesn't need to be file, ie. sort
instead of cat
cat data.csv | column -t -s -n, | less -S
BSD/MacOS column does not support -n argument, so:
cat data.csv | sed 's/,/ ,/g' | column -t -s, | less -S
Useful Utilities
ncdu
ncurses disk usage analyzer - scans all directories in the path and shows a list sorted by size