用于删除除.cpp文件以外的所有文件的Shell命令
我想删除目录中的所有文件,但不想删除用于删除除.cpp文件以外的所有文件的Shell命令,shell,Shell,我想删除目录中的所有文件,但不想删除.cpp文件 我需要一些命令,比如: rm all except .cpp files 编辑 基于,您还可以循环自己: for f in *; do if [[ $f != *.cpp ]]; then rm "$f"; fi; done 否则,类似的方法可能会奏效: ls | grep -v ".cpp$" | xargs rm 如果要递归执行,可以使用: find . -type f -not -iname "*.cpp" | xargs rm
.cpp
文件
我需要一些命令,比如:
rm all except .cpp files
编辑
基于,您还可以循环自己:
for f in *; do if [[ $f != *.cpp ]]; then rm "$f"; fi; done
否则,类似的方法可能会奏效:
ls | grep -v ".cpp$" | xargs rm
如果要递归执行,可以使用:
find . -type f -not -iname "*.cpp" | xargs rm
在bash中,您可以通过运行
shopt-s extglob
打开extglob
(如果您还没有),然后:
rm !(*.cpp)
(运行echo!(*.cpp)
首先检查!)