TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Linux Commands for Developers

98 点作者 vamsee超过 12 年前

22 条评论

q_revert超过 12 年前
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..<p><pre><code> sort order.* </code></pre> is surely more elegant than<p><pre><code> cat order.* | sort </code></pre> 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..<p>personally, i find that using 'cat output | $command' helps to separate out the 'logic' of what i'm doing, if that makes sense..<p>also, again, purely as a matter of taste<p>i'd prefer<p><pre><code> egrep 'Hardcover|Kindle' </code></pre> over<p><pre><code> grep "\(Kindle\|Hardcover\)" </code></pre> EDIT: (as alexfoo has pointed out, this isn't a proper AND as it worries about the order.. my bad, still useful though :D )<p>and as a sidenote, something i only found recently, but which is quite useful, a logical AND with egrep looks like<p><pre><code> egrep 'Hardcover.*Kindle'</code></pre>
评论 #4447856 未加载
评论 #4448041 未加载
评论 #4448045 未加载
评论 #4447844 未加载
评论 #4448215 未加载
评论 #4448430 未加载
rimantas超过 12 年前
One guideline to keep in mind:<p><pre><code> &#62; If the original title begins with a number or number + gratuitous &#62; adjective, we'd appreciate it if you'd crop it. E.g. translate &#62; "10 Ways To Do X" to "How To Do X," and "14 Amazing Ys" to "Ys." &#62; Exception: when the number is meaningful, e.g. "The 5 Platonic Solids."</code></pre>
angusgr超过 12 年前
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.<p>Say you have two files, one with lines of numbers:<p><pre><code> 1 2 3 </code></pre> ... and one with letters:<p><pre><code> A B C </code></pre> $ <i>paste numbers letters</i><p><pre><code> 1 A 2 B 3 C </code></pre> Want CSV?<p>$ <i>paste -d, numbers letters</i><p><pre><code> 1,A 2,B 3,C </code></pre> Or, with '-s' you can join lines from inside the same file. For instance, you can sum numbers:<p>$ <i>paste -sd+ numbers</i><p><pre><code> 1+2+3 </code></pre> $ <i>paste -sd+ numbers |bc</i><p><pre><code> 6 </code></pre> (Thanks to a Stack Overflow post somewhere for suggesting that one!)<p>Useful example: the total resident memory size of all chromium processes:<p>$ <i>ps --no-headers -o rss -C chromium | paste -sd+ | bc</i><p><pre><code> 793180</code></pre>
评论 #4448125 未加载
djcb超过 12 年前
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.<p>What about some <i>slightly</i> less basic ones that I'd think would be useful for many people.<p><pre><code> # less with syntax highlighting alias less="/usr/share/vim/vimcurrent/macros/less.sh" tailf # tail -f, but better &#38; 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!</code></pre>
评论 #4448582 未加载
评论 #4448610 未加载
评论 #4449259 未加载
评论 #4448580 未加载
评论 #4449764 未加载
pstadler超过 12 年前
You should really try ack (<a href="http://betterthangrep.com" rel="nofollow">http://betterthangrep.com</a>) as a replacement for grep.
davidw超过 12 年前
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.
评论 #4448180 未加载
评论 #4448876 未加载
yesbabyyes超过 12 年前
I was surprised and a little disappointed that `join(1)` didn't join the list!<p>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:<p><pre><code> $ 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</code></pre>
reirob超过 12 年前
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.
评论 #4447933 未加载
评论 #4447931 未加载
klochner超过 12 年前
A better post + thread:<p>"What are some time-saving tips that every Linux user should know?"<p><a href="http://www.quora.com/Linux/What-are-some-time-saving-tips-that-every-Linux-user-should-know" rel="nofollow">http://www.quora.com/Linux/What-are-some-time-saving-tips-th...</a><p><a href="https://news.ycombinator.com/item?id=2361978" rel="nofollow">https://news.ycombinator.com/item?id=2361978</a>
einhverfr超过 12 年前
I came across something in fortune some time ago which you can find at:<p><a href="http://motd.ambians.com/quotes.php/name/linux_songs_poems/toc_id/1-1-31/s/8" rel="nofollow">http://motd.ambians.com/quotes.php/name/linux_songs_poems/to...</a><p>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 <i>before</i> sending through uniq is helpful as well.
评论 #4448100 未加载
talkingquickly超过 12 年前
tail -f filename should definitely make the list, essential for watching what's appended to log files in real time.
评论 #4447825 未加载
评论 #4448138 未加载
dllthomas超过 12 年前
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.
评论 #4452374 未加载
tszming超过 12 年前
A better title:<p>8 Linux Commands Every Developer Should Know [for log analysis]
lloeki超过 12 年前
Unless you want to show before/after context (-A/-B flags), one should grep <i>before</i> sort, not after. Less work to do.
dlsym超过 12 年前
<i>sigh</i> And I tought we were through with collections of trivial shell commands.
dazzawazza超过 12 年前
might be better titled as "8 Unix commands every developer should know".<p>They are all generic unix commands.
评论 #4448658 未加载
评论 #4448446 未加载
protolif超过 12 年前
To continue reading, subscribe? seriously?
asdfprou超过 12 年前
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超过 12 年前
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超过 12 年前
It says sed has basic stream editing capabilities. Basic. This guy should check, sed has very complex and powerful editing capabilities.
yogione超过 12 年前
how do I execute the out put of something like this:<p>grep -i 'pattern' file | awk '{print $5}' | sed 's/^/cmd/g'<p>I end up sending to a file, chmod, then run it at the shell.
评论 #4448009 未加载
评论 #4448001 未加载
评论 #4449344 未加载
zvrba超过 12 年前
comm is another very useful command