5 ms·
To find VIM swp files you can run this command on your public_html directory: find . -name "*.swp" You can find and remove them with: find . -name "*
by mmorey 14y ago
To find VIM swp files you can run this command on your public_html directory:
find . -name "*.swp"
You can find and remove them with:
find . -name "*.swp" -exec rm -f \{\} \;
- mauvehaus 14y agoA solution using xargs instead of exec: find . -name "*.swp" | xargs rm I believe find -exec forks and execs once for every file found, xargs may only fork and exec once, provided that all of the files find finds fit in a single command line. Hopefully not an issue in this case, but it can greatly speed up a deletion when you have a lot of files to find and delete. [EDIT] Doesn't properly handle spaces in filenames, see the comments below for other slick solutions.
- nodata 14y agoPlease don't run the command above, it doesn't handle spaces. You might delete something you didn't intend to delete. You need to add -print0 to find, and -0 to xargs to make it work properly: find . -name "*.swp" -print0 | xargs -0 rm But better would be to use -delete as I wrote above.
- mauvehaus 14y agoI'm a little bummed to find that this doesn't work on Solaris either (just checked). I don't generally use spaces in paths, but it's probably about half luck that I haven't been bitten by this yet. And sadly, I can't always just put GNU findutils on.
- emillon 14y agoTechnically, your solution does not work with files whose name contain a space or newline. A working solution is either to do '-print0' in find and '-0' in xargs, or to just use '-delete' instead of the -exec. It is also possible to use '+' instead of ';' with '-exec' to say "fork as few times as possible", ie pack the largest list of arguments to rm you can. But '-delete', when supported, won't even fork/exec.
- nodata 14y agoFor GNU: find . -name "*.swp" -delete