dogewang
dogewang

Reputation: 678

Permission with tar command

enter image description here

enter image description here

I have some problem with linux "tar" command.I want to unzip a config001.gz to a directory(with owner root ,group root and 777 permission as show in pic).

My origin dir and target dir is shown in pic.
My question is:

my mount infomation: fuse.mfs rw,nosuid,nodev,relatime,user_id=0,group_id=0,allow_other 0 0

Upvotes: 0

Views: 5401

Answers (1)

KamilCuk
KamilCuk

Reputation: 140940

why there is en empty folder in a config001.tgz file?

There is the "root folder" included in the tar archive. The folder the tar was in. The privileges, owner and group, permissions and creation/modification (or one of them, I am not sure) dates are included. You can create such archive with:

mkdir -p /tmp/a
cd /tmp/a
echo 123 > 1
echo 234 > 2
tar cfvp /tmp/test.tar .

# and inspect with:
tar -tvf ./test.tar 
drwxr-xr-x kamil/kamil       0 2019-07-15 12:50 ./
-rw-r--r-- kamil/kamil       4 2019-07-15 12:50 ./2
-rw-r--r-- kamil/kamil       4 2019-07-15 12:50 ./1

By specifing the ., ie. the current directory, the information about the current directory itself will be included in he tar. Ie. the information about the owner and group, permissions and dates.

if I don't append --no-overwrite-dir after command,it will raise error, what permission does "tar" want to change?

tar wants to change the permissions of the directory you are inside. The hpc_dir directory. The hpc_dir is owned by root, so tar can't change/touch it.

why --no-overwrite-dir option can fix the problem?

Because then tar sees the the currect directory hpc_dir exists. Because of that, tar doesn't try to create the directory, nor tries to change the owner and group permissions of the directory, nor tries to restore the creation date of the directory.

You could just go with mkdir somedir; tar xzfv archive.tar -C somedir - that way the somedir will be created by current user, so tar will be able to change it's properties.

Or you could just change the owner of hpc_dir directory, letting your user modify it.

Upvotes: 2

Related Questions