shi*_*ada 11 terminal bash shell command-line globbing
如何删除所有 .swp 文件?我试过了,rm *.swp但我得到了rm: *.swp: No such file or directory
rwxr-xr-x 16 teacher staff 544 Jan 17 13:19 .
drwxr-xr-x 19 teacher staff 646 Jan 16 12:48 ..
-rw-r--r-- 1 teacher staff 20480 Jan 17 09:48 .6-1-period-2.txt.swp
-rw-r--r-- 1 teacher staff 16384 Jan 17 09:05 .6-2-period-6.txt.swp
-rw-r--r--@ 1 teacher staff 6148 Jan 15 16:16 .DS_Store
-rw-r--r-- 1 teacher staff 12288 Jan 16 19:46 .grade8.txt.swp
-rw-r--r-- 1 teacher staff 11070 Jan 17 09:48 6-1-period-2.txt
Run Code Online (Sandbox Code Playgroud)
ter*_*don 10
你想做的是
rm .*swp
Run Code Online (Sandbox Code Playgroud)
该*不匹配开头的文件.,除非你打开dotglob(假设你正在使用bash):
$ ls -la
-rw-r--r-- 1 terdon terdon 0 Jan 17 05:50 .foo.swp
$ ls *swp
ls: cannot access *swp: No such file or directory
$ shopt -s dotglob
$ ls *swp
.foo.swp
Run Code Online (Sandbox Code Playgroud)
如果您说:文件是隐藏的,那么它们以点 (.) 开头,请尝试:
find . -type f -name ".*.swp" -exec rm -f {} \;
Run Code Online (Sandbox Code Playgroud)
通过这种方法,您可以在当前目录和子目录中查找所有隐藏文件。如果你只想删除当前目录的隐藏文件,一个简单的rm -f .*.swp工作就可以了
尝试使用这个
find . -type f -name "*.swp" -exec rm -f {} \;
-name "FILE-TO-FIND" : File pattern.
-exec rm -rf {} \; : Delete all files matched by file pattern.
-type f : Only match files and do not include directory names.
Run Code Online (Sandbox Code Playgroud)