Live data from Hacker News

Top Unix Command Line Utilities

blog.coldflake.com

51–60 of 65 posts

Re: Top Unix Command Line Utilities

#53

Does anybody know of great guides to master the majority of the useful CLI tools available on Unix and Linux? For me the challenge is that I don't even know I have some of these fantastic solutions readily available. I'd really benefit of knowing they're there in the first place instead of hacking a homebrew solution every time. Learn Linux the Hard Way talks about them quite a bit, is that the go to guide in 2012 or…

http://www.commandlinefu.com/commands/browse is a good resource to at least browse through for inspiration.

I also learned a lot from "The Linux Cookbook" (Second Edition) by Michael Stutz (this might be the first edition online: http://dsl.org/cookbook/cookbook_toc.html).

Re: Top Unix Command Line Utilities

#54
post #38
post #36

Earlier quoted context omitted.

The for loop works fine. Performing word splitting/wildcard expansion/etc on a variable will, well, split it into words/expand wildcards/etc, whether it was introduced by a for loop or not.

I am not sure I understand what you mean. Word-splitting is performed by the "for x in y" construct, using the IFS variable, so by default if you have a file called "foo bar.mp4" the command line from the article: for i in *.mp4; do ffmpeg -i "$i" "${i%.mp4}.mp3"; done will result in executing: ffmpeg -i foo foo.mp3 ffmpeg -i bar.mp4 bar.mp3 Which is obviously not what was meant. So it's a good habit to learn to loop…

Maybe you are confusing this with what happens when you do

    for i in `find -name '*.mp4'`; do # ...
or similar. In that case, the output of `find` is indeed split first, and `for` sees "foo", "bar.mp4", and so on.

Re: Top Unix Command Line Utilities

#55
post #52
post #31

Combine sort and uniq is useless since sort has already -u flag.

sort | uniq -c | sort -n is something I use all the time to get sorted frequency tables.

And, by the way, the two commands are something that could be done in O(n), rather than O(n*log(n)) - but this little procedure is so damn easy to write, that on relatively thin inputs that are less than 20m lines long, I usually just do this.

Re: Top Unix Command Line Utilities

#56
post #48

The second #6 example, the one with xargs, is wrong. Xargs(1) doesn't necessarily create a single du process, it might create several.

I was wondering about that, but is it really wrong? From what I found in the "BSD General Commands Manual":

Any arguments specified on the command line are given to utility upon each invocation, followed by some number of the arguments read from the standard input of xargs. The utility is repeatedly executed until standard input is exhausted.

and

-P maxprocs Parallel mode: run at most maxprocs invocations of utility at once.

The way I interpret that is that you could run xargs in parallel mode, but by default the "utility is repeatedly executed" in the same process.

Re: Top Unix Command Line Utilities

#57
post #31

Combine sort and uniq is useless since sort has already -u flag.

Except for those cases where you want counts, only unique/only duplicate, skipping fields, doing case-insensitive duplicate detection, or only comparing a chunk of the line - all but the last two I've used and now that I've found those in the man page (GNU uniq) I can replace some silly shell hacks that I've used over the years. It's like saying that tail is pointless unless you're doing tail -f... you're missing the actual useful functionality due to presuming the tool only does what you've done with it in the past.

Re: Top Unix Command Line Utilities

#58
post #54
post #38

Earlier quoted context omitted.

I am not sure I understand what you mean. Word-splitting is performed by the "for x in y" construct, using the IFS variable, so by default if you have a file called "foo bar.mp4" the command line from the article: for i in *.mp4; do ffmpeg -i "$i" "${i%.mp4}.mp3"; done will result in executing: ffmpeg -i foo foo.mp3 ffmpeg -i bar.mp4 bar.mp3 Which is obviously not what was meant. So it's a good habit to learn to loop…

Maybe you are confusing this with what happens when you do for i in `find -name '*.mp4'`; do # ... or similar. In that case, the output of `find` is indeed split first, and `for` sees "foo", "bar.mp4", and so on.

Ah yes, you are right, thanks!

Re: Top Unix Command Line Utilities

#59
post #3

These obviously aren't related to 2012 at all. Some issues: - don't forget that /dev/random blocks - It's easier to use dd_rescue to track progress than to signal dd - Using dd to zero out a hard drive repeatedly doesn't increase security[1]. Using ATA secure erase does[2] - an alternative for summing file sizes is du -ch **/*.png [1] http://en.wikipedia.org/wiki/Data_erasure#Number_of_overwrit... [2] https://ata.wik…

> It's easier to use dd_rescue to track progress than to signal dd

Why? I just use: watch pkill -USR1 dd

Re: Top Unix Command Line Utilities

#60
post #44
post #19

Earlier quoted context omitted.

My .bash_history weights 1.7Mo (almost 100k lines). I set a very high HISTSIZE since I don't see any reason to lose this data.

One reason might be that bash reads this whole file into memory on interactive startup and rewrites it completely when shutting down.

I second this, I think it is good practice to rotate the history file manually when it reaches several MBs. (Using zsh, the main symptoms of a large history file is sluggishness when using ^R and a lag of a few tenths of a second when closing a terminal.)
Post reply on HN