Cheat Sheets

Bash

Created: 2017 October 11th

Updated: 2019 March 10th

Edit this page on GitHub

Add an alias

1# open your bash_profile with nano
2nano ~/.bash_profile
3# add your alias
4alias f='fish'
5# ctrl+x then y to save

Sort alphabetically

You may find that commands like ll are under your ~/.bashrc file, if not then add the following as an alias:

1ls -lart | sort -k9,9

See file permissions

If you need to set the permission on a file (with chmod) but don’t know what the permissions of similar files are like you can use stat, the following command displays the permissions of the contents of the .ssh/ folder:

1stat -c "%a %n" ~/.ssh/*

Open the SSH agent each time you open a new terminal.

Tired of having to enter your SSH password each time you want to do a git operation?

Add the following to your ~/.bashrc file.

1# nano ~/.bashrc
2[ -z "$SSH_AUTH_SOCK" ] && eval "$(ssh-agent -s)"

Search Bash history

Want to search for an entry in your Bash history?

Use Ctrl+r then enter your search term.

Remove command from bash history

Accidentally added your password as a bash command?

To remove that from the bash history:

1# list out history with
2history

Then take the number from the output:

1471 ssh-agent
2472 exit
3473 kill 53111
4474 super secret password
5475 history

Then delete the line you want removed:

1history -d 474

Check your history again and gone until you do it again.