

Ask HN: What are some good examples to demonstrate unix philosophy? - oxplot

If you were to explain to someone how linux is different, how simple tools are used together to achieve just about anything, what example(s) would you give them? I&#x27;m talking about a shell pipeline that&#x27;s useful and easy to understand but one that would be very difficult to get done in an environment like windows. Examples other than a shell pipeline are also fine as long as an outsider can relate to them.<p>I use gnu parallel a lot and naturally that&#x27;s my first choice, something like:<p>$ &lt;urllist ssh user@host &#x27;parallel -j 30 curl &quot;{}&quot; | grep -Po &quot;tel:\d+&quot; | sed &quot;s&#x2F;tel:&#x2F;&#x2F;&quot; | sort -u&#x27;
======
devnonymous
I've always found the `find` and xargs command pair to be the quickest way to
demonstrate the unix philosophy. For example, consider, if we want to do this
...

# inplace (-i), execute (-e), subtitution of the regular expression 'Pattern'
(s/Pattern/), # with the word 'Substitution' (Substitution/), on all matches
(g) in file 'filename', you'd do ...

$ sed -i -e 's/Pattern/Substitution/g' <filename>

# Now if you want to do this for all text files under a directory tree ...

$ find -name ' _.txt ' | xargs sed -i -e 's/Pattern/Substitution/g'

# ...while limiting it to just 2 levels of 'depth' ...

$ find -name '_.txt' -maxdepth 2 | xargs sed -i -e 's/Pattern/Substitution/g'

# ...and for only those that were modified yesterday ... ... # ...belonging to
a certain user .... ...

you get the idea. Other good tools that fall in the similar category are
'sort', 'uniq', 'tr' ...etc. Eg:

$ find /tmp/ -type f -exec stat -c "%s %n" {} \; | sort -n

