How do I match only dotfiles in bash?
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
rm -rf .*
will only not end horribly because rm
refuses to delete .
and ..
.
How do I exclude these special directories from a glob pattern?
This is not solved by dotglob
since I want to match only files beginning with a dot not all files.
bash wildcards dot-files
add a comment |Â
up vote
3
down vote
favorite
rm -rf .*
will only not end horribly because rm
refuses to delete .
and ..
.
How do I exclude these special directories from a glob pattern?
This is not solved by dotglob
since I want to match only files beginning with a dot not all files.
bash wildcards dot-files
1
History: unix.stackexchange.com/a/90075/117549
– Jeff Schaller
21 mins ago
Possible duplicate of grep ignores files starting with dot
– Jeff Schaller
18 mins ago
@JeffSchaller, doesn't that one ask for all files, which is easily accomplished withdotglob
? Here, they just want those starting with a dot.
– ilkkachu
13 mins ago
Stéphane’s answer in it: unix.stackexchange.com/a/264571/117549
– Jeff Schaller
9 mins ago
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
rm -rf .*
will only not end horribly because rm
refuses to delete .
and ..
.
How do I exclude these special directories from a glob pattern?
This is not solved by dotglob
since I want to match only files beginning with a dot not all files.
bash wildcards dot-files
rm -rf .*
will only not end horribly because rm
refuses to delete .
and ..
.
How do I exclude these special directories from a glob pattern?
This is not solved by dotglob
since I want to match only files beginning with a dot not all files.
bash wildcards dot-files
bash wildcards dot-files
edited 24 mins ago


Ipor Sircer
9,5791920
9,5791920
asked 28 mins ago


Franklin
1233
1233
1
History: unix.stackexchange.com/a/90075/117549
– Jeff Schaller
21 mins ago
Possible duplicate of grep ignores files starting with dot
– Jeff Schaller
18 mins ago
@JeffSchaller, doesn't that one ask for all files, which is easily accomplished withdotglob
? Here, they just want those starting with a dot.
– ilkkachu
13 mins ago
Stéphane’s answer in it: unix.stackexchange.com/a/264571/117549
– Jeff Schaller
9 mins ago
add a comment |Â
1
History: unix.stackexchange.com/a/90075/117549
– Jeff Schaller
21 mins ago
Possible duplicate of grep ignores files starting with dot
– Jeff Schaller
18 mins ago
@JeffSchaller, doesn't that one ask for all files, which is easily accomplished withdotglob
? Here, they just want those starting with a dot.
– ilkkachu
13 mins ago
Stéphane’s answer in it: unix.stackexchange.com/a/264571/117549
– Jeff Schaller
9 mins ago
1
1
History: unix.stackexchange.com/a/90075/117549
– Jeff Schaller
21 mins ago
History: unix.stackexchange.com/a/90075/117549
– Jeff Schaller
21 mins ago
Possible duplicate of grep ignores files starting with dot
– Jeff Schaller
18 mins ago
Possible duplicate of grep ignores files starting with dot
– Jeff Schaller
18 mins ago
@JeffSchaller, doesn't that one ask for all files, which is easily accomplished with
dotglob
? Here, they just want those starting with a dot.– ilkkachu
13 mins ago
@JeffSchaller, doesn't that one ask for all files, which is easily accomplished with
dotglob
? Here, they just want those starting with a dot.– ilkkachu
13 mins ago
Stéphane’s answer in it: unix.stackexchange.com/a/264571/117549
– Jeff Schaller
9 mins ago
Stéphane’s answer in it: unix.stackexchange.com/a/264571/117549
– Jeff Schaller
9 mins ago
add a comment |Â
4 Answers
4
active
oldest
votes
up vote
4
down vote
This should do it:
rm -rf .[^.] .??*
This command can catch all cases.
.[^.]
will catch any two character entries. .??*
will only match 3+ character filenames.
add a comment |Â
up vote
0
down vote
You need to exclude single and double dots:
rm -rf ..?,.[!.]*
..?*
matches everything with two dots followed by anything.[!.]*
matches everything with single dot not followed by another dot
add a comment |Â
up vote
0
down vote
With extglob
:
$ shopt -s extglob
$ touch ... .a .bbb ..c foo
$ echo .!(.|)
... .a .bbb ..c
!(.|)
matches anything but a dot or empty, so .!(.|)
matches anything starting with a dot, except .
and ..
.
add a comment |Â
up vote
0
down vote
@Goro has, I think, the simplest totally correct answer. However, I find it's a pain to type. I would suggest instead
ls .??*
It's absolutely true that this will miss files like .a
, but those are so extraordinarily rare that in practice I don't think it matters, especially for interactive usage.
add a comment |Â
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
This should do it:
rm -rf .[^.] .??*
This command can catch all cases.
.[^.]
will catch any two character entries. .??*
will only match 3+ character filenames.
add a comment |Â
up vote
4
down vote
This should do it:
rm -rf .[^.] .??*
This command can catch all cases.
.[^.]
will catch any two character entries. .??*
will only match 3+ character filenames.
add a comment |Â
up vote
4
down vote
up vote
4
down vote
This should do it:
rm -rf .[^.] .??*
This command can catch all cases.
.[^.]
will catch any two character entries. .??*
will only match 3+ character filenames.
This should do it:
rm -rf .[^.] .??*
This command can catch all cases.
.[^.]
will catch any two character entries. .??*
will only match 3+ character filenames.
answered 23 mins ago
Goro
10.2k64993
10.2k64993
add a comment |Â
add a comment |Â
up vote
0
down vote
You need to exclude single and double dots:
rm -rf ..?,.[!.]*
..?*
matches everything with two dots followed by anything.[!.]*
matches everything with single dot not followed by another dot
add a comment |Â
up vote
0
down vote
You need to exclude single and double dots:
rm -rf ..?,.[!.]*
..?*
matches everything with two dots followed by anything.[!.]*
matches everything with single dot not followed by another dot
add a comment |Â
up vote
0
down vote
up vote
0
down vote
You need to exclude single and double dots:
rm -rf ..?,.[!.]*
..?*
matches everything with two dots followed by anything.[!.]*
matches everything with single dot not followed by another dot
You need to exclude single and double dots:
rm -rf ..?,.[!.]*
..?*
matches everything with two dots followed by anything.[!.]*
matches everything with single dot not followed by another dot
answered 22 mins ago
jimmij
29.6k867102
29.6k867102
add a comment |Â
add a comment |Â
up vote
0
down vote
With extglob
:
$ shopt -s extglob
$ touch ... .a .bbb ..c foo
$ echo .!(.|)
... .a .bbb ..c
!(.|)
matches anything but a dot or empty, so .!(.|)
matches anything starting with a dot, except .
and ..
.
add a comment |Â
up vote
0
down vote
With extglob
:
$ shopt -s extglob
$ touch ... .a .bbb ..c foo
$ echo .!(.|)
... .a .bbb ..c
!(.|)
matches anything but a dot or empty, so .!(.|)
matches anything starting with a dot, except .
and ..
.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
With extglob
:
$ shopt -s extglob
$ touch ... .a .bbb ..c foo
$ echo .!(.|)
... .a .bbb ..c
!(.|)
matches anything but a dot or empty, so .!(.|)
matches anything starting with a dot, except .
and ..
.
With extglob
:
$ shopt -s extglob
$ touch ... .a .bbb ..c foo
$ echo .!(.|)
... .a .bbb ..c
!(.|)
matches anything but a dot or empty, so .!(.|)
matches anything starting with a dot, except .
and ..
.
answered 18 mins ago


ilkkachu
52.9k680145
52.9k680145
add a comment |Â
add a comment |Â
up vote
0
down vote
@Goro has, I think, the simplest totally correct answer. However, I find it's a pain to type. I would suggest instead
ls .??*
It's absolutely true that this will miss files like .a
, but those are so extraordinarily rare that in practice I don't think it matters, especially for interactive usage.
add a comment |Â
up vote
0
down vote
@Goro has, I think, the simplest totally correct answer. However, I find it's a pain to type. I would suggest instead
ls .??*
It's absolutely true that this will miss files like .a
, but those are so extraordinarily rare that in practice I don't think it matters, especially for interactive usage.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
@Goro has, I think, the simplest totally correct answer. However, I find it's a pain to type. I would suggest instead
ls .??*
It's absolutely true that this will miss files like .a
, but those are so extraordinarily rare that in practice I don't think it matters, especially for interactive usage.
@Goro has, I think, the simplest totally correct answer. However, I find it's a pain to type. I would suggest instead
ls .??*
It's absolutely true that this will miss files like .a
, but those are so extraordinarily rare that in practice I don't think it matters, especially for interactive usage.
answered 2 mins ago
Dale Hagglund
31612
31612
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%2f476245%2fhow-do-i-match-only-dotfiles-in-bash%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
1
History: unix.stackexchange.com/a/90075/117549
– Jeff Schaller
21 mins ago
Possible duplicate of grep ignores files starting with dot
– Jeff Schaller
18 mins ago
@JeffSchaller, doesn't that one ask for all files, which is easily accomplished with
dotglob
? Here, they just want those starting with a dot.– ilkkachu
13 mins ago
Stéphane’s answer in it: unix.stackexchange.com/a/264571/117549
– Jeff Schaller
9 mins ago