5
1
I want to archive all .ctl files in a folder, recursively.
tar -cf ctlfiles.tar `find /home/db -name "*.ctl" -print`
The error message :
tar: Removing leading `/' from member names
tar: /home/db/dunn/j: Cannot stat: No such file or directory
tar: 74.ctl: Cannot stat: No such file or directory
I have these files: /home/db/dunn/j 74.ctl and j 75. Notice the extra space. What if the files have other special characters? How do I archive these files recursively?
This fails if a filename contains a newline. Rare but possible. – None – 2010-06-01T23:38:18.580
@davisre - good point – R Samuel Klatchko – 2010-06-01T23:42:56.453
this is the right answer, it tells one instance of tar to read the filenames needed to get the content from stdin.
@davisre: i tried to create a filename in zsh with ctrl-v-enter, this creates a \r and this solution still works. maybe with a \n it does not work but i think that is pretty rare to have such filenames, it is more probable to have unicode chars in the filenames than a \n. – akira – 2010-06-02T12:06:05.737
You can fix the newline problem with
– wchargin – 2019-07-12T20:14:41.047--null
; see David Bartlett’s answer. (This also works with arbitrary Unicode characters, as long as they use an extended ASCII encoding like UTF-8 or ISO-8859-x.)