Skip to content

Instantly share code, notes, and snippets.

@nabucosound
Created July 20, 2013 00:44
Show Gist options
  • Save nabucosound/6043329 to your computer and use it in GitHub Desktop.
Save nabucosound/6043329 to your computer and use it in GitHub Desktop.
Lazy mind, always forgetting shell commands to perform basic stuff.

Command Line Cheatsheet

Filesystem

Delete recursively:

find . -name "*.pyc" | xargs rm -f
rm -rf `find . -type d -name .svn`
find . -iname .DS_Store -print0 | xargs -0 -n 1 rm -f

Batch rename:

for file in *.txt  ; do mv $file `echo $file | sed 's/\(.*\.\)txt/\1rst/'` ; done

Find largest files and folders:

sudo du -a /srv/www/ | sort -n -r | head -n 10
find /var -type f -ls | sort -k 7 -r -n | head -10

Delete files older than:

find . -ctime +30 -exec rm -rf {} \;

reStructuredText

Using linked css and header level to H2:

rst2html.py --link-stylesheet --initial-header-level=2 src.rst > dst.html

Imagemagick

Convert png to ico (favicons):

convert nb_logo.png -resize 16x16 nb_logo.ico

Get information (dimensions, size...):

identify image.jpg

Resize only width:

convert dipticnuvolic1.png -resize 700x diptic1.png

Force resize:

convert time_out_gran.jpeg -resize 320x214! time_out_mobile_portada.jpeg

Crop image:

convert ~/Desktop/timeout.png -crop 138x117+0+0 nuvolic/website/static/img/timeout.png

Networking

Get my public IP address:

curl http://whatismyip.org
curl ifconfig.me

List of nameservers for TLD:

dig +short NS nomadblue.com

Backup gmail emails with label 'X' with getmail:

# First Place getmail.gmail in ~/.getmail/
cd /Users/nabuco/gmail-archive/
getmail -r /Users/nabuco/.getmail/getmail.gmail

lftp

FTP Upload a single file in one command line:

lftp -c "open ftp://salgotweb:l8zfsnsy@ftp.salgot.com/; cd es/; put caca; quit;"

Mirror only HTML files in directory recursively:

mirror -I *.html .

Multiple put of HTMl files from local dir to remote dir:

mput es/*.html -d es/

ssh

Tell the fingerprint of an encryption key:

ssh-keygen -lf <keyfile>

ack

Open files matching pattern in Vim:

vim `ack -l PATTERN`

Search only filenames matching pattern:

find . -name filename.txt | xargs ack PATTERN -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment