0

I want to cat several files that are to be found using find.

The file names contain spaces. This is what I have tried:

$  find "/tmp/database"  -name "FOO 03-11*" 
/tmp/database/01/FOO 03-11.txt
/tmp/database/03/FOO 03-11.txt
/tmp/database/02/FOO 03-11.txt
/tmp/database/05/FOO 03-11.txt
/tmp/database/04/FOO 03-11.txt

$  find "/tmp/database"  -name "FOO 03-11*" | sort
/tmp/database/01/FOO 03-11.txt
/tmp/database/02/FOO 03-11.txt
/tmp/database/03/FOO 03-11.txt
/tmp/database/04/FOO 03-11.txt
/tmp/database/05/FOO 03-11.txt

$  find "/tmp/database"  -name "FOO 03-11*" | sort | xargs
/tmp/database/01/FOO 03-11.txt /tmp/database/02/FOO 03-11.txt /tmp/database/03/FOO 03-11.txt /tmp/database/04/FOO 03-11.txt /tmp/database/05/FOO 03-11.txt

$  find "/tmp/database"  -name "FOO 03-11*" | sort | xargs cat
cat: /tmp/database/01/FOO: No such file or directory
cat: 03-11.txt: No such file or directory
cat: /tmp/database/02/FOO: No such file or directory
cat: 03-11.txt: No such file or directory
cat: /tmp/database/03/FOO: No such file or directory
cat: 03-11.txt: No such file or directory
cat: /tmp/database/04/FOO: No such file or directory
cat: 03-11.txt: No such file or directory
cat: /tmp/database/05/FOO: No such file or directory
cat: 03-11.txt: No such file or directory

I am using /bin/sh in FreeBSD 12, which is expected to be a POSIX compliant shell.

M.E.
  • 4,955
  • 4
  • 49
  • 128
  • 2
    If it's a POSIX-compliant shell, `cat /tmp/database/*/FOO\ 03-11*` should work fine. POSIX mandates that words resulting from a pathname expansion be sorted lexicographically. – oguz ismail May 30 '21 at 10:07
  • Thanks, that is useful information. Would that work if there is a folder under `/tmp/database/` that does not contain a file with that pattern? – M.E. May 30 '21 at 10:39
  • 1
    Yes, it will work. – oguz ismail May 30 '21 at 11:17

0 Answers0