bourne-shell find-remove

时间:2012-03-02 04:45:53

标签: scripting sh

我正在尝试编写一个bourne-shell脚本,该脚本将字符串作为参数并删除包含该字符串的目录中的所有文件 我正在考虑使用find和execute rm all,但我刚开始使用b-shell

find . -name $1 'core' -exec rm -i* {}\;

任何帮助将不胜感激。感谢。

3 个答案:

答案 0 :(得分:1)

为什么不呢:

#!/bin/sh
rm *$1*

删除当前目录中包含您的参数的文件。

答案 1 :(得分:0)

remove.sh脚本:

#!/bin/sh
find . -type f -iname *$1* -exec rm -rf {} \;

用法:

$remove.sh "main"

答案 2 :(得分:0)

find . -type f -name "$1" -delete

这将递归到所有子目录。如果你不想这样,那么使用rm或-maxdepth 1。