Live data from Hacker News

Unix Commands I Abuse Every Day

everythingsysadmin.com

1–10 of 108 posts

Re: Unix Commands I Abuse Every Day

#2
My #1 abuse is xargs -n1.

A lot of people like writing bash for loops, I will try and avoid that as much as possible, xargs -n1 is the bash equivalent of a call to 'map' in a functional language.

For instance, let's say you want to create thumbnails of a bunch of jpegs:

find images -name "*.jpg" | xargs -n1 -IF echo F F | sed -e 's/.jpg$/_thumb.jpg/' | xargs -n2 echo convert -geometry 200x

Additionally, it's fully parallelizable as xargs supports something akin to pmap.

Re: Unix Commands I Abuse Every Day

#3
cat foo | less

Normally I'd typed something like "grep -i 'something' foo | less", and wanted to just up arrow the previous line and change the grep stuff to cat. I don't know why, it doesn't really save me anything. Maybe it's the hackerish "because I can, that's why" instinct at work.

Re: Unix Commands I Abuse Every Day

#4
post #2

My #1 abuse is xargs -n1. A lot of people like writing bash for loops, I will try and avoid that as much as possible, xargs -n1 is the bash equivalent of a call to 'map' in a functional language. For instance, let's say you want to create thumbnails of a bunch of jpegs: find images -name "*.jpg" | xargs -n1 -IF echo F F | sed -e 's/.jpg$/_thumb.jpg/' | xargs -n2 echo convert -geometry 200x Additionally, it's fully pa…

If you like xargs, but want jobs to execute in parallel, you may enjoy GNU parallel.

Your trivial example:

find images -name "*.jpg" | parallel convert -geometry 200x {} {.}_thumb.jpg

Re: Unix Commands I Abuse Every Day

#5
post #4
post #2

My #1 abuse is xargs -n1. A lot of people like writing bash for loops, I will try and avoid that as much as possible, xargs -n1 is the bash equivalent of a call to 'map' in a functional language. For instance, let's say you want to create thumbnails of a bunch of jpegs: find images -name "*.jpg" | xargs -n1 -IF echo F F | sed -e 's/.jpg$/_thumb.jpg/' | xargs -n2 echo convert -geometry 200x Additionally, it's fully pa…

If you like xargs, but want jobs to execute in parallel, you may enjoy GNU parallel. Your trivial example: find images -name "*.jpg" | parallel convert -geometry 200x {} {.}_thumb.jpg

xargs --max-procs=#

Re: Unix Commands I Abuse Every Day

#6
Random note. The most commonly "abused" Unix command is cat. The name is short for "concatenate", and its intended purpose was originally to combine 2 or more files at once.

Therefore every time you use it to spool one file into a pipeline, that is technically an abuse!

Re: Unix Commands I Abuse Every Day

#9
post #2

My #1 abuse is xargs -n1. A lot of people like writing bash for loops, I will try and avoid that as much as possible, xargs -n1 is the bash equivalent of a call to 'map' in a functional language. For instance, let's say you want to create thumbnails of a bunch of jpegs: find images -name "*.jpg" | xargs -n1 -IF echo F F | sed -e 's/.jpg$/_thumb.jpg/' | xargs -n2 echo convert -geometry 200x Additionally, it's fully pa…

Would anyone mind doing me a favor by explaining xargs in more detail? I've tried learning it a couple times but I always seem to forget the primary situations in which it's useful. Thank you in advance!

Re: Unix Commands I Abuse Every Day

#10
post #3

cat foo | less Normally I'd typed something like "grep -i 'something' foo | less", and wanted to just up arrow the previous line and change the grep stuff to cat. I don't know why, it doesn't really save me anything. Maybe it's the hackerish "because I can, that's why" instinct at work.

It'll save you a few more keystrokes if you do

    cat !$ | less
!$ is "the last argument to the previous command".
Post reply on HN