
using tar to copy files
July 24, 2007I found the ”tar“ command quite useful in copying a directory (including all its files and sub-directories) to another directory of my choice:
cd /from-stuff/
tar cf – . | (cd /to-stuff; tar xvf -)
/from-stuff/: the directory from which you want to copy the files
/to-stuff/: the directory to which you want to copy your stuff
I have not figured out the tar command yet, so i am currently using this like a black box with input(from-stuff) and an output(to-stuff)
Advertisement
Tar is really useful command
Here is short explanation :
tar cf – . | (cd /target; tar xvf -)
so: tar everything in current dir (.) and put the tar file to standard output (-), then change dir to /target and un-tar to current dir everything from standard input (-).
In this case standard output from first tar is piped to standard input of second tar.
cool! someone tool the trouble to explain it… thanx dude
A simpler way of doing this would be to use cp instead of tar. The -R flag enables you to copy recursively (i.e. the directory/files you specify, and everything underneath (in) them in the directory hierarchy. The new command would be:
cp -R /from-stuff /to-stuff
Good luck!
Though tar follows and keeps (broken) symlinks, permissions, etc. With cp is hassle…