# Latest git commit hash
git log --pretty=format:'%h' -n1

# Search for a gem on rubygem servers
gem search -r eventmachine

# List files and directories and sort on their sizes
du -hs * | sort -h

# Show how much space the current directory uses
du -hs

# Show overall disc usage stats
df -h

# Grep with extended regular expression
# http://www.cyberciti.biz/faq/grep-regular-expressions/
grep -E "slot=(8,9,10)"

# Return only the matched content instead of the whole line - helpful for minified javascript
grep -ioR '\./assets.*swf?' ./
# -l - return only the filename
# -c - see how much it apeared in each searched file

# Grep certain file extensions
grep -nir --include "*.js" --include "*.html" "searched term" ./

# Copy directory and replace links with real files
cp -Lr some-dir some-new-dir

# rsync - better then copy
# Copy to the 10.0.50.50 server with specified credentials
rsync -av -e "ssh -i /home/user/.ssh/servers-keys" /directory/which/should/be/copied 10.0.50.50:/directory/where/to/copy

# Other Example. Resource: http://articles.slicehost.com/2007/10/9/backing-up-your-files-with-rsync
rsync -e 'ssh -p 30000' -avl --delete --stats --progress demo@123.45.67.890:/home/demo /backup/

# Repeat command (ls -al) every 5 seconds
watch -n 5 'ls -al'

# curl send on OPTIONS request
curl -I -v -H 'Host: www.example.com' -X OPTIONS http://www.example.com

# View the command of the process matched with the id: PROCESS_ID
ls -l /proc/{PROCESS_ID}/exe 

# Display all files except png's, gif's and jpg's
# -f will show full paths
tree -f -I '*gif|*jpg|*png'

# Kill a process
kill `ps -eo pid,args | awk '$3 == "myservice.java" { print $1 }'`

# See which process is using the current directory
fuser -v ./

# List process details
ps -eo user,pid,%cpu,%mem,stat,start,time,cmd

# list process relations
ps auxw --forest

# Sort by second column where the separator is a ","
sort -t "," -k 2 input-file.data

# Create a basic auth (htpasswd) file
htpasswd -cdb file-name 'user-name' 'your-password' # File name is usually "htpasswd"
# !!important!! -c will override the file if it exists. If You already have a file remove the -c option

# monitor the system calls used by a program
strace git ls-remote git@localhost:repo.git

# -p flag to attach to a running process
strace -p 1725 -o output.txt; tail -f output.txt

# xargs example
find . -name *.scss | xargs -I style_file echo "->" style_file

# Strace save output to file
strace -p 2707 -o /tmp/debug.log -f

# View process memory details - memory map of a process
pmap -x <PID>