General Computing
linux tar archiving special-characters
Updated Sat, 23 Jul 2022 13:04:11 GMT

Tar cf cannot archive files with a colon in their name


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)?




Solution

Use . to archive the whole directory instead of *

tar cf ../test.tar .