1

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.

Phase
  • 13
  • 2

1 Answers1

2
cp -R $1 $2
find $2 -type f -exec bzip2 {} \;
Jay
  • 9,314
  • 7
  • 33
  • 40
  • Make sure you mark the question as answered so Jay gets the credit and the question doesn't show in the unanswered list. – Dan Short Sep 12 '11 at 18:51