11/21/2016 - 9:45 AM



Add folder to PATH:
sudo nano /etc/paths
#These commands are useful in some WTF moments

# Find apache config files
apachectl -V
# convert newlines to linux format (in file web/login.php)
# Explanation: -p: assume a "while input" loop, -i: edit input file in place, -e: execute following command
perl -pi -e 's/\r\n/\n/g' web/login.php
# sometimes this works 
perl -pi -e 's/\r/\n/g' web/login.php
# obvioulsy we could do this instead - in theory (not tested)
less web/login.php | perl -p -e 's/\r/\n/g' > web/login.php

# echo with newline (note -e)
echo -e "Blah Blah\n"

# sync data and spindown disk sdb
sudo hdparm -y /dev/sdb

# create ssh tunnel and use it for chrome
ssh -D 8080 -N 
google-chrome --proxy-server=socks5:// --user-data-dir=/tmp

# Create a remote/reverse tunnel to the local machine
# Note: GatewayPorts must be set to "yes" in /etc/ssh/sshd_config
ssh -R 8080:localhost:80

# find processes occupying TCP ports:
sudo netstat -lntpu
# or ss instead of netstat

# DEPRECATED: List packages and the size they each take up (Debian-based)
dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n
# Actually the command above only lists the "installed-size" which is actually an estimation of the disk space needed, and is extracted from package meta-information. Hence deprecation.

# Detach process from terminal
# If it's an SSH session then I can close it without killing the process after doing that
# For example, process rclone. Order of steps does not matter.
# - I believe this step is optional: redirect stdout and stderr to a file (~/rclone.log)
# requires
reredirect -m ~/rclone.log <PID>
# - Send to bg and detach it
disown <"rclone"|PID>
# run jobs to check that the job is gone
# - We can open another tty and reattach it there (needs reptyr)
reptyr <PID>
# =========  Settings

# Use nano as editor (because I'm no masochist)
git config --global core.editor "nano"

# =========  Commands

#<remoteName> is usually "origin"

#Check out single file/dir (relative/path) from different branch (feature_1). Head remains on current branch.
git checkout <branchName> -- relative/path

#Combine above with init, (shallow) fetch to only "clone" a single directory
git init
git remote add origin <repo-URL>
git fetch --depth 1 origin <branch>
git checkout origin/<branch> -- relative/path

#Remove last 3 commits from current branch. Use in conjunction with other commands for useful operations. Eg: "moving" last 3 commits to another branch.
git reset --hard HEAD~3

#Add remote repository
git remote add <remoteName> <remoteUrl>

#Delete branch locally and remotely (replace -d by -D for force delete)
git branch -d <branch_name>
git push <remote_name> --delete <branch_name>

#Create local branch
git branch <branchName>

#Push newly created local branch to remote repo (creating it there, if needed)
git push -u <remoteName> <branchName>

#Create local branch that tracks remote branch (if we are already in the branch, then the first <branchName> argument can be omitted)
git branch --track <branchName> <remoteName>/<branchName>

#Delete remote branch
git push <remoteName> :<branchName>

#Rename branch (<oldBranchName> can be omitted for renaming current branch)
git branch -m <oldBranchName> <newBranchName>

#Git has not "remote rename" operation, so we have to delete and re-push the branch like that:
git push <remoteName> :<oldBranchName> <newBranchName>

#"Branch in the past"
#You can create the branch via hash,
git branch branchname <sha1-of-commit>
#or by using a symbolic ref.
git branch branchname HEAD~3

#Line ending settings. (autocrlf fase = ignore line ending)
git config --system core.autocrlf false
git config --system core.eol lf

#ignore file mode changes

#list settings (check that they are to your liking)
git config --global -l
git config --system -l
git config --local -l

#some things I find myself wanting to do:
 - commit to different branch
 - commit to two branches at once
 - Merge all but one commit that is somewhere in the middle. Would push the commit to the top. That one might be complicated.