delete all .swp file using rm command
I am trying to find and delete all .swp files in my current directory. I was using below command:
rm -i `find . | grep .swp$`
But everytime it is giving me this error:
rm: missing operand
Try `rm --help' for more information.
Anything wrong I am doing?
linux grep rm
add a comment |
I am trying to find and delete all .swp files in my current directory. I was using below command:
rm -i `find . | grep .swp$`
But everytime it is giving me this error:
rm: missing operand
Try `rm --help' for more information.
Anything wrong I am doing?
linux grep rm
1
see also How can I delete all files with a particular extension in a particular folder?
– don_crissti
Apr 27 '15 at 20:08
1
Please clarify your question. Do you want to delete files in your current directory, or in your current directory and all its subdirs?
– dr01
Apr 28 '15 at 9:14
add a comment |
I am trying to find and delete all .swp files in my current directory. I was using below command:
rm -i `find . | grep .swp$`
But everytime it is giving me this error:
rm: missing operand
Try `rm --help' for more information.
Anything wrong I am doing?
linux grep rm
I am trying to find and delete all .swp files in my current directory. I was using below command:
rm -i `find . | grep .swp$`
But everytime it is giving me this error:
rm: missing operand
Try `rm --help' for more information.
Anything wrong I am doing?
linux grep rm
linux grep rm
asked Apr 27 '15 at 20:01
arsenalarsenal
1,098142747
1,098142747
1
see also How can I delete all files with a particular extension in a particular folder?
– don_crissti
Apr 27 '15 at 20:08
1
Please clarify your question. Do you want to delete files in your current directory, or in your current directory and all its subdirs?
– dr01
Apr 28 '15 at 9:14
add a comment |
1
see also How can I delete all files with a particular extension in a particular folder?
– don_crissti
Apr 27 '15 at 20:08
1
Please clarify your question. Do you want to delete files in your current directory, or in your current directory and all its subdirs?
– dr01
Apr 28 '15 at 9:14
1
1
see also How can I delete all files with a particular extension in a particular folder?
– don_crissti
Apr 27 '15 at 20:08
see also How can I delete all files with a particular extension in a particular folder?
– don_crissti
Apr 27 '15 at 20:08
1
1
Please clarify your question. Do you want to delete files in your current directory, or in your current directory and all its subdirs?
– dr01
Apr 28 '15 at 9:14
Please clarify your question. Do you want to delete files in your current directory, or in your current directory and all its subdirs?
– dr01
Apr 28 '15 at 9:14
add a comment |
4 Answers
4
active
oldest
votes
The error message you received probably indicates that no file matched the name pattern .swp$. A generally safer way to do what you wrote (because it will handle any file name):
find . -name '*.swp' -print0 | xargs -0 rm -i --
In the snippet above, I used -print0 so that find separates
records with null characters; the default is newlines, which
unfortunately is valid within a filename. With -print0, the command
works works with any filenames, including any that embed
newlines. Likewise, xargs -0 processes its input as null-separated
records.
What is the-print0flag?
– T.Woody
Jan 14 at 17:57
Thanks! I will be removing my comments then ;)
– T.Woody
Jan 14 at 22:39
add a comment |
Or a variation with find alone e.g.:
find . -name "*.swp" -ok rm {} +
or just without confirmation (WARNING!):
find . -name "*.swp" -delete
1
Hah, I was thinking of posting the same, but then figured I would wait for comments, if any :). Note that POSIX find doesn't support closing a-okcommand with+; I would write-ok rm -- {} ;instead.
– dhag
Apr 27 '15 at 20:25
Thanks for the POSIX hint! I'm on OSX atm so I expected other limitations anyway. :)
– FloHimself
Apr 27 '15 at 20:28
add a comment |
If you want to be more restricted, you can use this:
find . -type f -name "*.swp" -exec rm -f {} ;
-0 for usingexec
– Michael Durrant
Apr 27 '15 at 20:37
@MichaelDurrant What's wrong with usingexec?
– Erathiel
Apr 28 '15 at 8:36
add a comment |
Always use the simplest tool for the job. As you want to operate on the current directory only, this command will work fine:
rm -i *.swp
1
This command is different from what the OP is doing, sincefindby default will recurse into subdirectories to find matching files.
– a CVn
Apr 28 '15 at 9:06
The OP wrote, verbatim: "I am trying to find and delete all .swp files in my current directory." He didn't specify that he wants to delete files in subdirectories also. As per OP's specifications, thermcommand I posted is the best choice.
– dr01
Apr 28 '15 at 9:11
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f198971%2fdelete-all-swp-file-using-rm-command%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
The error message you received probably indicates that no file matched the name pattern .swp$. A generally safer way to do what you wrote (because it will handle any file name):
find . -name '*.swp' -print0 | xargs -0 rm -i --
In the snippet above, I used -print0 so that find separates
records with null characters; the default is newlines, which
unfortunately is valid within a filename. With -print0, the command
works works with any filenames, including any that embed
newlines. Likewise, xargs -0 processes its input as null-separated
records.
What is the-print0flag?
– T.Woody
Jan 14 at 17:57
Thanks! I will be removing my comments then ;)
– T.Woody
Jan 14 at 22:39
add a comment |
The error message you received probably indicates that no file matched the name pattern .swp$. A generally safer way to do what you wrote (because it will handle any file name):
find . -name '*.swp' -print0 | xargs -0 rm -i --
In the snippet above, I used -print0 so that find separates
records with null characters; the default is newlines, which
unfortunately is valid within a filename. With -print0, the command
works works with any filenames, including any that embed
newlines. Likewise, xargs -0 processes its input as null-separated
records.
What is the-print0flag?
– T.Woody
Jan 14 at 17:57
Thanks! I will be removing my comments then ;)
– T.Woody
Jan 14 at 22:39
add a comment |
The error message you received probably indicates that no file matched the name pattern .swp$. A generally safer way to do what you wrote (because it will handle any file name):
find . -name '*.swp' -print0 | xargs -0 rm -i --
In the snippet above, I used -print0 so that find separates
records with null characters; the default is newlines, which
unfortunately is valid within a filename. With -print0, the command
works works with any filenames, including any that embed
newlines. Likewise, xargs -0 processes its input as null-separated
records.
The error message you received probably indicates that no file matched the name pattern .swp$. A generally safer way to do what you wrote (because it will handle any file name):
find . -name '*.swp' -print0 | xargs -0 rm -i --
In the snippet above, I used -print0 so that find separates
records with null characters; the default is newlines, which
unfortunately is valid within a filename. With -print0, the command
works works with any filenames, including any that embed
newlines. Likewise, xargs -0 processes its input as null-separated
records.
edited Jan 14 at 20:09
answered Apr 27 '15 at 20:07
dhagdhag
11.3k33045
11.3k33045
What is the-print0flag?
– T.Woody
Jan 14 at 17:57
Thanks! I will be removing my comments then ;)
– T.Woody
Jan 14 at 22:39
add a comment |
What is the-print0flag?
– T.Woody
Jan 14 at 17:57
Thanks! I will be removing my comments then ;)
– T.Woody
Jan 14 at 22:39
What is the
-print0 flag?– T.Woody
Jan 14 at 17:57
What is the
-print0 flag?– T.Woody
Jan 14 at 17:57
Thanks! I will be removing my comments then ;)
– T.Woody
Jan 14 at 22:39
Thanks! I will be removing my comments then ;)
– T.Woody
Jan 14 at 22:39
add a comment |
Or a variation with find alone e.g.:
find . -name "*.swp" -ok rm {} +
or just without confirmation (WARNING!):
find . -name "*.swp" -delete
1
Hah, I was thinking of posting the same, but then figured I would wait for comments, if any :). Note that POSIX find doesn't support closing a-okcommand with+; I would write-ok rm -- {} ;instead.
– dhag
Apr 27 '15 at 20:25
Thanks for the POSIX hint! I'm on OSX atm so I expected other limitations anyway. :)
– FloHimself
Apr 27 '15 at 20:28
add a comment |
Or a variation with find alone e.g.:
find . -name "*.swp" -ok rm {} +
or just without confirmation (WARNING!):
find . -name "*.swp" -delete
1
Hah, I was thinking of posting the same, but then figured I would wait for comments, if any :). Note that POSIX find doesn't support closing a-okcommand with+; I would write-ok rm -- {} ;instead.
– dhag
Apr 27 '15 at 20:25
Thanks for the POSIX hint! I'm on OSX atm so I expected other limitations anyway. :)
– FloHimself
Apr 27 '15 at 20:28
add a comment |
Or a variation with find alone e.g.:
find . -name "*.swp" -ok rm {} +
or just without confirmation (WARNING!):
find . -name "*.swp" -delete
Or a variation with find alone e.g.:
find . -name "*.swp" -ok rm {} +
or just without confirmation (WARNING!):
find . -name "*.swp" -delete
answered Apr 27 '15 at 20:18
FloHimselfFloHimself
6,36421318
6,36421318
1
Hah, I was thinking of posting the same, but then figured I would wait for comments, if any :). Note that POSIX find doesn't support closing a-okcommand with+; I would write-ok rm -- {} ;instead.
– dhag
Apr 27 '15 at 20:25
Thanks for the POSIX hint! I'm on OSX atm so I expected other limitations anyway. :)
– FloHimself
Apr 27 '15 at 20:28
add a comment |
1
Hah, I was thinking of posting the same, but then figured I would wait for comments, if any :). Note that POSIX find doesn't support closing a-okcommand with+; I would write-ok rm -- {} ;instead.
– dhag
Apr 27 '15 at 20:25
Thanks for the POSIX hint! I'm on OSX atm so I expected other limitations anyway. :)
– FloHimself
Apr 27 '15 at 20:28
1
1
Hah, I was thinking of posting the same, but then figured I would wait for comments, if any :). Note that POSIX find doesn't support closing a
-ok command with +; I would write -ok rm -- {} ; instead.– dhag
Apr 27 '15 at 20:25
Hah, I was thinking of posting the same, but then figured I would wait for comments, if any :). Note that POSIX find doesn't support closing a
-ok command with +; I would write -ok rm -- {} ; instead.– dhag
Apr 27 '15 at 20:25
Thanks for the POSIX hint! I'm on OSX atm so I expected other limitations anyway. :)
– FloHimself
Apr 27 '15 at 20:28
Thanks for the POSIX hint! I'm on OSX atm so I expected other limitations anyway. :)
– FloHimself
Apr 27 '15 at 20:28
add a comment |
If you want to be more restricted, you can use this:
find . -type f -name "*.swp" -exec rm -f {} ;
-0 for usingexec
– Michael Durrant
Apr 27 '15 at 20:37
@MichaelDurrant What's wrong with usingexec?
– Erathiel
Apr 28 '15 at 8:36
add a comment |
If you want to be more restricted, you can use this:
find . -type f -name "*.swp" -exec rm -f {} ;
-0 for usingexec
– Michael Durrant
Apr 27 '15 at 20:37
@MichaelDurrant What's wrong with usingexec?
– Erathiel
Apr 28 '15 at 8:36
add a comment |
If you want to be more restricted, you can use this:
find . -type f -name "*.swp" -exec rm -f {} ;
If you want to be more restricted, you can use this:
find . -type f -name "*.swp" -exec rm -f {} ;
answered Apr 27 '15 at 20:27
canonalecanonale
1
1
-0 for usingexec
– Michael Durrant
Apr 27 '15 at 20:37
@MichaelDurrant What's wrong with usingexec?
– Erathiel
Apr 28 '15 at 8:36
add a comment |
-0 for usingexec
– Michael Durrant
Apr 27 '15 at 20:37
@MichaelDurrant What's wrong with usingexec?
– Erathiel
Apr 28 '15 at 8:36
-0 for using
exec– Michael Durrant
Apr 27 '15 at 20:37
-0 for using
exec– Michael Durrant
Apr 27 '15 at 20:37
@MichaelDurrant What's wrong with using
exec?– Erathiel
Apr 28 '15 at 8:36
@MichaelDurrant What's wrong with using
exec?– Erathiel
Apr 28 '15 at 8:36
add a comment |
Always use the simplest tool for the job. As you want to operate on the current directory only, this command will work fine:
rm -i *.swp
1
This command is different from what the OP is doing, sincefindby default will recurse into subdirectories to find matching files.
– a CVn
Apr 28 '15 at 9:06
The OP wrote, verbatim: "I am trying to find and delete all .swp files in my current directory." He didn't specify that he wants to delete files in subdirectories also. As per OP's specifications, thermcommand I posted is the best choice.
– dr01
Apr 28 '15 at 9:11
add a comment |
Always use the simplest tool for the job. As you want to operate on the current directory only, this command will work fine:
rm -i *.swp
1
This command is different from what the OP is doing, sincefindby default will recurse into subdirectories to find matching files.
– a CVn
Apr 28 '15 at 9:06
The OP wrote, verbatim: "I am trying to find and delete all .swp files in my current directory." He didn't specify that he wants to delete files in subdirectories also. As per OP's specifications, thermcommand I posted is the best choice.
– dr01
Apr 28 '15 at 9:11
add a comment |
Always use the simplest tool for the job. As you want to operate on the current directory only, this command will work fine:
rm -i *.swp
Always use the simplest tool for the job. As you want to operate on the current directory only, this command will work fine:
rm -i *.swp
answered Apr 28 '15 at 8:32
dr01dr01
16k114971
16k114971
1
This command is different from what the OP is doing, sincefindby default will recurse into subdirectories to find matching files.
– a CVn
Apr 28 '15 at 9:06
The OP wrote, verbatim: "I am trying to find and delete all .swp files in my current directory." He didn't specify that he wants to delete files in subdirectories also. As per OP's specifications, thermcommand I posted is the best choice.
– dr01
Apr 28 '15 at 9:11
add a comment |
1
This command is different from what the OP is doing, sincefindby default will recurse into subdirectories to find matching files.
– a CVn
Apr 28 '15 at 9:06
The OP wrote, verbatim: "I am trying to find and delete all .swp files in my current directory." He didn't specify that he wants to delete files in subdirectories also. As per OP's specifications, thermcommand I posted is the best choice.
– dr01
Apr 28 '15 at 9:11
1
1
This command is different from what the OP is doing, since
find by default will recurse into subdirectories to find matching files.– a CVn
Apr 28 '15 at 9:06
This command is different from what the OP is doing, since
find by default will recurse into subdirectories to find matching files.– a CVn
Apr 28 '15 at 9:06
The OP wrote, verbatim: "I am trying to find and delete all .swp files in my current directory." He didn't specify that he wants to delete files in subdirectories also. As per OP's specifications, the
rm command I posted is the best choice.– dr01
Apr 28 '15 at 9:11
The OP wrote, verbatim: "I am trying to find and delete all .swp files in my current directory." He didn't specify that he wants to delete files in subdirectories also. As per OP's specifications, the
rm command I posted is the best choice.– dr01
Apr 28 '15 at 9:11
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f198971%2fdelete-all-swp-file-using-rm-command%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
see also How can I delete all files with a particular extension in a particular folder?
– don_crissti
Apr 27 '15 at 20:08
1
Please clarify your question. Do you want to delete files in your current directory, or in your current directory and all its subdirs?
– dr01
Apr 28 '15 at 9:14