按文件复制目录树

发布于 2024-08-08 06:37:36 字数 550 浏览 6 评论 0原文

我的顾问经常将一堆软件编译到他的 /usr/local 中,然后将他的 /usr/local 作为 tarball 分发。然后,我将 tarball 提取到我们的实验室机器上供我们使用。到目前为止,这一切都很好,我们只需用 tarball 的内容替换旧的 /usr/local 即可。

但我已经开始在这些机器上安装我自己的软件。如果我删除 /usr/local,显然某些软件和配置也会被删除。

相反,我如何将文件从 tarball 递归复制到 /usr/local 中的相应目录中?

例如:

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

等等。

或者这对 ServerFault 来说是一个更好的问题吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

那支青花 2024-08-15 06:37:36
$ cd /usr
$ tar xvf f.tar

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

虽然实际上,我认为它应该放在其他目录中,或者放在 /usr/local/ 的子目录中。除了默认的 PATH 组件之外,/usr/local/ 并没有什么神奇之处。

$ 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.

琴流音 2024-08-15 06:37:36

cp 命令具有用于递归复制的 -r 标志:

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

请查找系统的 cp 手册页以获取更多信息。

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.

陌路黄昏 2024-08-15 06:37:36

使用 k 选项并指定目标以防止覆盖文件:

$ 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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文