LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   What does tar -cp do? (https://www.linuxquestions.org/questions/linux-newbie-8/what-does-tar-cp-do-741025/)

catkin 07-18-2009 11:33 AM

What does tar -cp do?
 
Hello :)

I cribbed a command intended to make an exact copy of files to another directory
Code:

tar cpBf - . | (cd <target directory>; tar xBf -)
and stupidly did not check it against the man page. Regards the p option the man page says "p, --same-permissions, --preserve-permissions. ignore umask when extracting files (the default for root)". Thus the p option is undefined when used with the c (create) option; it is only defined in conjunction with the x (extract) option.

The source directories (/etc/rc.[0-6S].d in turn) contain symbolic links and an ordinary file. After running the command, the modification times on all the symlinks was reset to the time the tar command was run; the ordinary files had the original modification time.

How did that happen?!

That's what backups are for :cool:

Edit:
Code:

c@CW8:~$ tar --version
tar (GNU tar) 1.19

Best

Charles

stress_junkie 07-18-2009 01:24 PM

Are you just complaining?

You didn't give the exact command that got you into trouble. Did you overwrite the files in the same place?

I wonder if you are confusing access time with modification time. If you overwrote the original files then the modification time change makes sense. Otherwise it doesn't.

This is how to use tar to copy a directory tree. I use this all the time.
Code:

tar c . | tar --directory /destination/dir -xvp
Code:

tar --version
tar (GNU tar) 1.19

I used to use that (cd /destination/dir; tar xp -) but the --directory parameter just makes it all much simpler.

catkin 07-18-2009 01:40 PM

Thanks stress_junkie :)
Quote:

Originally Posted by stress_junkie (Post 3611978)
Are you just complaining? It seems as though you answered your own question. First, you improperly used the p parameter.

This is how to use tar to copy a directory tree. I use this all the time.
Code:

tar c . | tar --directory /destination/dir -xvp
Code:

tar --version
tar (GNU tar) 1.19

I used to use that (cd /destination/dir; tar xp -) but the --directory parameter just makes it all much simpler.

Not complaining -- things are how they are -- more wanting to understand. Maybe it's an undocumented feature that some guru can explain.

Conventionally, incorrect use of options results in an error so I would regard the reported behaviour as a bug if it is as I presently understand it, especially as I don't expect tar c with any options to change any of the source files' properties except for access time.

Thanks for the "heads up" on the --directory option; it is a useful feature.

BTW, is it possible to use tar to copy symbolic links without changing their modification time?

Best

Charles


All times are GMT -5. The time now is 12:19 PM.