2.11.11

SHELL!

Okay so the guy at the cigar shop introduced me to the importance of http://teddziuba.com/2010/10/taco-bell-programming.html (TACO BELL programming)...

I've been having alot of issues with hadoop and linux lately... largely because I don't understand the taco bell nature of hadoop : its basically a whole bunch of shell scripts, privileges, and files. Its a great example of why the taco bell programming is so important.

So in honor of mr ziuba, I thought I might spend a couple of free hours in the lab today working on find, grep, and netstat. I'm structuring this in the form of "use linux on an as needed basis" rather than in an RTFM style... even though I think RTFM, for those with the patience for it, is always better.

So here are , in my opinions, the 10 most useful commands that I find myself running ALL THE TIME in the shell. I encourage others to add their own here as well .

I will be keeping this open for my own reference for a while.

1) I have 100 files , each of which has 10 sequences in them (these can be Amino Acid sequences, or simply names of people, or even phone numbers...) and want to find all in the fields that have 2 Q's in a row.

surprise : grep natively supports finding FILES


grep -m 1 -rl "QQ" *

(note the -rl , a less known feature of grep) .

2) Grep choked ! Can I tell it to only work on files of type ".java" ?

find . -name "*.java" -exec grep "Colbert" '{}' \.
OR
grep -rl "Colbert" --include=*java ./

3) I know that the guy who wrote the word "Colbert" in his code had an important for loop above or below that line. How can I get the "vicinity" of lines around colbert ? Use greps 'before' and 'after' modifiers....

grep -B 2 -A 2 "Colbert" *

4) What is the most recently written file by this out of control program I just started ?

find . -type f | xargs ls -ltrhg

5) How can I get the IP address out of my ifconfig ?

ifconfig | grep 'eth0'

6) I just installed (mysql/hadoop/apache/jetty/...) and its not working ! How can I see which ports are actively being listened (for example- it should be listening on 8080) ?

netstat -nap | grep '8080'

7) What is the name of my machine on this network ?

sudo /bin/hostname

8) I want to REMOVE all the bad lines from my file, these lines have a 'z' in them.

grep -v 'z' input.txt > cleanOutput.txt

9) How can I find all the files that contain EITHER my name, or COLBERT's name in them ?

grep -r 'Colbert\|Jay\' ./

10) I had to run this really complex command using sed in it a few minutes ago, but i can't find it in my history.... Where is it ?

history | grep 'sed'

2 comments:

  1. There are many such secrets, none of which are hidden. http://en.wikipedia.org/wiki/Unix_philosophy

    and the Koans - http://catb.org/~esr/writings/unix-koans/index.html

    As for command line tips - there has been a few posts in the last few days on them, such as a link to http://www.commandlinefu.com/commands/browse/sort-by-votes

    ReplyDelete
  2. Thats right . thanks al. !

    ReplyDelete