File name too long error with command ‘stat’

findstatxargs

I retrieve a booklist after seaching the python books in home directory using this command on OSX:

    find ~ -type f -iregex '.*python.*\.pdf'

the booklist

    ...
    .../Computing/Python/Beginning_Python.pdf
    .../Python/Core.Python.Applications.Programming.3rd.Edition.pdf
    .../Python/Packt.Mastering.Python.2016.4.pdf
    ...

I intend to check their status with command xargs and stat

    $ find ~ -type f -iregex '.*python.*\.pdf' | xargs stat -x
    # get error
    xargs: unterminated quote

Tried alternatively with option -0

    find ~ -type f -iregex '.*python.*\.pdf' | xargs -0 stat -x 
    # get error
    : stat: File name too long

How to resolve such a problem?

Best Answer

-0 to xargs doesn't make much sense if you don't also change the input to be 0-separated. Try find ~ -type f -iregex '.*python.*\.pdf' -print0 | xargs -0 stat -x

Related Question