LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Using tar on filenames containing spaces (https://www.linuxquestions.org/questions/linux-newbie-8/using-tar-on-filenames-containing-spaces-467157/)

soaked 07-24-2006 12:06 PM

Using tar on filenames containing spaces
 
I had an incremental backup script that produces a tarball of all files that have been amended in the last 7 days. It includes this line:

Code:

tar -rf /var/www/vhosts/<***>/tarbackupw_`date +%Y_%m_%d`.tar `find /var/www/vhosts/<***>/forums -type f -mtime -7`
It used to work fine, but now I have a new 3rd party script which produces files on the server that contain spaces in the filenames. So now I get this kind of error:

Code:

tar: /var/www/vhosts/<***>/forums/downloads/files/36-rct: Cannot stat: No such file or directory
tar: grand: Cannot stat: No such file or directory
tar: glacier.zip: Cannot stat: No such file or directory
tar: Error exit delayed from previous errors

(The filename is "36-rct grand glacier.zip")

Please can anybody suggest a similar script that will produce a tarball WITHOUT changing the filenames?

berbae 07-24-2006 12:21 PM

Try that:
Quote:

tar -rf /var/www/vhosts/<***>/tarbackupw_`date +%Y_%m_%d`.tar `find /var/www/vhosts/<***>/forums -type f -mtime -7 -exec echo \"{}\" \;`
to get "36-rct grand glacier.zip" with the double quotes for each file.

Matir 07-24-2006 12:21 PM

Yes, try:
Code:

tar -rf /var/www/vhosts/<***>/tarbackupw_`date +%Y_%m_%d`.tar `find /var/www/vhosts/<***>/forums -type f -mtime -7 -exec echo "{}" \;`

berbae 07-24-2006 12:35 PM

Hi Matir
Same idea at the same time!
But the double quotes in the echo must be backslashed.

Matir 07-24-2006 12:37 PM

Oops, yeah, they should be. Sorry, didn't test it before I posted it. :)


All times are GMT -5. The time now is 10:28 PM.