明显的解决scheme产生1:
bash$ rm -rf .* rm: cannot remove directory `.' rm: cannot remove directory `..' bash$ echo $? 1
一个可能的解决scheme将跳过“。” 和“..”目录,但只会删除名称长于3个字符的文件:
bash$ rm -f .??*
rm -rf。[^。]。* *
应该抓住所有的情况。 。* *只会匹配3个以上的字符文件名(如前面的回答中所解释的),。[^。]将捕获任何两个字符条目(非..)。
find -path './.*' -delete
这匹配当前目录中以a开头的所有文件.
并recursion删除它们。 非隐藏目录中的隐藏文件不被触摸。
如果你真的想擦掉目录中的所有东西 , find -delete
就足够了。
最好的方法可能是:
把rm改为ls -l如果你只是想看看会被删除什么,要详细输出你可能要添加-v选项到rm
PS。 不要忘记结束'\';
ls -la | awk '$NF ~ /^\.[^.]+/ {print $NF}' | xargs rm -rf ls -la ............. long list (all files and folders) $NF ................ last field (file or folder name) ~ ................ Regular Expression match /^\.[^.]+/ ......... dot followed by not dot at least once + If the last field $NF match pattern show it and send it to xargs which will perform the task.