How to remove all files starting with a certain string in Linux
I need to find all files starting with the name NAME
in a directory tree and remove all these files using one shell command.
linux bash
migrated from stackoverflow.com Oct 2 '12 at 13:40
This question came from our site for professional and enthusiast programmers.
add a comment |
I need to find all files starting with the name NAME
in a directory tree and remove all these files using one shell command.
linux bash
migrated from stackoverflow.com Oct 2 '12 at 13:40
This question came from our site for professional and enthusiast programmers.
add a comment |
I need to find all files starting with the name NAME
in a directory tree and remove all these files using one shell command.
linux bash
I need to find all files starting with the name NAME
in a directory tree and remove all these files using one shell command.
linux bash
linux bash
edited Oct 2 '12 at 14:36
slhck
161k47447470
161k47447470
asked Oct 2 '12 at 12:18
Achini PumikaAchini Pumika
156124
156124
migrated from stackoverflow.com Oct 2 '12 at 13:40
This question came from our site for professional and enthusiast programmers.
migrated from stackoverflow.com Oct 2 '12 at 13:40
This question came from our site for professional and enthusiast programmers.
add a comment |
add a comment |
7 Answers
7
active
oldest
votes
to delete all files which name has name--- you can use
find -name . 'name*' -exec rm {} ;
1
You can also add -f as an 'rm' argument so you don't get prompted for "Are you sure you want to remove X file?"
– UtahJarhead
Oct 2 '12 at 14:01
Which version ofgrep
has an-exec
switch?
– Ben Graham
Oct 3 '12 at 2:55
Why does this comment have downvotes?
– Ultrasonic54321
Jan 30 at 17:07
add a comment |
Delete all files in current directory and its sub-directories where the file name starts with "foo":
$ find . -type f -name foo* -exec rm {} ;
NB: use with caution - back up first - also do a dry run first, e.g.
$ find . -type f -name foo*
will just tell you the names of the files that would be deleted.
4
I had to delete over 2Million files and run in to trouble,find . -type f -name foo* -delete
did the trick
– Linas
Jan 25 '14 at 13:30
add a comment |
I have tried this way it is working for me try below command.
rm -rf Example*
here "Example" is text which is common for all files.
add a comment |
You can use find
:
find . -name "name*" -exec rm {} ;
Also instead of specifying '.' you can specify an absolute path.
– UtahJarhead
Oct 2 '12 at 14:02
add a comment |
With the globstar
option (enable with shopt -s globstar
):
rm -f **/NAME*
**/
expands to ./
, */
, */*/
, */*/*/
etc. If you have a directory name starting with NAME
, the command will complain that rm
can't remove directories, but that's all.
Notice that this might run into command line length limitations if the glob matches many files.
Alternatively, with as few invocations of rm
as possible, but not subject to any command line length limitations:
find . -type f -name 'NAME*' -exec rm -f {} +
(Notice the +
instead of ;
to close the -exec
statement.)
add a comment |
find . -name 'foo'* -type f -delete
seems like the simplest answer.
You can run this without the -delete
flag before to see which files will be deleted.
add a comment |
Search for the "Inode" number of the file/folder and then delete using inode number. Below is an example:
ls -il
3407873 drwxr-xr-x. 2 root root 4096 Mar 30 07:49 –p
find . -inum 3407873 -exec rm -rf {} ;
This is a good answer — to a different question. It’s not an answer to this question.
– Scott
Oct 26 '18 at 4:33
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2fsuperuser.com%2fquestions%2f482435%2fhow-to-remove-all-files-starting-with-a-certain-string-in-linux%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
7 Answers
7
active
oldest
votes
7 Answers
7
active
oldest
votes
active
oldest
votes
active
oldest
votes
to delete all files which name has name--- you can use
find -name . 'name*' -exec rm {} ;
1
You can also add -f as an 'rm' argument so you don't get prompted for "Are you sure you want to remove X file?"
– UtahJarhead
Oct 2 '12 at 14:01
Which version ofgrep
has an-exec
switch?
– Ben Graham
Oct 3 '12 at 2:55
Why does this comment have downvotes?
– Ultrasonic54321
Jan 30 at 17:07
add a comment |
to delete all files which name has name--- you can use
find -name . 'name*' -exec rm {} ;
1
You can also add -f as an 'rm' argument so you don't get prompted for "Are you sure you want to remove X file?"
– UtahJarhead
Oct 2 '12 at 14:01
Which version ofgrep
has an-exec
switch?
– Ben Graham
Oct 3 '12 at 2:55
Why does this comment have downvotes?
– Ultrasonic54321
Jan 30 at 17:07
add a comment |
to delete all files which name has name--- you can use
find -name . 'name*' -exec rm {} ;
to delete all files which name has name--- you can use
find -name . 'name*' -exec rm {} ;
edited Oct 10 '12 at 12:14
Community♦
1
1
answered Oct 2 '12 at 12:48
Dharshana
1
You can also add -f as an 'rm' argument so you don't get prompted for "Are you sure you want to remove X file?"
– UtahJarhead
Oct 2 '12 at 14:01
Which version ofgrep
has an-exec
switch?
– Ben Graham
Oct 3 '12 at 2:55
Why does this comment have downvotes?
– Ultrasonic54321
Jan 30 at 17:07
add a comment |
1
You can also add -f as an 'rm' argument so you don't get prompted for "Are you sure you want to remove X file?"
– UtahJarhead
Oct 2 '12 at 14:01
Which version ofgrep
has an-exec
switch?
– Ben Graham
Oct 3 '12 at 2:55
Why does this comment have downvotes?
– Ultrasonic54321
Jan 30 at 17:07
1
1
You can also add -f as an 'rm' argument so you don't get prompted for "Are you sure you want to remove X file?"
– UtahJarhead
Oct 2 '12 at 14:01
You can also add -f as an 'rm' argument so you don't get prompted for "Are you sure you want to remove X file?"
– UtahJarhead
Oct 2 '12 at 14:01
Which version of
grep
has an -exec
switch?– Ben Graham
Oct 3 '12 at 2:55
Which version of
grep
has an -exec
switch?– Ben Graham
Oct 3 '12 at 2:55
Why does this comment have downvotes?
– Ultrasonic54321
Jan 30 at 17:07
Why does this comment have downvotes?
– Ultrasonic54321
Jan 30 at 17:07
add a comment |
Delete all files in current directory and its sub-directories where the file name starts with "foo":
$ find . -type f -name foo* -exec rm {} ;
NB: use with caution - back up first - also do a dry run first, e.g.
$ find . -type f -name foo*
will just tell you the names of the files that would be deleted.
4
I had to delete over 2Million files and run in to trouble,find . -type f -name foo* -delete
did the trick
– Linas
Jan 25 '14 at 13:30
add a comment |
Delete all files in current directory and its sub-directories where the file name starts with "foo":
$ find . -type f -name foo* -exec rm {} ;
NB: use with caution - back up first - also do a dry run first, e.g.
$ find . -type f -name foo*
will just tell you the names of the files that would be deleted.
4
I had to delete over 2Million files and run in to trouble,find . -type f -name foo* -delete
did the trick
– Linas
Jan 25 '14 at 13:30
add a comment |
Delete all files in current directory and its sub-directories where the file name starts with "foo":
$ find . -type f -name foo* -exec rm {} ;
NB: use with caution - back up first - also do a dry run first, e.g.
$ find . -type f -name foo*
will just tell you the names of the files that would be deleted.
Delete all files in current directory and its sub-directories where the file name starts with "foo":
$ find . -type f -name foo* -exec rm {} ;
NB: use with caution - back up first - also do a dry run first, e.g.
$ find . -type f -name foo*
will just tell you the names of the files that would be deleted.
answered Oct 2 '12 at 12:19
Paul RPaul R
4,28611727
4,28611727
4
I had to delete over 2Million files and run in to trouble,find . -type f -name foo* -delete
did the trick
– Linas
Jan 25 '14 at 13:30
add a comment |
4
I had to delete over 2Million files and run in to trouble,find . -type f -name foo* -delete
did the trick
– Linas
Jan 25 '14 at 13:30
4
4
I had to delete over 2Million files and run in to trouble,
find . -type f -name foo* -delete
did the trick– Linas
Jan 25 '14 at 13:30
I had to delete over 2Million files and run in to trouble,
find . -type f -name foo* -delete
did the trick– Linas
Jan 25 '14 at 13:30
add a comment |
I have tried this way it is working for me try below command.
rm -rf Example*
here "Example" is text which is common for all files.
add a comment |
I have tried this way it is working for me try below command.
rm -rf Example*
here "Example" is text which is common for all files.
add a comment |
I have tried this way it is working for me try below command.
rm -rf Example*
here "Example" is text which is common for all files.
I have tried this way it is working for me try below command.
rm -rf Example*
here "Example" is text which is common for all files.
answered Jul 28 '16 at 10:51
Dinesh BhojvaniDinesh Bhojvani
24923
24923
add a comment |
add a comment |
You can use find
:
find . -name "name*" -exec rm {} ;
Also instead of specifying '.' you can specify an absolute path.
– UtahJarhead
Oct 2 '12 at 14:02
add a comment |
You can use find
:
find . -name "name*" -exec rm {} ;
Also instead of specifying '.' you can specify an absolute path.
– UtahJarhead
Oct 2 '12 at 14:02
add a comment |
You can use find
:
find . -name "name*" -exec rm {} ;
You can use find
:
find . -name "name*" -exec rm {} ;
answered Oct 2 '12 at 12:22
P.P.P.P.
45648
45648
Also instead of specifying '.' you can specify an absolute path.
– UtahJarhead
Oct 2 '12 at 14:02
add a comment |
Also instead of specifying '.' you can specify an absolute path.
– UtahJarhead
Oct 2 '12 at 14:02
Also instead of specifying '.' you can specify an absolute path.
– UtahJarhead
Oct 2 '12 at 14:02
Also instead of specifying '.' you can specify an absolute path.
– UtahJarhead
Oct 2 '12 at 14:02
add a comment |
With the globstar
option (enable with shopt -s globstar
):
rm -f **/NAME*
**/
expands to ./
, */
, */*/
, */*/*/
etc. If you have a directory name starting with NAME
, the command will complain that rm
can't remove directories, but that's all.
Notice that this might run into command line length limitations if the glob matches many files.
Alternatively, with as few invocations of rm
as possible, but not subject to any command line length limitations:
find . -type f -name 'NAME*' -exec rm -f {} +
(Notice the +
instead of ;
to close the -exec
statement.)
add a comment |
With the globstar
option (enable with shopt -s globstar
):
rm -f **/NAME*
**/
expands to ./
, */
, */*/
, */*/*/
etc. If you have a directory name starting with NAME
, the command will complain that rm
can't remove directories, but that's all.
Notice that this might run into command line length limitations if the glob matches many files.
Alternatively, with as few invocations of rm
as possible, but not subject to any command line length limitations:
find . -type f -name 'NAME*' -exec rm -f {} +
(Notice the +
instead of ;
to close the -exec
statement.)
add a comment |
With the globstar
option (enable with shopt -s globstar
):
rm -f **/NAME*
**/
expands to ./
, */
, */*/
, */*/*/
etc. If you have a directory name starting with NAME
, the command will complain that rm
can't remove directories, but that's all.
Notice that this might run into command line length limitations if the glob matches many files.
Alternatively, with as few invocations of rm
as possible, but not subject to any command line length limitations:
find . -type f -name 'NAME*' -exec rm -f {} +
(Notice the +
instead of ;
to close the -exec
statement.)
With the globstar
option (enable with shopt -s globstar
):
rm -f **/NAME*
**/
expands to ./
, */
, */*/
, */*/*/
etc. If you have a directory name starting with NAME
, the command will complain that rm
can't remove directories, but that's all.
Notice that this might run into command line length limitations if the glob matches many files.
Alternatively, with as few invocations of rm
as possible, but not subject to any command line length limitations:
find . -type f -name 'NAME*' -exec rm -f {} +
(Notice the +
instead of ;
to close the -exec
statement.)
edited Jan 30 at 17:05
answered Feb 24 '17 at 3:17
Benjamin W.Benjamin W.
17918
17918
add a comment |
add a comment |
find . -name 'foo'* -type f -delete
seems like the simplest answer.
You can run this without the -delete
flag before to see which files will be deleted.
add a comment |
find . -name 'foo'* -type f -delete
seems like the simplest answer.
You can run this without the -delete
flag before to see which files will be deleted.
add a comment |
find . -name 'foo'* -type f -delete
seems like the simplest answer.
You can run this without the -delete
flag before to see which files will be deleted.
find . -name 'foo'* -type f -delete
seems like the simplest answer.
You can run this without the -delete
flag before to see which files will be deleted.
answered Aug 27 '18 at 16:28
Yehuda SchwartzYehuda Schwartz
1212
1212
add a comment |
add a comment |
Search for the "Inode" number of the file/folder and then delete using inode number. Below is an example:
ls -il
3407873 drwxr-xr-x. 2 root root 4096 Mar 30 07:49 –p
find . -inum 3407873 -exec rm -rf {} ;
This is a good answer — to a different question. It’s not an answer to this question.
– Scott
Oct 26 '18 at 4:33
add a comment |
Search for the "Inode" number of the file/folder and then delete using inode number. Below is an example:
ls -il
3407873 drwxr-xr-x. 2 root root 4096 Mar 30 07:49 –p
find . -inum 3407873 -exec rm -rf {} ;
This is a good answer — to a different question. It’s not an answer to this question.
– Scott
Oct 26 '18 at 4:33
add a comment |
Search for the "Inode" number of the file/folder and then delete using inode number. Below is an example:
ls -il
3407873 drwxr-xr-x. 2 root root 4096 Mar 30 07:49 –p
find . -inum 3407873 -exec rm -rf {} ;
Search for the "Inode" number of the file/folder and then delete using inode number. Below is an example:
ls -il
3407873 drwxr-xr-x. 2 root root 4096 Mar 30 07:49 –p
find . -inum 3407873 -exec rm -rf {} ;
edited Mar 30 '15 at 6:12
bummi
1,48231422
1,48231422
answered Mar 30 '15 at 6:04
DiwaDiwa
52
52
This is a good answer — to a different question. It’s not an answer to this question.
– Scott
Oct 26 '18 at 4:33
add a comment |
This is a good answer — to a different question. It’s not an answer to this question.
– Scott
Oct 26 '18 at 4:33
This is a good answer — to a different question. It’s not an answer to this question.
– Scott
Oct 26 '18 at 4:33
This is a good answer — to a different question. It’s not an answer to this question.
– Scott
Oct 26 '18 at 4:33
add a comment |
Thanks for contributing an answer to Super User!
- 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%2fsuperuser.com%2fquestions%2f482435%2fhow-to-remove-all-files-starting-with-a-certain-string-in-linux%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