0

I'm creating a tar file from a list of files with the -T option. When extracting the tar file, subdirectory permissions are root:root instead of the permissions on the directory itself? Any ideas how to fix this?

Example:

# cat filelist.txt

file1.txt

dir1/file2.txt

dir1/dir2/file3.txt

# tar cf files.tar -T filelist.txt

# tar xf files.tar

Ownership on extracted files match original ownership on file1.txt, file2.txt, and file3.txt Ownership on dir1 and dir2 does not match. Owner is root:root

I could follow a solution similar to Preserve ownership & rights of parent directory when extracting tar archive but was hoping there was another way as that might add up to some more work for a bunch of directories.

0

You need to back up the directories as well as the files, for which you have to do two things:-

1) Add the directories to your file list:

file1.txt
dir1
dir1/file2.txt
dir1/dir2
dir1/dir2/file3.txt

2) Add --no-recursion to the back-up run string to stop all the other files in the directories being included:

tar cf files.tar --no-recursion -T filelist.txt

Note that the order is important: the directories must precede any reference in a subdirectory or file; and the --no-recursion parameter must come before the -T, but after the cf FileName command.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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