When working with the output of commands such as locate
which produce lists of paths in "human readable form" (i.e. without \
in front of spaces), how do you redirect their output to another command?
The output of $ locate [something]
produces paths with spaces in them, which inhibits other programs to use the paths in the case they contain spaces. For example, if I were to
$ du -h `locate *.doc`
this will produce an error on all files and directories that contain spaces. (wrapping the ticks in spaces does not work)
find
orlocate -0
acceptable? If not, why? – George Vasiliou Apr 24 '17 at 21:55command1
is NULL separated$ [command1] | xargs -0 [command2]
will accomplish what I want. – rien333 Apr 24 '17 at 22:10locate -0
orfind -print0
as advised in bellow answer will generate a null separated list of files/paths; xargs will handle this null byte separation and will feed correctlydu
utility. So, bellow answer is your solution. There is nothing more rigid to overcome special chars (like spaces) in filenames/pathnames than using tools which support null byte separated results (and both locate and find can null separate their results) – George Vasiliou Apr 24 '17 at 22:15