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
[ 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).
Minor nitpick from the man page: "egrep is the same as grep -E. fgrep is the same as grep -F. Direct invocation as either egrep or fgrep is deprecated, but is provided to allow historical applications that rely on them to run unmodified."
> 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."
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:
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!
I ask the programmers on my team, some of whom are quite junior and unexperienced, to send weekly status reports with an overview of what they did in the previous week, what they expect to do in the next, and other. Other is usually made up of areas of concern and interesting things that have made it onto one's radar. (You can put basically whatever you like in the other section. I'm still hoping somebody will send a joke.)
Since I wouldn't ever ask them to do something I wouldn't do myself, I send these reports too. This link will go in my miscellany section this week. I think it'll be useful, and I wouldn't have ever found it or even considered including something like it had it not shown up on HN.
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.
Absolutely, especially for those who do network programming under Unix/Linux. Combined with lsof, it can help a lot in troubleshooting issues such as deadlocks.
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
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.
I disagree. They may not be obviously related to coding, though they'll probably end up being useful at some point anyway... But they're definitely useful for working with logs, working with datasets, working with config files, and a host of other development-related tasks. Just yesterday I was on a Windows machine and dearly felt the loss of sed and uniq. I have a task lined up for today to either find Windows alternatives or install msys.
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.
less +F filename does the same thing, but loses the following when the logfile gets rotated. Does the same thing happen to tail -f? (edit: alexfoo answered that tail -F tracks the file properly)
one benefit to less +F is that you can cancel the following and read normally in less.
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.
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.
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.
q_revert|13 years ago
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
over 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
alexfoo|13 years ago
> 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:-
(Of course, someone will now show how this can be done in even fewer characters).ralph|13 years ago
ciupicri|13 years ago
alexfoo|13 years ago
However, things change if you start adding certain options to sort:-
and are definitely not the same thing (for most input files at least).krzyk|13 years ago
unknown|13 years ago
[deleted]
rimantas|13 years ago
angusgr|13 years ago
Say you have two files, one with lines of numbers:
... and one with letters: $ paste numbers letters Want CSV?$ paste -d, numbers letters
Or, with '-s' you can join lines from inside the same file. For instance, you can sum numbers:$ paste -sd+ numbers
$ paste -sd+ numbers |bc (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
yesbabyyes|13 years ago
djcb|13 years ago
What about some slightly less basic ones that I'd think would be useful for many people.
maw|13 years ago
Since I wouldn't ever ask them to do something I wouldn't do myself, I send these reports too. This link will go in my miscellany section this week. I think it'll be useful, and I wouldn't have ever found it or even considered including something like it had it not shown up on HN.
thomaslangston|13 years ago
masklinn|13 years ago
That's better about tailf, and why would I use it instead of the (far superior to tail) less +F?
stretchwithme|13 years ago
Evbn|13 years ago
pstadler|13 years ago
davidw|13 years ago
cygwin98|13 years ago
pooriaazimi|13 years ago
yesbabyyes|13 years ago
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:
reirob|13 years ago
jrajav|13 years ago
antback|13 years ago
klochner|13 years ago
"What are some time-saving tips that every Linux user should know?"
http://www.quora.com/Linux/What-are-some-time-saving-tips-th...
https://news.ycombinator.com/item?id=2361978
einhverfr|13 years ago
http://motd.ambians.com/quotes.php/name/linux_songs_poems/to...
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|13 years ago
talkingquickly|13 years ago
alexfoo|13 years ago
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).
vacri|13 years ago
one benefit to less +F is that you can cancel the following and read normally in less.
dllthomas|13 years ago
billsix|13 years ago
tszming|13 years ago
8 Linux Commands Every Developer Should Know [for log analysis]
lloeki|13 years ago
dlsym|13 years ago
dazzawazza|13 years ago
They are all generic unix commands.
ams6110|13 years ago
aw3c2|13 years ago
protolif|13 years ago
asdfprou|13 years ago
unknown|13 years ago
[deleted]
corford|13 years ago
gbog|13 years ago
yogione|13 years ago
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|13 years ago
Or surround in backticks
I prefer $() as they nest better.Or have I misunderstood your question?
badboy|13 years ago
Domenic_S|13 years ago
grep -i 'pattern' file | awk '{print $5}' | xargs cmd
zvrba|13 years ago