Below is a compilation of command line tips that have helped me over the years. As this is a cheat sheet, it will be updated over time to include new cheats and to maintain existing ones.

Git and GitHub


Add GitHub as known host

ssh-keyscan -t rsa github.com > ~/.ssh/known_hosts

GitHub Workflow

If working alone:

  • create new branch for feature you’re working on: git checkout -b branchname
  • commit changes from your branch
  • git checkout master and then git pull
  • git merge branch
  • git push
  • git push origin --delete branch

If collaborating:

  • create new branch for feature you’re working on
  • commit changes from your branch
  • git push
  • on GitHub
    • create pull request
      • have conversations
      • merge branch with master
      • delete branch
  • git up
  • git fetch -p (deletes remote-tracking branches which no longer exist on the remote) or git branch -d branch_name

Commit current changes to a different branch

  • git stash
  • git checkout other-branch
  • git stash pop

Change commit description that’s already been pushed to GitHub

  • GitHub guide
  • git commit -amend
  • fix message
  • git push -f origin branch-name

Untrack a new file

git rm --cached <file-name>

Remove untracked files from working tree

git clean -f -n
git clean -f

Linux


Exclude all “permission denied” messages from find

find . ! -readable -prune

Pressing enter produces ^M instead of a newline

stty sane

Restarting linux without doing an automatic fsck

  1. shutdown -rf now
  2. if there’s a read-only file system, you can remount it - BUT usually a system is read-only if it’s about to be unreadable altogether, so be careful
  3. mount -o remount /dev/sda1

CentOS enable access to web server

iptables -I INPUT -i eth0 -p tcp -m tcp --dport 80 -j ACCEPT
# to make the changes permanent
-A INPUT -i eth0 -p tcp -m tcp --dport 80 -j ACCEPT
service httpd restart

Set gdm3 as default display

sudo dpkg-reconfigure gdm

Boot into terminal

ctrl + alt + F1

Mac OS


Create bootable flash drive

  1. open terminal
  2. run diskutil list
  3. identify which disk corresponds to your USB stick
  4. diskutil unmountDisk /dev/rdisk2
  5. sudo dd if=/path/to/ubuntu.iso of=/dev/rdisk2 bs=1m

Checksums on Mac

  • shasum -a 256 /tmp/1.iso
  • md5 /tmp/1.iso

Fix “function definition file not found” error on Mac OS

rm ~/.zcomp*

Windows


Kill process in Windows

  1. netstat -ano
  2. netstat -ano | find [port number]
  3. taskkill /F /PID [PID number]

Invert Mouse Scroll Wheel in Windows

Get-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Enum\HID\*\*\Device` Parameters FlipFlopWheel -EA 0 | ForEach-Object { Set-ItemProperty $_.PSPath FlipFlopWheel 1 }`

Misc


MkDocs

  1. mkdocs new my-project
  2. mkdocs build -clean
  3. mkdocs serve
  4. mkdocs gh-deploy -clean

Make file executable

chmod +x script.sh

Fixing the block size on a USB drive

sudo dd if=/dev/zero of=/dev/<id_of_your_device> bs=2048 oflag=direct

Fix vim_files: function definition file not found

exec zsh

Copy last command to clipboard

echo !! | clipboard