How to delete all hidden .swp files from terminal
How can I delete all .swp files? I tried rm *.swp
but I got 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
What you wanted to do is
rm .*swp
The *
does not match files starting with a .
unless you turn on dotglob (assuming you are using 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
If you say: files are hidden, then they start with a dot (.), so try:
find . -type f -name ".*.swp" -exec rm -f {} \;
With this approach you're looking for all hidden files into the current directory and subdirectories. If you want delete the hidden files of just the current directory, a simple rm -f .*.swp
works ok