如何在目录中递归地 bzip 归档特定文件而不在 bash 中归档文件本身?

发布于 2024-12-04 02:45:50 字数 1050 浏览 2 评论 0原文

正如标题所示,我正在尝试创建一个脚本,它将一个目录作为输入 bzip 目录中的文件,同时将目录本身保留到另一个作为输入的目录中。因此,例如:

$ tree testdir
testdir
├── foo.bar
├── hello.bar
├── hmm
│   ├── down.ov
│   ├── hulk.bar
│   ├── nope
│   │   ├── around.zap
│   │   ├── over.bar
│   │   ├── side.it
│   │   └── under.bar
│   ├── smash.er
│   └── up.bar
├── no.wsx
├── test.bar
└── yes.lol
$ ./script testdir testdir2
$ tree testdir2
testdir2
├── foo.bar.bz2
├── hello.bar.bz2
├── hmm
│   ├── down.ov.bz2
│   ├── hulk.bar.bz2
│   ├── nope
│   │   ├── around.zap.bz2
│   │   ├── over.bar.bz2
│   │   ├── side.it.bz2
│   │   └── under.bar.bz2
│   ├── smash.er.bz2
│   └── up.bar.bz2
├── no.wsx.bz2
├── test.bar.bz2
└── yes.lol.bz2

我知道如何做到这一点,但它涉及 while 循环和 cd 命令等等,我认为这是低效的。所以,我希望能从你们那里得到一些帮助。即使你们为我指明了正确的方向,那也很棒。

Just as the title says, I'm trying to create a script that will take a directory as input bzip the files within the directory while preserving the directories themselves into another directory taken as input. So, for example:

$ tree testdir
testdir
├── foo.bar
├── hello.bar
├── hmm
│   ├── down.ov
│   ├── hulk.bar
│   ├── nope
│   │   ├── around.zap
│   │   ├── over.bar
│   │   ├── side.it
│   │   └── under.bar
│   ├── smash.er
│   └── up.bar
├── no.wsx
├── test.bar
└── yes.lol
$ ./script testdir testdir2
$ tree testdir2
testdir2
├── foo.bar.bz2
├── hello.bar.bz2
├── hmm
│   ├── down.ov.bz2
│   ├── hulk.bar.bz2
│   ├── nope
│   │   ├── around.zap.bz2
│   │   ├── over.bar.bz2
│   │   ├── side.it.bz2
│   │   └── under.bar.bz2
│   ├── smash.er.bz2
│   └── up.bar.bz2
├── no.wsx.bz2
├── test.bar.bz2
└── yes.lol.bz2

I have an idea of how to do it, but it involves while loops and cd commands and whatnot, which I consider to be inefficient. So, I was hoping to get some help from you guys here. Even if you guys point me in the right direction that would be fantastic.

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

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

发布评论

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

评论(1

一个人的夜不怕黑 2024-12-11 02:45:50
cp -R $1 $2
find $2 -type f -exec bzip2 {} \;
cp -R $1 $2
find $2 -type f -exec bzip2 {} \;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文