Delete all directory that begin with a particular string
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
What command do I have to use to delete all directories that begin with "graphene-80"
What can I add to the "rm" command as option?
linux directory rm
add a comment |Â
up vote
2
down vote
favorite
What command do I have to use to delete all directories that begin with "graphene-80"
What can I add to the "rm" command as option?
linux directory rm
On the whole system or in a particular directory, or anywhere beneath a particular directory?
â Kusalananda
Feb 7 at 14:18
in the directory /tmp
â user1543915
Feb 7 at 14:22
Just empty directories, or the contents too?
â ilkkachu
Feb 7 at 15:50
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
What command do I have to use to delete all directories that begin with "graphene-80"
What can I add to the "rm" command as option?
linux directory rm
What command do I have to use to delete all directories that begin with "graphene-80"
What can I add to the "rm" command as option?
linux directory rm
edited Feb 7 at 14:24
Jeff Schaller
31.3k846105
31.3k846105
asked Feb 7 at 14:10
Thouraya
111
111
On the whole system or in a particular directory, or anywhere beneath a particular directory?
â Kusalananda
Feb 7 at 14:18
in the directory /tmp
â user1543915
Feb 7 at 14:22
Just empty directories, or the contents too?
â ilkkachu
Feb 7 at 15:50
add a comment |Â
On the whole system or in a particular directory, or anywhere beneath a particular directory?
â Kusalananda
Feb 7 at 14:18
in the directory /tmp
â user1543915
Feb 7 at 14:22
Just empty directories, or the contents too?
â ilkkachu
Feb 7 at 15:50
On the whole system or in a particular directory, or anywhere beneath a particular directory?
â Kusalananda
Feb 7 at 14:18
On the whole system or in a particular directory, or anywhere beneath a particular directory?
â Kusalananda
Feb 7 at 14:18
in the directory /tmp
â user1543915
Feb 7 at 14:22
in the directory /tmp
â user1543915
Feb 7 at 14:22
Just empty directories, or the contents too?
â ilkkachu
Feb 7 at 15:50
Just empty directories, or the contents too?
â ilkkachu
Feb 7 at 15:50
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
2
down vote
Using find command:
find /tmp -type d -name 'graphene-80*' -delete
Arguments used:
-type
to filter directory only and avoid finding files-name
to find file that match the pattern define between quotes-delete
to delete the result of the find command
EDIT:
cleaner with -delete
like shown in this post:
Find files matching template and remove
2
Use-depth
when deleting directories, orfind
may complain about "no such directory" when trying to process the directories it has just deleted. You should probably also use-type d
to be sure to not delete files.
â Kusalananda
Feb 7 at 14:19
Indeed, thanks.
â Kevin Lemaire
Feb 7 at 14:21
3
On Linux (as the Q is tagged),-delete
will add in-depth
for you.
â Jeff Schaller
Feb 7 at 14:22
find: warning: you have specified the -depth option after a non-option argument -type, but options are not positional (-depth affects tests specified before it as well as those specified after it). Please specify options before other arguments.
â user1543915
Feb 7 at 14:37
It's corrected.
â Kevin Lemaire
Feb 7 at 14:42
add a comment |Â
up vote
1
down vote
To delete the directories matching the pattern graphene-80*
directly under /tmp
, use
rm -rf /tmp/graphene-80*/
Here, the trailing /
ensures that only directories whose names match the graphene-80*
pattern are deleted, and not files etc.
To find the matching directories elsewhere under /tmp
and delete them wherever they may be (or to handle the case where there are too many matching names resulting in a too long command), use
find /tmp -depth -type d -name 'graphene-80*' -prune -exec rm -rf ';'
To additionally see the names of the directories as they are deleted, insert -print
before -exec
. Inserting -print
after -exec
will print the names of directories succesfully deleted.
find -delete
will only delete directories if they are empty. You'd probably want-name 'graphene-80*' -prune -exec rm -rf +
, or with-delete
, use some-path
approach to also delete the files inside those directories (note that -delete implies -depth)
â Stéphane Chazelas
Feb 8 at 11:03
You'd want to use-prune
as well to not descend into the directories you're going to delete anyway.
â Stéphane Chazelas
Feb 8 at 11:12
@StéphaneChazelas Thanks, I was mislead by Jeff's comment to another answer and assumed it worked the way I thought it would without testing.
â Kusalananda
Feb 8 at 11:12
You should choose between + and ;. Note that with +, -exec always returns true since the execution of the command is postponed (see alsorm -v
with some implementations to print deleted files)
â Stéphane Chazelas
Feb 8 at 11:14
@StéphaneChazelas Sorted. I have too much in my head today. I appreciate your input as always.
â Kusalananda
Feb 8 at 11:16
add a comment |Â
up vote
0
down vote
To remove just empty directories with names matching graphene-80*
, either
find /tmp -type d -name "graphene-80*" -exec rmdir +
or
find /tmp -type d -name "graphene-80*" -delete
(rmdir
and GNU find should give you errors for the nonempty ones.)
To remove the directories with their contents:
find /tmp -type d -name "graphene-80*" -exec rm -r ; -prune
(With -exec rm +
you may get errors from rm
if there are nested matching directories; and without -prune
, from find
since it tries to descend to the just-removed directories.)
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
Using find command:
find /tmp -type d -name 'graphene-80*' -delete
Arguments used:
-type
to filter directory only and avoid finding files-name
to find file that match the pattern define between quotes-delete
to delete the result of the find command
EDIT:
cleaner with -delete
like shown in this post:
Find files matching template and remove
2
Use-depth
when deleting directories, orfind
may complain about "no such directory" when trying to process the directories it has just deleted. You should probably also use-type d
to be sure to not delete files.
â Kusalananda
Feb 7 at 14:19
Indeed, thanks.
â Kevin Lemaire
Feb 7 at 14:21
3
On Linux (as the Q is tagged),-delete
will add in-depth
for you.
â Jeff Schaller
Feb 7 at 14:22
find: warning: you have specified the -depth option after a non-option argument -type, but options are not positional (-depth affects tests specified before it as well as those specified after it). Please specify options before other arguments.
â user1543915
Feb 7 at 14:37
It's corrected.
â Kevin Lemaire
Feb 7 at 14:42
add a comment |Â
up vote
2
down vote
Using find command:
find /tmp -type d -name 'graphene-80*' -delete
Arguments used:
-type
to filter directory only and avoid finding files-name
to find file that match the pattern define between quotes-delete
to delete the result of the find command
EDIT:
cleaner with -delete
like shown in this post:
Find files matching template and remove
2
Use-depth
when deleting directories, orfind
may complain about "no such directory" when trying to process the directories it has just deleted. You should probably also use-type d
to be sure to not delete files.
â Kusalananda
Feb 7 at 14:19
Indeed, thanks.
â Kevin Lemaire
Feb 7 at 14:21
3
On Linux (as the Q is tagged),-delete
will add in-depth
for you.
â Jeff Schaller
Feb 7 at 14:22
find: warning: you have specified the -depth option after a non-option argument -type, but options are not positional (-depth affects tests specified before it as well as those specified after it). Please specify options before other arguments.
â user1543915
Feb 7 at 14:37
It's corrected.
â Kevin Lemaire
Feb 7 at 14:42
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Using find command:
find /tmp -type d -name 'graphene-80*' -delete
Arguments used:
-type
to filter directory only and avoid finding files-name
to find file that match the pattern define between quotes-delete
to delete the result of the find command
EDIT:
cleaner with -delete
like shown in this post:
Find files matching template and remove
Using find command:
find /tmp -type d -name 'graphene-80*' -delete
Arguments used:
-type
to filter directory only and avoid finding files-name
to find file that match the pattern define between quotes-delete
to delete the result of the find command
EDIT:
cleaner with -delete
like shown in this post:
Find files matching template and remove
edited Feb 7 at 14:38
answered Feb 7 at 14:17
Kevin Lemaire
1,037421
1,037421
2
Use-depth
when deleting directories, orfind
may complain about "no such directory" when trying to process the directories it has just deleted. You should probably also use-type d
to be sure to not delete files.
â Kusalananda
Feb 7 at 14:19
Indeed, thanks.
â Kevin Lemaire
Feb 7 at 14:21
3
On Linux (as the Q is tagged),-delete
will add in-depth
for you.
â Jeff Schaller
Feb 7 at 14:22
find: warning: you have specified the -depth option after a non-option argument -type, but options are not positional (-depth affects tests specified before it as well as those specified after it). Please specify options before other arguments.
â user1543915
Feb 7 at 14:37
It's corrected.
â Kevin Lemaire
Feb 7 at 14:42
add a comment |Â
2
Use-depth
when deleting directories, orfind
may complain about "no such directory" when trying to process the directories it has just deleted. You should probably also use-type d
to be sure to not delete files.
â Kusalananda
Feb 7 at 14:19
Indeed, thanks.
â Kevin Lemaire
Feb 7 at 14:21
3
On Linux (as the Q is tagged),-delete
will add in-depth
for you.
â Jeff Schaller
Feb 7 at 14:22
find: warning: you have specified the -depth option after a non-option argument -type, but options are not positional (-depth affects tests specified before it as well as those specified after it). Please specify options before other arguments.
â user1543915
Feb 7 at 14:37
It's corrected.
â Kevin Lemaire
Feb 7 at 14:42
2
2
Use
-depth
when deleting directories, or find
may complain about "no such directory" when trying to process the directories it has just deleted. You should probably also use -type d
to be sure to not delete files.â Kusalananda
Feb 7 at 14:19
Use
-depth
when deleting directories, or find
may complain about "no such directory" when trying to process the directories it has just deleted. You should probably also use -type d
to be sure to not delete files.â Kusalananda
Feb 7 at 14:19
Indeed, thanks.
â Kevin Lemaire
Feb 7 at 14:21
Indeed, thanks.
â Kevin Lemaire
Feb 7 at 14:21
3
3
On Linux (as the Q is tagged),
-delete
will add in -depth
for you.â Jeff Schaller
Feb 7 at 14:22
On Linux (as the Q is tagged),
-delete
will add in -depth
for you.â Jeff Schaller
Feb 7 at 14:22
find: warning: you have specified the -depth option after a non-option argument -type, but options are not positional (-depth affects tests specified before it as well as those specified after it). Please specify options before other arguments.
â user1543915
Feb 7 at 14:37
find: warning: you have specified the -depth option after a non-option argument -type, but options are not positional (-depth affects tests specified before it as well as those specified after it). Please specify options before other arguments.
â user1543915
Feb 7 at 14:37
It's corrected.
â Kevin Lemaire
Feb 7 at 14:42
It's corrected.
â Kevin Lemaire
Feb 7 at 14:42
add a comment |Â
up vote
1
down vote
To delete the directories matching the pattern graphene-80*
directly under /tmp
, use
rm -rf /tmp/graphene-80*/
Here, the trailing /
ensures that only directories whose names match the graphene-80*
pattern are deleted, and not files etc.
To find the matching directories elsewhere under /tmp
and delete them wherever they may be (or to handle the case where there are too many matching names resulting in a too long command), use
find /tmp -depth -type d -name 'graphene-80*' -prune -exec rm -rf ';'
To additionally see the names of the directories as they are deleted, insert -print
before -exec
. Inserting -print
after -exec
will print the names of directories succesfully deleted.
find -delete
will only delete directories if they are empty. You'd probably want-name 'graphene-80*' -prune -exec rm -rf +
, or with-delete
, use some-path
approach to also delete the files inside those directories (note that -delete implies -depth)
â Stéphane Chazelas
Feb 8 at 11:03
You'd want to use-prune
as well to not descend into the directories you're going to delete anyway.
â Stéphane Chazelas
Feb 8 at 11:12
@StéphaneChazelas Thanks, I was mislead by Jeff's comment to another answer and assumed it worked the way I thought it would without testing.
â Kusalananda
Feb 8 at 11:12
You should choose between + and ;. Note that with +, -exec always returns true since the execution of the command is postponed (see alsorm -v
with some implementations to print deleted files)
â Stéphane Chazelas
Feb 8 at 11:14
@StéphaneChazelas Sorted. I have too much in my head today. I appreciate your input as always.
â Kusalananda
Feb 8 at 11:16
add a comment |Â
up vote
1
down vote
To delete the directories matching the pattern graphene-80*
directly under /tmp
, use
rm -rf /tmp/graphene-80*/
Here, the trailing /
ensures that only directories whose names match the graphene-80*
pattern are deleted, and not files etc.
To find the matching directories elsewhere under /tmp
and delete them wherever they may be (or to handle the case where there are too many matching names resulting in a too long command), use
find /tmp -depth -type d -name 'graphene-80*' -prune -exec rm -rf ';'
To additionally see the names of the directories as they are deleted, insert -print
before -exec
. Inserting -print
after -exec
will print the names of directories succesfully deleted.
find -delete
will only delete directories if they are empty. You'd probably want-name 'graphene-80*' -prune -exec rm -rf +
, or with-delete
, use some-path
approach to also delete the files inside those directories (note that -delete implies -depth)
â Stéphane Chazelas
Feb 8 at 11:03
You'd want to use-prune
as well to not descend into the directories you're going to delete anyway.
â Stéphane Chazelas
Feb 8 at 11:12
@StéphaneChazelas Thanks, I was mislead by Jeff's comment to another answer and assumed it worked the way I thought it would without testing.
â Kusalananda
Feb 8 at 11:12
You should choose between + and ;. Note that with +, -exec always returns true since the execution of the command is postponed (see alsorm -v
with some implementations to print deleted files)
â Stéphane Chazelas
Feb 8 at 11:14
@StéphaneChazelas Sorted. I have too much in my head today. I appreciate your input as always.
â Kusalananda
Feb 8 at 11:16
add a comment |Â
up vote
1
down vote
up vote
1
down vote
To delete the directories matching the pattern graphene-80*
directly under /tmp
, use
rm -rf /tmp/graphene-80*/
Here, the trailing /
ensures that only directories whose names match the graphene-80*
pattern are deleted, and not files etc.
To find the matching directories elsewhere under /tmp
and delete them wherever they may be (or to handle the case where there are too many matching names resulting in a too long command), use
find /tmp -depth -type d -name 'graphene-80*' -prune -exec rm -rf ';'
To additionally see the names of the directories as they are deleted, insert -print
before -exec
. Inserting -print
after -exec
will print the names of directories succesfully deleted.
To delete the directories matching the pattern graphene-80*
directly under /tmp
, use
rm -rf /tmp/graphene-80*/
Here, the trailing /
ensures that only directories whose names match the graphene-80*
pattern are deleted, and not files etc.
To find the matching directories elsewhere under /tmp
and delete them wherever they may be (or to handle the case where there are too many matching names resulting in a too long command), use
find /tmp -depth -type d -name 'graphene-80*' -prune -exec rm -rf ';'
To additionally see the names of the directories as they are deleted, insert -print
before -exec
. Inserting -print
after -exec
will print the names of directories succesfully deleted.
edited Feb 8 at 11:15
answered Feb 7 at 14:38
Kusalananda
103k13202318
103k13202318
find -delete
will only delete directories if they are empty. You'd probably want-name 'graphene-80*' -prune -exec rm -rf +
, or with-delete
, use some-path
approach to also delete the files inside those directories (note that -delete implies -depth)
â Stéphane Chazelas
Feb 8 at 11:03
You'd want to use-prune
as well to not descend into the directories you're going to delete anyway.
â Stéphane Chazelas
Feb 8 at 11:12
@StéphaneChazelas Thanks, I was mislead by Jeff's comment to another answer and assumed it worked the way I thought it would without testing.
â Kusalananda
Feb 8 at 11:12
You should choose between + and ;. Note that with +, -exec always returns true since the execution of the command is postponed (see alsorm -v
with some implementations to print deleted files)
â Stéphane Chazelas
Feb 8 at 11:14
@StéphaneChazelas Sorted. I have too much in my head today. I appreciate your input as always.
â Kusalananda
Feb 8 at 11:16
add a comment |Â
find -delete
will only delete directories if they are empty. You'd probably want-name 'graphene-80*' -prune -exec rm -rf +
, or with-delete
, use some-path
approach to also delete the files inside those directories (note that -delete implies -depth)
â Stéphane Chazelas
Feb 8 at 11:03
You'd want to use-prune
as well to not descend into the directories you're going to delete anyway.
â Stéphane Chazelas
Feb 8 at 11:12
@StéphaneChazelas Thanks, I was mislead by Jeff's comment to another answer and assumed it worked the way I thought it would without testing.
â Kusalananda
Feb 8 at 11:12
You should choose between + and ;. Note that with +, -exec always returns true since the execution of the command is postponed (see alsorm -v
with some implementations to print deleted files)
â Stéphane Chazelas
Feb 8 at 11:14
@StéphaneChazelas Sorted. I have too much in my head today. I appreciate your input as always.
â Kusalananda
Feb 8 at 11:16
find -delete
will only delete directories if they are empty. You'd probably want -name 'graphene-80*' -prune -exec rm -rf +
, or with -delete
, use some -path
approach to also delete the files inside those directories (note that -delete implies -depth)â Stéphane Chazelas
Feb 8 at 11:03
find -delete
will only delete directories if they are empty. You'd probably want -name 'graphene-80*' -prune -exec rm -rf +
, or with -delete
, use some -path
approach to also delete the files inside those directories (note that -delete implies -depth)â Stéphane Chazelas
Feb 8 at 11:03
You'd want to use
-prune
as well to not descend into the directories you're going to delete anyway.â Stéphane Chazelas
Feb 8 at 11:12
You'd want to use
-prune
as well to not descend into the directories you're going to delete anyway.â Stéphane Chazelas
Feb 8 at 11:12
@StéphaneChazelas Thanks, I was mislead by Jeff's comment to another answer and assumed it worked the way I thought it would without testing.
â Kusalananda
Feb 8 at 11:12
@StéphaneChazelas Thanks, I was mislead by Jeff's comment to another answer and assumed it worked the way I thought it would without testing.
â Kusalananda
Feb 8 at 11:12
You should choose between + and ;. Note that with +, -exec always returns true since the execution of the command is postponed (see also
rm -v
with some implementations to print deleted files)â Stéphane Chazelas
Feb 8 at 11:14
You should choose between + and ;. Note that with +, -exec always returns true since the execution of the command is postponed (see also
rm -v
with some implementations to print deleted files)â Stéphane Chazelas
Feb 8 at 11:14
@StéphaneChazelas Sorted. I have too much in my head today. I appreciate your input as always.
â Kusalananda
Feb 8 at 11:16
@StéphaneChazelas Sorted. I have too much in my head today. I appreciate your input as always.
â Kusalananda
Feb 8 at 11:16
add a comment |Â
up vote
0
down vote
To remove just empty directories with names matching graphene-80*
, either
find /tmp -type d -name "graphene-80*" -exec rmdir +
or
find /tmp -type d -name "graphene-80*" -delete
(rmdir
and GNU find should give you errors for the nonempty ones.)
To remove the directories with their contents:
find /tmp -type d -name "graphene-80*" -exec rm -r ; -prune
(With -exec rm +
you may get errors from rm
if there are nested matching directories; and without -prune
, from find
since it tries to descend to the just-removed directories.)
add a comment |Â
up vote
0
down vote
To remove just empty directories with names matching graphene-80*
, either
find /tmp -type d -name "graphene-80*" -exec rmdir +
or
find /tmp -type d -name "graphene-80*" -delete
(rmdir
and GNU find should give you errors for the nonempty ones.)
To remove the directories with their contents:
find /tmp -type d -name "graphene-80*" -exec rm -r ; -prune
(With -exec rm +
you may get errors from rm
if there are nested matching directories; and without -prune
, from find
since it tries to descend to the just-removed directories.)
add a comment |Â
up vote
0
down vote
up vote
0
down vote
To remove just empty directories with names matching graphene-80*
, either
find /tmp -type d -name "graphene-80*" -exec rmdir +
or
find /tmp -type d -name "graphene-80*" -delete
(rmdir
and GNU find should give you errors for the nonempty ones.)
To remove the directories with their contents:
find /tmp -type d -name "graphene-80*" -exec rm -r ; -prune
(With -exec rm +
you may get errors from rm
if there are nested matching directories; and without -prune
, from find
since it tries to descend to the just-removed directories.)
To remove just empty directories with names matching graphene-80*
, either
find /tmp -type d -name "graphene-80*" -exec rmdir +
or
find /tmp -type d -name "graphene-80*" -delete
(rmdir
and GNU find should give you errors for the nonempty ones.)
To remove the directories with their contents:
find /tmp -type d -name "graphene-80*" -exec rm -r ; -prune
(With -exec rm +
you may get errors from rm
if there are nested matching directories; and without -prune
, from find
since it tries to descend to the just-removed directories.)
edited Feb 7 at 16:23
answered Feb 7 at 15:59
ilkkachu
49.6k673137
49.6k673137
add a comment |Â
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f422548%2fdelete-all-directory-that-begin-with-a-particular-string%23new-answer', 'question_page');
);
Post as a guest
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
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
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
On the whole system or in a particular directory, or anywhere beneath a particular directory?
â Kusalananda
Feb 7 at 14:18
in the directory /tmp
â user1543915
Feb 7 at 14:22
Just empty directories, or the contents too?
â ilkkachu
Feb 7 at 15:50