-1

I retrieve a booklist after seaching the python books in home directory using command

    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 -0 stat -x

get error

 : stat: File name too long

How to conquer such a problem?

AbstProcDo
  • 19,953
  • 19
  • 81
  • 138
  • How many files match the regex? – Phil Mar 27 '18 at 11:48
  • there's 45 files matched @Phil – AbstProcDo Mar 27 '18 at 11:51
  • have you tried looping through the list of filenames from find, rather than piping directly to xargs? That way you could echo each filename and see if there is still an issue. – Phil Mar 27 '18 at 11:57
  • 1
    $ find ~ -type f -iregex '.*python.*\.pdf' | xargs -0 echo works well to print all the books @Phil – AbstProcDo Mar 27 '18 at 11:59
  • 1
    @WangGaowei That's because `echo` gets one argument with a bunch of embedded newlines, rather than `echo` being called with a single newline-free argument many times. – chepner Mar 27 '18 at 14:21
  • There's no need here (as is commonly the case) to use `xargs` with `find`; just use `find ~ -type f -iregex '.*python.*\.pdf' -exec stat -x {} \+`. – chepner Mar 27 '18 at 14:22

1 Answers1

2

If you use -0 with xargs, you are also supposed to use -print0 with find.

Arndt Jonasson
  • 856
  • 1
  • 6
  • 14