
Linux Commands for Developers - vamsee
http://blog.jayfields.com/2012/08/8-linux-commands-every-developer-should.html
======
q_revert
I was expecting to see the first comment in here complaining about his use of
'cat', as in all of the examples his second argument could've easily taken a
filename argument..

    
    
      sort order.*
    

is surely more elegant than

    
    
      cat order.* | sort
    

which is fair enough, however, as it happens, i generally do end up using
'cat' in the way he's used it.. for such small jobs nobody can be genuinely
worried about the overhead, and it comes down to a matter of taste..

personally, i find that using 'cat output | $command' helps to separate out
the 'logic' of what i'm doing, if that makes sense..

also, again, purely as a matter of taste

i'd prefer

    
    
      egrep 'Hardcover|Kindle'
    

over

    
    
      grep "\(Kindle\|Hardcover\)"
    

EDIT: (as alexfoo has pointed out, this isn't a proper AND as it worries about
the order.. my bad, still useful though :D )

and as a sidenote, something i only found recently, but which is quite useful,
a logical AND with egrep looks like

    
    
      egrep 'Hardcover.*Kindle'

~~~
alexfoo
[ EDIT - Two replies as original post had been edited by the time I posted the
first. ]

> and as a sidenote, something i only found recently, but which is quite
> useful, a logical AND with egrep looks like > > egrep 'Hardcover. _Kindle'

That's not a true logical AND since it won't pick up an entry with the text
"Kindle Hardcover". Only entries with the word "Hardcover" eventually followed
by "Kindle". To cover both cases you'd need:-

    
    
      egrep 'Hardcover.*Kindle|Kindle.*Hardcover'
    

(Of course, someone will now show how this can be done in even fewer
characters).

~~~
illicium
How about:

    
    
        grep Hardcover | grep Kindle

~~~
alexfoo
Yup, but I had meant in one command though, i.e.

    
    
      sed -n '/Kindle/{/Hardcover/p}'

------
rimantas
One guideline to keep in mind:

    
    
      > If the original title begins with a number or number + gratuitous
      > adjective, we'd appreciate it if you'd crop it. E.g. translate
      > "10 Ways To Do X" to "How To Do X," and "14 Amazing Ys" to "Ys."
      > Exception: when the number is meaningful, e.g. "The 5 Platonic Solids."

------
angusgr
One I learned for the first time the other day is 'paste'. Good for people
like me who never fully grokked awk, it joins lines from separate files into a
single file.

Say you have two files, one with lines of numbers:

    
    
      1
      2
      3
    

... and one with letters:

    
    
      A
      B
      C
    

$ _paste numbers letters_

    
    
      1	A
      2	B
      3	C
    

Want CSV?

$ _paste -d, numbers letters_

    
    
      1,A
      2,B
      3,C
    

Or, with '-s' you can join lines from inside the same file. For instance, you
can sum numbers:

$ _paste -sd+ numbers_

    
    
      1+2+3
    

$ _paste -sd+ numbers |bc_

    
    
      6
    

(Thanks to a Stack Overflow post somewhere for suggesting that one!)

Useful example: the total resident memory size of all chromium processes:

$ _ps --no-headers -o rss -C chromium | paste -sd+ | bc_

    
    
      793180

~~~
yesbabyyes
`paste` is also very useful together with stdin redirection and subshells.
E.g.:

    
    
        paste <(ping 8.8.8.8) <(while true; do iwconfig wlan0 | grep "Bit Rate"; sleep 1; done)

~~~
ralph
They could drift. Better to do a one-ping ping and run iwconfig once in a
loop.

------
djcb
Hmmm, is this HN worthy? These commands are so basic that I don't expect any
HN-reader using Unix systems not to know those.

What about some _slightly_ less basic ones that I'd think would be useful for
many people.

    
    
      # less with syntax highlighting
      alias less="/usr/share/vim/vimcurrent/macros/less.sh"
      
      tailf # tail -f, but better & shorter
    
      mtr # check your connection (ie., traceroute with more info)
    
      htop # nice a colorful process listing (better than top)
    
      locate # search files by name -- that late-night disk thrashing is useful after all!

~~~
Evbn
If you are going to use vim, why bit he pretending it is less? Just use vim.

~~~
Nick_C
Because the vim macro changes all settings so it behaves just like less,
including making the file effectively read-only, and without the overhead of
loading all the plugins.

------
pstadler
You should really try ack (<http://betterthangrep.com>) as a replacement for
grep.

------
davidw
I think it's obligatory that someone writes 'strace' in threads about articles
like this, so here goes. strace is fantastic for debugging certain categories
of problem.

~~~
pooriaazimi
I'm yet to find a decent introduction to strace (or dtrace). I'd appreciate if
someone could point me to one...

~~~
jswanson
Here's a post outlining how strace can be used to solve problems:

[https://blogs.oracle.com/ksplice/entry/strace_the_sysadmin_s...](https://blogs.oracle.com/ksplice/entry/strace_the_sysadmin_s_microscope)

More from a sysadmin POV than a dev, but you'd probably still find it useful.

------
yesbabyyes
I was surprised and a little disappointed that `join(1)` didn't join the list!

With the files in the example (order.out.log, order.in.log), to join every
record on it's id, you would do something like:

    
    
      $ join -j 2 order.out.log order.in.log
    
      111, 8:22:19 1, Patterns of Enterprise Architecture, Kindle edition, 39.99 8:22:20 Order Complete
      112, 8:23:45 1, Joy of Clojure, Hardcover, 29.99 8:23:50 Order sent to fulfillment
      113, 8:24:19 -1, Patterns of Enterprise Architecture, Kindle edition, 39.99 8:24:20 Refund sent to processing

------
reirob
I thought to learn something useful for programing (debugging, program runtime
analysis, etc.). But instead the article is just about the generic commands
cat, sort, grep, cut, sed, uniq, find and less. It is not really development
related.

~~~
antback
Totally agree! Wasted time. Everybody know these commands.

~~~
Domenic_S
You and I do, but surely you know a web dev or two that struggles to read log
files meaningfully or doesn't know how to grep their html source for
something?

Send the article along, it's not always about you...

------
klochner
A better post + thread:

"What are some time-saving tips that every Linux user should know?"

[http://www.quora.com/Linux/What-are-some-time-saving-tips-
th...](http://www.quora.com/Linux/What-are-some-time-saving-tips-that-every-
Linux-user-should-know)

<https://news.ycombinator.com/item?id=2361978>

------
einhverfr
I came across something in fortune some time ago which you can find at:

[http://motd.ambians.com/quotes.php/name/linux_songs_poems/to...](http://motd.ambians.com/quotes.php/name/linux_songs_poems/toc_id/1-1-31/s/8)

I have found it to be surprisingly useful. Nobody uses all the commands but
remembering that something like zcat exists can be extremely useful. Also
remembering to pipe through sort _before_ sending through uniq is helpful as
well.

~~~
gav
In most cases you can replace "sort | uniq" with "sort -u".

------
talkingquickly
tail -f filename should definitely make the list, essential for watching
what's appended to log files in real time.

~~~
alexfoo
I prefer:-

tail -F filename

as most of the logfiles I need to watch tend to wrap at some point and 'tail
-f' doesn't check for inode changes.

(-F is a non-standard option, it's there on GNU's [EDIT] tail binary and OS-X
but not Solaris for example).

~~~
talkingquickly
Thanks, very useful - didn't know that!

------
dllthomas
Those are, indeed, 8 commands every developer should know. Calling them "Linux
Commands" is a little weird - I don't think there's anything there not
specified in POSIX, and I think they all appear on OS X and other unix
systems.

~~~
billsix
Agreed. Especially since he used 'find /Users -name "order*"', which means it
was probably written on OS X.

------
tszming
A better title:

8 Linux Commands Every Developer Should Know [for log analysis]

------
lloeki
Unless you want to show before/after context (-A/-B flags), one should grep
_before_ sort, not after. Less work to do.

------
dlsym
_sigh_ And I tought we were through with collections of trivial shell
commands.

------
dazzawazza
might be better titled as "8 Unix commands every developer should know".

They are all generic unix commands.

~~~
ams6110
And to be really pedantic, they aren't "unix commands" they are utility
programs.

------
protolif
To continue reading, subscribe? seriously?

------
asdfprou
Regardless of the actual content, I applaud the "storytelling" way of
presenting content. With a flow of examples that tie into each other the
reader is given background context and can say to him/herself "I've had that
problem before!", as I found myself doing.

------
corford
lsof -i always gets left out of these lists. It's really handy for quickly
seeing what daemons are running (under which user) and on what interfaces
they're bound to.

------
gbog
It says sed has basic stream editing capabilities. Basic. This guy should
check, sed has very complex and powerful editing capabilities.

------
yogione
how do I execute the out put of something like this:

grep -i 'pattern' file | awk '{print $5}' | sed 's/^/cmd/g'

I end up sending to a file, chmod, then run it at the shell.

~~~
michaelcampbell
In bash...

    
    
        $(grep -i 'pattern' file | awk '{print $5}' | sed 's/^/cmd/g')
    

?

Or surround in backticks

    
    
        `command which outputs text you want to run as a command`
    

I prefer $() as they nest better.

Or have I misunderstood your question?

~~~
yogione
That's it $() works. thanks.

------
zvrba
comm is another very useful command

