小智 24
Bash 扩展了 globbing(首先测试,然后删除回声):
shopt -s extglob
echo rm -rf !(A)
Run Code Online (Sandbox Code Playgroud)
dot*_*joe 14
find -maxdepth 1 -type d -not -name A -not -name "." -exec rm -ir {} \;
Run Code Online (Sandbox Code Playgroud)
Bre*_*nt 10
关于什么:
mv A /tmp/
rm * -rf
mv /tmp/A .
Run Code Online (Sandbox Code Playgroud)
这避免了其他命令中拼写错误的一些“可怕”。
就像是
find . -type d -not -name A -exec rm -ir {} \;
Run Code Online (Sandbox Code Playgroud)
应该做。
编辑
确实应该是
find . -type d -maxdepth 1 -not -name A -exec rm -ir {} \;
Run Code Online (Sandbox Code Playgroud)
防止find
在A以下递归。