[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Parsing a file name in the shell



On Wed, 2002-02-06 at 11:52, Mark Asselstine wrote:
> You can shorten
> rm -rf {1,2,3,4,5,6,7,8,9,0}foo
> to
> rm -rf [0-9]*
> 
> This will remove any file or directory which has a numeric beginning for
> the
> directory you run the command from. Ideally you would put this in an
> executable
> script and have a cron job run it on occassion. You would end of with
> something
> like this.
> 
> #!/bin/bash
> cd [whatever directory]
> rm -rf [0-9]*

Hey, that's even better. No for loop. Nice and clean. Once again it is
proven that there are more ways to skin a cat then there are cats.

> 
> if you also have subdirectories to search you could do
> #!/bin/bash
> cd [whatever directory]
> for j in `find . -name "[0-9]*"`;do
> rm -rf $j
> done
> 
> again however this will remove all DIRECTORIES and FILES. To remove only
> 
> directories you need one small modification to test if it is a directory
> 
> and leave the files untouched.
> 
> #!/bin/bash
> cd [whatever directory]
> for j in `find . -name "[0-9]*"`;do
> if [ -d $j ];then
> rm -rf $j
> fi
> done
> 
> Again you would want to put this in an executable script and add it to
> you
> crontab to run occassionally.

Twas the plan. Erase early...erase often. Thanks.



Reply to: