0

I'm currently working on a task of archiving an old web application. I made back-ups of the database and the application itself, now I'm trying to back-up the filestore that contains all uploaded files.

Unfortunately, said application hasn't always correctly handled uploaded files, which has resulted in a lot of files containing the full pathname on the client that uploaded them, for example "C:\test\test.doc".

I want to create a tar archive containing all the files, but tar cf gives errors on files having a colon in their name. I tried escaping, but no luck.

An example:

-rw-r--r-- 1 root root 29696 Jan  3 09:43 C:\test\test.doc

Just tar everything:

[root@server test]# tar cf test.tar *
tar: C\:\test\test.doc: Cannot stat: No such file or directory
tar: Error exit delayed from previous errors

Surrounded by double quotes:

[root@server test]# tar cf test.tar "C:\\test\\test.doc"
tar: C\:\test\test.doc: Cannot stat: No such file or directory
tar: Error exit delayed from previous errors

Using the escape character:

[root@server test]# tar cf test.tar C\:\\test\\test.doc
tar: C\:\test\test.doc: Cannot stat: No such file or directory
tar: Error exit delayed from previous errors

Is there a way to achieve this (without file rename)?

  • 1
    Have you tried the first match on google for "tar escape colon" search? – Zumo de Vidrio Jan 3 '17 at 9:05
  • Yup, first hit is about extracting a tar file with a colon in its name ;) – verhage Jan 3 '17 at 9:13
3

Use . to archive the whole directory instead of *

tar cf ../test.tar .
1

The following also works (escape the \ inside single quotes):

$ touch 'C:\test\test.doc'
$ ls
C:\test\test.doc
$ tar cf test.tar 'C:\\test\\test.doc' 
$ tar tf test.tar 
C:\\test\\test.doc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.