如何在目录中递归地 bzip 归档特定文件而不在 bash 中归档文件本身?
正如标题所示,我正在尝试创建一个脚本,它将一个目录作为输入 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)