Live data from Hacker News

Unix Commands I Abuse Every Day

everythingsysadmin.com

101–108 of 108 posts

Re: Unix Commands I Abuse Every Day

#101

Earlier quoted context omitted.

find ./ -name '*.log' -print0 | xargs -0 rm Fixes that issue and xargs is far more efficient, it doesn't launch a new process for each line like exec does, but far more importantly, xargs is generalizable to all commands so you only have to learn it once; exec is just an ugly hack on find, you can't generalize it across all commands; xargs is much more unixy.

> it doesn't launch a new process for each line like exec does Exec doesn't either if you use "+" as a terminator: find . $(options) -exec command {} \; executes one command per match, find . $(options) -exec command {} + executes a single command with all matches > exec is just an ugly hack on find Obvious and complete nonsense, -exec is both an important predicate of find and a useful and efficient tool. -print0/xa…

You apparently missed the part where I said "but far more importantly".

Re: Unix Commands I Abuse Every Day

#102

Earlier quoted context omitted.

> it doesn't launch a new process for each line like exec does Exec doesn't either if you use "+" as a terminator: find . $(options) -exec command {} \; executes one command per match, find . $(options) -exec command {} + executes a single command with all matches > exec is just an ugly hack on find Obvious and complete nonsense, -exec is both an important predicate of find and a useful and efficient tool. -print0/xa…

You apparently missed the part where I said "but far more importantly".

No, that's just your opinion and you're entitled to it so I don't care, the rest is factually incorrect.

Re: Unix Commands I Abuse Every Day

#103
post #74

Earlier quoted context omitted.

Wanting to remove the files was so common that some finds have it built-in. Avoids even the overhead of -exec rm {} +. find -name '*.log' -delete

True, but the issue isn't removing files, the issue is generalizing a command for mapping output of a command to another command. rm was just a simple example. xargs is far more useful than simply deleting files.

Removing files is a common need coupled with find yet many readers don't know of -delete; I was pointing it out. That doesn't weaken xargs's valid uses. You seem a little defensive? :-)

Re: Unix Commands I Abuse Every Day

#104
post #82

Earlier quoted context omitted.

It's most definitely catenate. I understand catenate to mean chain and concatenate to be to chain together. Since "cat foo bar xyzzy" doesn't modify the files to join them in any way I don't think they're chained together. Besides, ken & Co. aren't daft. con would be short for concatenate. :-)

According to the 1st Edition and 6th Edition manual pages: NAME cat -- concatenate and print See: http://man.cat-v.org/unix-1st/1/cat http://man.cat-v.org/unix-6th/1/cat I'm pretty sure based on the timeline of pipe (~1973, roughly V4) that the cat command (~1971 V1) predates pipes.

Fortunately they fixed that errant man page. :-) http://man.cat-v.org/plan_9/1/cat

Re: Unix Commands I Abuse Every Day

#105
Another 'less' abuse: using it as an interactive grep via '&' line filtering.

It's a newish feature of less (those of you with stale RHEL installs won't find it). Type '&' and you'll filter down a listing to match pattern. Regexes supported. Prefixed '!' negates filter.

Wishlist: interactive filter editing (similar to mutt's mail index view filters), so you don't have to re-type full expressions.

Re: Unix Commands I Abuse Every Day

#106

Earlier quoted context omitted.

You apparently missed the part where I said "but far more importantly".

No, that's just your opinion and you're entitled to it so I don't care, the rest is factually incorrect.

Oh, I agree on the + thing, I wasn't aware of that option, however, it doesn't make exec any more generalizable across commands which is what matters.

Re: Unix Commands I Abuse Every Day

#107
post #103

Earlier quoted context omitted.

True, but the issue isn't removing files, the issue is generalizing a command for mapping output of a command to another command. rm was just a simple example. xargs is far more useful than simply deleting files.

Removing files is a common need coupled with find yet many readers don't know of -delete; I was pointing it out. That doesn't weaken xargs's valid uses. You seem a little defensive? :-)

Too much reddit perhaps. I use the delete switch myself regularly.

Re: Unix Commands I Abuse Every Day

#108
Witless uninstall #1 (perfect for those crappy tarfiles that exact everything into the current directory)

    tar -tf tarfile.tar | xargs rm
Witless uninstall #2. Find a file that you changed just before "make install" into the wrong spot (usually config.log is a good candidate).

    find /bogus/installdir -newer config.log  | xargs rm
Yes, this is totally unsafe. But it's an abuse... so, there you go
Post reply on HN