Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am trying to remove all vim swap file *.swp and remove them with a confirmation. The find command found the files, but rm says No such file or directory with the -i option. When I hardcode the path of the file and just use rm -i then it seems to work.

See below

(doors)hobbes3@hobbes3 ~/Sites $ find mysite mysite_BAK -name *.swp -exec 'rm -i {}' \;
find: rm -i mysite/templates/.base.html.swp: No such file or directory
find: rm -i mysite/templates/doors/orders/.create.html.swp: No such file or directory
find: rm -i mysite/templates/doors/orders/.detail.html.swp: No such file or directory
find: rm -i mysite/templates/doors/orders/.list.html.swp: No such file or directory
(doors)hobbes3@hobbes3 ~/Sites $ rm -i mysite/templates/.base.html.swp 
remove mysite/templates/.base.html.swp? n

I guess I'm doing something wrong with the -exec option. Any suggestions? Thanks in advance!

share|improve this question
Actually I just tried without the -i option and it still gave the same errors. Hmmm... –  hobbes3 Mar 25 '12 at 7:41
add comment

2 Answers

up vote 5 down vote accepted

The error is generated by find, not rm.

The reason is that you have written it so 'rm -i <file>' is the single argument. This shall be rewritten:

find mysite mysite_BAK -name *.swp -exec rm -i '{}' \;

so find gets multiple arguments after "-exec" and treats the first one as command and others as the command arguments.

share|improve this answer
A simple solution. Thanks. –  hobbes3 Mar 25 '12 at 7:54
You can also leave out the quotes around {} –  Bernhard Mar 25 '12 at 9:17
add comment

I usually find it easier to use simple tools combined

cd to dir and then:

rm -i `find . | grep .swp$`

its easier to remember (if performance is not an issue)!

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.