Archive

Archive for the ‘GNU Tools’ Category

Null delimit find output

November 8th, 2009 admin No comments

If you are attempting to pipe the output of find to another command
such as xargs, and your files have quotes, spaces, or other “nonstandard”
characters in them, you can null terminate (rather than newline terminate) your
find output with -print0. You can then use the -0 option
to xargs to read the NUL delimeted output.

For example, I had a bunch of 1252 byte files in a directory with spaces in their
filenames. So…

# find . -size 1252c -print0 | xargs -0 rm

Too easy!

Cheers,
Kevin

Categories: GNU Tools, One Liners Tags:

Formatting seq output

November 3rd, 2009 admin No comments

seq comes with the -f option, allowing us to specify a printf(3) format string.

For example, to zero pad seq output (five zeros):

$ seq -f %05g 1 10
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010

See: seq(1) printf(3)

Cheers,
Kevin

Categories: GNU Tools, One Liners Tags: