Live data from Hacker News

Unix Commands I Wish I’d Discovered Years Earlier

spin.atomicobject.com

231–240 of 259 posts

Re: Unix Commands I Wish I’d Discovered Years Earlier

#231

Earlier quoted context omitted.

You should do a screencast of such infinitely useful classics as tac , tsort , and sl . (Actually, I have found use for those first two on occasion. ;)

Thanks for the suggestion! Actually, I initially wanted to do one on more advanced commands, but I thought I'd better lay a foundation first. I also want to cover using pipe (|) to chain these commands together. I'll make sure to include these.

Don't miss xargs.

Re: Unix Commands I Wish I’d Discovered Years Earlier

#232
post #226

When do you need man ascii and xxd? I'm a front-end developer so I have no clue about these low-level things but I'm interested and would like to learn.

This is a very silly use, but I use `ascii` when I can't distinguish between 0 and O in a font ? `ascii 0`, for example, clears that right up.

Re: Unix Commands I Wish I’d Discovered Years Earlier

#233
post #148

Earlier quoted context omitted.

I am not saying find is outputting files, I am saying it is decoding the full table entry for each file and formatting it, then passing that listing as an entry to wc. Which has to be a bunch of overhead that adds up when you have hundreds of thousands of files to count. All we want from find is "count the number of inode entries in this tree branch that are type f". No formatting, no output, just count. That has to…

OMM, looking at 700k files on a spinning disk, I'm getting an uncached run at 1m13s, and a cached run at 1.2 seconds. That's "time find . | wc -l" It's going to be disk limited unless you're in cache. Switching to "time find . -printf '1' | wc -c" lowers overhead to .7 seconds, so roughly 1us/file.

There is a more important benefit to using the -prinf '1' approach - which is that it won't miscount the result if any of the filenames contain newlines.

Re: Unix Commands I Wish I’d Discovered Years Earlier

#234
post #8

Earlier quoted context omitted.

Right, you can use this to easily find the number of days in an arbitrary month in a script: % cal 2 1972 | tail +3 | wc -w 29

tail: cannot open +3 for reading: No such file or directory What am I doing wrong? This worked like a charm though: cal dec 2002 | tail -6 | wc -w (since it always takes up 6 lines, even sep 1752)

The "+n" syntax is not standards compliant, from the tail info page (on fedora 19):

  On older systems, the leading '-' can be replaced by '+' in the obsolete option syntax with the same meaning as in counts, and obsolete usage overrides normal usage when the two conflict.  This obsolete behavior can be enabled or disabled with the '_POSIX2_VERSION' environment variable (*note Standards conformance::).

Re: Unix Commands I Wish I’d Discovered Years Earlier

#235
post #53
post #18

I believe xxd is actually part of vim and not a Unix command itself. It's used to support hex-editing binary files, but you can see why it's useful in other roles as well.

The origins of xxd seem to be a bit murky, as I've seen others say the same thing about xxd being available only if vim is installed, but I've never seen a Unix system that didn't have vi(m) included. $ man xxd | grep vi Use xxd as a filter within an editor such as vim(1) to hexdump a region Use xxd as a filter within an editor such as vim(1) to recover a binary Use xxd as a filter within an editor such as vim(1) to…

There was a time when I, annoyed at being thrown into vi(m) whenever something spawned an editor, rather than setting the EDITOR environment variable on login, removed vi and replaced it with symlinks to emacs on the servers I managed.

I'm a bit more tolerant of vi now, but just because I "never" see it courtesy of suitable EDITOR entries.

Re: Unix Commands I Wish I’d Discovered Years Earlier

#236
post #189
post #177

Earlier quoted context omitted.

Isn't that the same as ls -1 ?

Mostly, yes, except that ls -1 does not turn off colours, and maybe there are a few more differences.

I can't imagine why anyone would want to spawn another process instead of just RTFM, if you are on linux:

    ls --color=never -1

Re: Unix Commands I Wish I’d Discovered Years Earlier

#238
post #189

Earlier quoted context omitted.

Mostly, yes, except that ls -1 does not turn off colours, and maybe there are a few more differences.

I can't imagine why anyone would want to spawn another process instead of just RTFM, if you are on linux: ls --color=never -1

Because, in many - if not most - situations, spawning another process is insanely lightweight compared to the cognitive/physical load of your alternative (which includes remembering the switch and its value ("never" is hardly intuitive), remembering whether or not you're using a system that supports it (surprise, surprise, OSX doesn't), and typing all those extra characters).

Admittedly, I never actually do this because I don't ever care to not see colour (what would be the motive?), but I can understand why the OP does what they do.

Re: Unix Commands I Wish I’d Discovered Years Earlier

#239
post #189

Earlier quoted context omitted.

Mostly, yes, except that ls -1 does not turn off colours, and maybe there are a few more differences.

I can't imagine why anyone would want to spawn another process instead of just RTFM, if you are on linux: ls --color=never -1

You are Randal L. Schwartz and I claim my five pounds.

[http://partmaps.org/era/unix/award.html]

Re: Unix Commands I Wish I’d Discovered Years Earlier

#240

Earlier quoted context omitted.

Great links, though I admit when I saw the OP I was expecting content like that and was pleasantly surprised that they really were "Unix commands I wish I'd discovered years earlier", and not the standard array of unix tips+tricks that you can get by without for awhile but as you become more advanced become second-nature. "Man ascii." The number of times that I wound up generating my own ascii table from whatever lan…

re: ascii tables You reminded me of something. There is actually a really cool and simple site called asciiflow [1], which I use all the time to draw diagrams for explaining things in email, etc. It's pretty cool, and was even submitted several times to HN [2, 3]. [1] http://www.asciiflow.com/#Draw [2] https://news.ycombinator.com/item?id=2847177 [3] https://news.ycombinator.com/item?id=3598177

Its really cool that this is a GWT app as well - don't see much of those these days.
Post reply on HN