views:

170

answers:

3

My advisor frequently compiles a bunch of software into his /usr/local and then distributes his /usr/local as a tarball. I then extract the tarball onto our lab machines for our use. Until now, this has worked fine, we just replace the old /usr/local with the contents of the tarball.

But I have started installing my own software on these machines. If I delete /usr/local, obviously some of that software and config gets deleted as well.

Instead, how can I recursively copy files from the tarball into the corresponding directory in /usr/local?

For example:

tarball path            filesystem path
------------            ---------------
local/bin/myprog   ->   /usr/local/bin/myprog
local/lib/mylib.so ->   /usr/local/lib/mylib.so

etc.

Or is this a better question for ServerFault?

+1  A: 
$ cd /usr
$ tar xvf f.tar

or

$ cd /tmp
$ tar xvf f.tar
$ cp -R local/. /usr/local/.

Although really, I think it should just go in some other directory, or in a subdir of /usr/local/. There isn't anything magical about /usr/local/ except perhaps a default PATH component.

DigitalRoss
+1  A: 

The cp command has the -r flag for copying recursively:

$ cp -r local/* /usr/local/

Please look up your system's man page for cp for more information.

Hai Vu
A: 

Use the k option and specify the destination to protect against overwriting files:

$ cd /usr 
$ tar xvfk localtarball.tar local
local/
local/file
tar: local/file: Cannot open: File exists
local/bar2/
local/bar2/bar3
tar: local/file: Cannot open: File exists
local/bar2a/bar2aY/
tar: Error exit delayed from previous errors
Dennis Williamson