Random oneliners

From diffies' wiki
Jump to navigationJump to search

Here I place some useful/interesting/silly oneliners – mostly in GNU bash and Perl.

List characters used in a file tree

This produces a neatly formatted listing of special characters in a given directory tree. (Note the slash, which is the path separator.)

find directory/ | fold -w1 | sort | uniq | fmt

Example output:

_ - @ / = 0 1 2 3 4 5 6 7 8 9 a A b B c C d D e E f F g G h H i j J l
L m n N o p P q r R s S t u U v w x y Y

Note that this breaks for whitespace (ASCII space is rendered as a blank line at the beginning of the output) and control characters, not to mention Unicode.

Processing of a big filesystem trees can take a considerable time, as this dumb oneliner sorts the letters before deduplicating them.

List extensions in a file tree

This one is just like #List characters used in a file tree, but it operates on file extensions.

find -name '?*.*' -type f | sed 's/.*[.]//' | sort | uniq | fmt

Consider adding another uniq to save memory when sorting large trees.

Example output (executed on the FreeRTOS source tree):

asm bat c cfg cmake config h idx inc md pack png py readme rev s S s26
s43 s79 s82 s85 s90 sample sh src txt url xc yaml yml

Note the find pattern: It requires filenames with a dot and at least one character before it. This omits hidden files, which we usually don't want in our output.