Linux Cheat Sheet

NOTE: MORE ITEMS WILL BE ADDED TO THIS LIST

Today I decided to keep a Linux cheat sheet around to avoid looking up some common tasks on Google. I keep forgetting some commands and I feel like I should get them tattooed somewhere on the back of my hand so that I wouldn’t forget them. Although this list is currently very short, I will keep adding new stuff to it.

Program Specific:

     Git:

Update a submodule to the latest remote commit: git submodule update --remote --merge

     Screen:

Start a named session: screen -S [SESSION NAME]
Rename the session currently attached to: Ctrl + A ; :sessionname [NEW SESSION NAME]
List all sessions: screen -ls
Attach to a session screen -r [SESSION NAME]
Detach from window: Ctrl + A ; D
Exit screen: Ctrl + A ; \

     Fail2ban:

Unban an IP address: fail2ban-client set [JAIL NAME] unbanip [IP ADDRESS]

Script Related:

Autostart program: put the script in /etc/rc.local
Dump output to file (with stderr rerouting): [PROGRAM]  |& tee output.txt

Commands:

     File and Directory Management:

Create symbolic link: ln -s [TARGET] [LINK NAME]
Change to last working directory: cd -
Copy from remote to local rsync -az --progress [USERNAME]@[REMOTE HOST]:[REMOTE PATH] [LOCAL PATH]

     Searching:

Find a specific file:  find [START PATH] -name [NAME OF FILE]
Find a directory:  find [START PATH] -type d -name [NAME OF DIRECTORY]
Find text if files: grep -Ril "[TEXT TO FIND]" [START PATH]

     User Management:

List the groups that a user belongs to: groups
Add user to the list of sudoers: sudo adduser [USERNAME] sudo
Run program as another user: su [USERNAME] -c "[COMMAND TO RUN]"