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]"

Automount NTFS Partitions with All Permissions

Somethings really need to be burned onto the inside of my skull., since I forget them ALL the time. This is especially true for Linux commands for trivial tasks. Automounting NTFS partitions with execution permission in Linux is one of those things for me. Here’s how to do it in Linux Mint (or probably any other Debian-based Linux distro)

1) Find  the UUID of your partition by

 

2) Add the following line in the file /etc/fstab

 

3) Run the following command to verify everything is working fine

 

You can verify the uid for your user by running

 

Note the option umask=000. This gives execution permission to all files.