Easily remember linux commands

I use an absolute ton of awesome tools my various linux distros. The problem is I tend to forget a lot of the time how to use the tools, so I got a list of frequently used command with and a few examples of how to use them from here. So here’s the file I use. — Create a new tar archive $ tar cvf archive_name.tar dirname/ — Extract from an existing tar archive. $ tar xvf archive_name.tar — Grep for a given string in a file (case in-sensitive search). $ grep -i “the” demo_file — Print the grep line, along with the 3 lines after it. $ grep -A 3 -i “example” demo_text — Grep for a given string in all files recursively $ grep -r “ramesh” * — Grep for a string that starts with $ char and contains what’s in $1 grep — color=auto -B 1 -E ‘^$.b’$1’b’ cmd_examples.txt — Find files using file-name ( case in-sensitve find) $ find -iname “MyCProgram.c” — Execute commands on files found by the find command $ find -iname “MyCProgram.c” -exec md5sum {} ; — Find all empty files in home directory $ find ~ -empty — Converts the DOS file format to Unix file format using sed command. $ sed ’s/.$//’ filename — Print file content in reverse order $ sed -n ‘1!G;h;$p’ thegeekstuff.txt — Add line number for all non-empty-lines in a file $ sed ‘/./=’ thegeekstuff.txt | sed ‘N; s/n/ /’ — Remove duplicate lines using awk $ awk ‘!($0 in array) { array[$0]; print }’ temp — Print all lines from /etc/passwd that has the same uid and gid $ awk -F ‘:’ ‘$3==$4’ passwd.txt — Print only specific field from a file. $ awk ‘{print $2,$5;}’ employee.txt — Diff ignore white space while comparing. $ diff -w name_list.txt name_list_new.txt — Sort a file in ascending order $ sort names.txt — Sort a file in descending order $ sort -r names.txt — Sort passwd file by 3rd field. — Xarg:Copy all images to external hard-drive $ ls *.jpg | xargs -n1 -i cp {} /external-hard-drive/directory — Xarg:Search all jpg images in the system and archive it. $ find / -name *.jpg -type f -print | xargs tar -cvzf images.tar.gz — XargLDownload all the URLs mentioned in the url-list.txt file $ cat url-list.txt | xargs wget –c — LS:Order Files Based on Last Modified Time (In Reverse Order) Using ls -ltr $ ls -ltr — LS:Visual Classification of Files With Special Characters Using ls -F $ ls -F — Gzip:Display compression ratio of the compressed file using gzip -l $ gzip -l *.gz $ bzip2 test.txt $ bzip2 -d test.txt.bz2 — UNZip:View the contents of *.zip file (Without unzipping it): $ unzip -l jasper.zip — Shutdown the system after 10 minutes. $ shutdown -h +10 — Force the filesystem check during reboot. ...

February 19, 2012 · Shane Dowling

Simple ubuntu backup to S3

After browsing the web for ages to find a decent solution to backup my server to amazon s3 I finally came across one and I’m just throwing it up here. So basically all I need it to do was backup my sites(filesystem and mysql databases) and some config for lighttpd. The post I’m basing this off is here. Install automysqlbackup using apt sudo apt-get install automysqlbackup Run automysqlbackup as root(just to give it a test) sudo automysqlbackup ...

January 14, 2012 · Shane Dowling

Simple git web interface

I decided instead of springing for a monthly github payed account I’d install git on a server and use a decent web interface that could be easily installed. So for this little guide I’m rocking ubuntu 10.04 with git and lighttpd already installed. It was a Goldilocks search for ease of installation vs web interfaces usefulness. I tried a number of options, gitweb looked a little rough for my liking and Gitorious and InDeferno were just an utter pain to install. Eventually I came across gitalist and decided I would give it’s incredibly simple to installation go(http://www.gitalist.com/install/). By simply following the directions I managed to get it running without any thought. The problem was it was running on port 3000, I wanted it to hook it into lighttpd and have it run under a subdomain. ...

January 7, 2012 · Shane Dowling

CLI Dash

Due to being flu-ridden for the entire holiday period, I decided to write up a quick tool I’ve been wanting to write for ages. It’s written in Python, so go easy, I’m no Python expert and I’m sick. The tool is essentially a wee-little dashboard for your linux server. It only supports a few system details at present(essentially handy little things python does) but I’ll add more as I get the time, if you’ve any suggestions let me know. ...

December 31, 2011 · Shane Dowling

Good Coding Practice Snippets

After reading through Code Complete I decided to make up mind-maps on each topic in the hope that I would peruse them every so often to brush up on my programming best practice. Recently I decided take a look over them and was dismayed at the amount of knowledge from the book I’d forgotten or that hadn’t become habit. Sure I’d remember a decent chunk of the good stuff and it has certainly improved my programming ability but there was so much I’d missed, even from the tiny mind-maps I’d made. ...

December 24, 2011 · Shane Dowling

Very Simple EC2 Snapshot Management

I’ve been pulling my hair out trying to get a handy ec2 snapshot backup/management working. My google results have ranged from broken libraries to using bash scripts to do one aspect and php scripts to do another, all of the solutions seem to have serious issues with regions. Anyway I’ve coded up a very very stupidly simple bash script that’s based on the ec2-api-tools. Ubuntu based info here. Essentially sudo apt-get install ec2-api-tools should get the required tools. ...

April 1, 2011 · Shane Dowling

Music at work

For anyone bored of trying to decide what to listen to at work I’d recommend indie 103.1. Decent music and as it’s in La it’s 8 hours behind, so no annoying presenters during the work day(If you’re in the timezone of course). Anyway, for anyone rocking mplayer a bash alias for ya. I guess for those who don’t you can just the url…. alias listen_indie1031=“mplayer http://208.80.52.108:80/KDLDFMCMP3” The stream even pulls down artist/trackname. ...

January 13, 2011 · Shane Dowling

Daily WTF — Shopping Carts

Daily WTF-Shopping Carts Really entertaining how the writer “thought” through this solution. Amazing.

January 12, 2011 · Shane Dowling

Software Engineer

Best job of 2011 Apparently.

January 8, 2011 · Shane Dowling

Intel Insider — Now hardware can screw you with copy protection.

Intel Insider-Now hardware can screw you with copy protection. Another product I have to remember never to buy. Companies should be punished for this behaviour.

January 6, 2011 · Shane Dowling