Shared settings between different shells.
Get basename of file
file_path=...
echo ${file_path##*/}
Get dirname of file
file_path=...
echo ${file_path%/*}
Remove all files except for specified one link:
rm -f !(survivior.txt)
Make a directory and move into it link
mkdir /home/foo/doc/bar && cd $_
Rename a file extension link
mv filename.{old,new}
Open Finder from the current Terminal location link
open .
Start COMMAND
, and kill it if still running after 5 seconds link
timeout 5s <COMMAND>
Run last command (potentially as root) link
[sudo] !!
Run last command starting with string
!string
Run previous command with changed arguments link
^foo^bar # changes first found match
^foo^bar^:& # changes all found matches
Invoke editor to edit command link
ctrl-x e
fc
# In vim mode; ie. go out of insert mode and v
<Esc> v
Use last argument of most recent command link
<Esc> _
$_
Delete and yank partial command link
<ctrl+u> [...] <ctrl+y>
# In vim mode; ie. same yanking as usual
<Esc> dd [...] p
Show currently mounted file systems link
mount | column -t
Show external IP link
curl ifconfig.me
Serve current directory as LAN server link
python -m SimpleHTTPServer 8080
python3 -m http.server 8080