CLI #Ref

The purpose of this page is to serve as quick reference for an assortment of console commands that I have found to be useful, even if some are rarely used.

Last Updated: Oct. 11, 2014

Convert an Apple DMG to the more usage IMG format (Windows/Linux)

dmg2img source.dmg destination.img

Suppress overwrite prompt when copying (Linux) (note the backslash prefix)

\cp -r source/* ./

Mount a Virtualbox Shared folder:

mount -t vboxsf share_name /mount/point

Append a line to a file, without using redirection

echo "line of text to add" | tee -a /path/to/file

Get the number and count of unique IPs in a web server log file

awk '{!a[$1]++}END{for(i in a) if ( a[i] >10 ) print a[i],i }' access.log

Get the total size of files (in the current folder) modified in the last day

find . -mtime -1 -ls | awk '{total += $7} END {print total}'

Perform an inline replacement of text in all matching files

find . -type f -name "*.ext" -print | xargs sed -i 's/match/replacement/g'
find . -type f -name "*.ext" -exec sed -i 's/match/replacement/g' {} \;

Access a VirtualHost by IP:

curl --header "Host:"

Purge a Varnish (3.x) cache entry from localhost (note: you can omit the --head parameter and use the full URL instead of passing the Host header; and it does work without --http1.0).

curl -X PURGE --http1.0 --head --header "Host:"
curl --compressed -X PURGE --http1.0 --head --header "Host:"

Optimize all MySQL tables:

mysqlcheck -o -u root -p --all-databases

Find if kernel is compiled with a specific option:

grep OPTION_NAME /boot/config-$(uname -r)

Testing gzip with cURL:

curl --compressed --head

Run a node.js – express app in production mode with forever:

NODE_ENV=production forever start app.js

Test if user has read permissions (also works for other file permissions, and file properties):

sudo -u USER test -r /path/to/file && echo 'yes' || echo 'no'

Test if a file is newer than another file:

test FILE1 -nt FILE2 && echo 'yes' || echo 'no'

Clear the NPM cache (fixes most npm install problems):

npm cache clear

Determine the device a path is mounted on:

mountpoint -d /path/

Go to the previous directory you were in:

cd -

Logout (linux shell):


Install Redis 2.8 on Amazon Linux (from Remi):

yum install
yum --enablerepo=remi install redis

Resend mails from local mbox:

cat /var/spool/mail/test |
formail -I "To:" \
        -s /usr/sbin/sendmail -t -f

Leave a Reply

Your email address will not be published. Required fields are marked *