1

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.

1 Answer 1

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.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .