Xargs -0 not working

Hi,

Can anyone tell me an alternative for -0 argument of xargs.

my os is HP-UX

find . -name "*.sh" -print0 | xargs -0
xargs: unknown option: -0

Thanks

It depends on what you're going to do with them. It's great you're considering protecting yourself against newlines in filenames. If you have bash available, it can read NUL terminated input like so (someone else can chime in about ksh, but I assume it's very similar):

$ while IFS= read -r -d '' f; do a+=("$f"); done < <(find . -name '*.txt' -print0); declare -p a
declare -a a='([0]="./file0123456789012foo.txt")'

I looks like you have GNU findutils already installed (since your find supports -print0 ).
This should also offer an xargs that supports --null . Perhaps you have a PATH issue or findutils hasn't been installed properly.

What output do you get from:

type find xargs

What is the full command-line you are trying to run? Many people think they need something like:

find path... primary... -print0 | xargs -0 command

when:

find path... primary... -exec command {} +

is faster and simpler. The xargs utility certainly has options that can't be duplicated by the find -exec primary, but if find -exec is sufficient for what you're doing, avoid the pipeline.

1 Like
type find xargs
find is /usr/bin/find
xargs is /usr/bin/xargs