Useful CLI Commands


Display just the HTTP response using curl (ref)

$ curl -IL

Find the cause of last shutdown/reboot on Linux (ref)

$ last reboot
$ last -x | grep shutdown

Restart Frozen dock in Max OSX (ref)

$ killall Dock

Inspect memory hardware in Linux

$ sudo lshw -C memory

Search and replace text in multipe files from command line (Linux and Mac OS)

$ find . -type f -name "<FILE_FILTER>" -exec sed -i 's/<SEARCH>/<REPLACE>/g' {} \;
# e.g
$ find . -type f -name "*.txt" -exec sed -i 's/hello/bye/g' {} \;

Copy SSH public key to a remote server when ssh-copy-id is not present

$ cat ~/.ssh/ | ssh [email protected] "mkdir -p ~/.ssh; $ cat >> ~/.ssh/authorized_keys"

Add Music Files to iTunes from Command Line (Mac) (ref)

$ open -a iTunes -g song.mp3

Fetch and pipe the content of a webpage to stdout

$ wget -q http://target.url -O -

Create a rendered visual diff of a LaTeX project

# Requirements
# 1. git is used for version control
# 2. latexdiff:
# 3. git-latexdiff:

$ git latexdiff --bibtex --main root.tex [--latexmk] OLD_HASH [NEW_HASH]

Using ssh-agent to avoid typing in SSH passwords multiple times

$ eval `ssh-agent`
$ ssh-add [/path/to/id_rsa]