开发者

shell script to delete a directory whose name is digit number?

In Unix, how c开发者_JAVA技巧an I write a shell script to delete a directory whose name is digit number ?

Thanks.


You can use the shell expansion for that:

$ mkdir 1 2 3 4 5
$ rmdir [0-9]

See http://www.gnu.org/software/bash/manual/bashref.html#Shell-Expansions for more information.


The following solution removes directories that is a number or more

shopt -s extglob
rm -fr +([0-9]) # use when directories are non-empty
rmdir +([0-9]) # use when you know the directories are all empty


If the digit is 0 just: rmdir 0


Delete all folders just containing digits in the current directory:

for i in `find . -maxdepth 1 | grep "^./[0-9]\+\$"`; do rm -rf $i; done
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜