Re: scripting question
In article <[🔎] 20030416001851.351A8422C@sitemail.everyone.net>,
Maria Rodriguez <maria@gatormail.ws> wrote:
>Hello!
>I have a directory that has a lot of subdirectories, only one of which I
>want to keep. Let's say I want to keep only the "B" subdirectory below:
>
>/path/to/A
>/path/to/B
>/path/to/C
>
>Is there a way >>> on the command line <<< to remove all the directories
>other than B?
'find' version:
$ cd /path/to
$ find . -path ./B -prune -o -print | xargs rm -rf
See 'man find', under the '-path' option there's almost literally
the above example.
pure 'sh' version:
$ cd /path/to
$ for i in *; do if [ "$i" != B ]; then rm -rf $i; fi; done
Mike.
Reply to: