4 ms·
Ask HN: What are some good examples to demonstrate unix philosophy?
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'm talking about a shell pipeline that'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.
I use gnu parallel a lot and naturally that's my first choice, something like:
$ <urllist ssh user@host 'parallel -j 30 curl "{}" | grep -Po "tel:\d+" | sed "s/tel://" | sort -u'
- devnonymous 13y agoI'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