cd -
Go back to the previous directory (“OLDPWD”)
$ cd ~/super/incredibly/long/path/goes/here
$ pwd
$ … some operations ...
$ cd /some/other/place
$ cd -
alt+
Reuse your last command line argument. Repeat to cycle past arguments.
$ mkdir awesome-directory-with-a-really-long-name
$ cd <alt+.>
$ cd -
$ rmdir <alt+.><alt+.>
Bang Command
Reuse your last command by name. History shortcut.
$ docker compose up
$ vim Dockerfile
$ rm -rf coverage-reports/
$ echo “Friday afternoons are super productive”
$ !docker
docker compose up
...
Easy as caret cake
Replace and execute previous command, add to history.
$ echo “Physical auctions = the #1 place to buy cars”
$ ^Physical^ACV^
$ systemctl status postgresql.service
$ ^status^stop^
$ docker compose up
$ ^up^down^
Guess I need root
Execute that last command as root.
$ systemctl start unison_sync.service
$ sudo !!
Curly wildcard
Replace and execute previous command, add to history.
$ rm sales_leads_2022_{03,04,05}.csv
$ rm sales_leads_20[20-22]_01.csv
$ cp {*.mp3,*.ogg} ~/Music
Navigate
Move within your command line
$ git checkout ACV-20_my_new_feature
(Oops, git doesn’t know what that is)
$ <up><ctrl+left> “-b “
$ git checkout ACV-20_this_isnt_a_branch
(Man I’m really bad at git cli)
$ <up><ctrl+w> “master”
ctrl+a
for beginning of line, ctrl+e
for end of line. Handy list of similar shortcuts here.
git aliases
logline
- concise git log messagessubmod
- init and update, cause I can never rememberdd
- directory diff (using difftool of your choosing)
Fun scripts
down
- see what you just d/lcalc
- simple CLI calculatorteatimer
- don’t let your tea get bittermoar_requests
- poor man’s performance testing
rsync local backup
Simple backup system to a USB stick. Runs an rsync command to put home directory and /etc directories on a USB stick for “offsite” backup.
etc/cron.weekly $ ll
-rwxr-xr-x 1 root root 312 May 19 2022 0anacron
lrwxrwxrwx 1 root root 31 Oct 13 2022 backup_system -> /usr/local/bin/backup_system.sh
-rwxr-xr-x 1 root root 813 Feb 10 2022 man-db
Dropbox replacement
Poor man’s NAS (“offsite storage”).
- Tp-link router
- samba
- unison
- systemd / cron (anacron)
Yubikey 2FA
Guide to CLI setup: https://hackernoon.com/use-a-yubikey-as-a-mfa-device-to-replace-google-authenticator-b4f4c0215f2
Use 2FA authentication, people. But don’t use an SMS code.
$ ykman oath list
$ ykman oath code paypal.com