Using regex for locate and grep to get only folders
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
When I try to search using locate
and grep
something like:
locate A-B | grep .dir
The result is:
.../A-B-C.dir
.../A-B-C.dir/file
.../A-B-C.dir/file1
.../A-B-D.dir
.../A-B-D.dir/file1
...
How to modify grep
or locate
to make the search finished with .dir
and nothing more?
I have quite old system:
Secure Locate 2.7 - Released January 24, 2003
grep (GNU grep) 2.5.1
linux grep regular-expression locate
add a comment |Â
up vote
0
down vote
favorite
When I try to search using locate
and grep
something like:
locate A-B | grep .dir
The result is:
.../A-B-C.dir
.../A-B-C.dir/file
.../A-B-C.dir/file1
.../A-B-D.dir
.../A-B-D.dir/file1
...
How to modify grep
or locate
to make the search finished with .dir
and nothing more?
I have quite old system:
Secure Locate 2.7 - Released January 24, 2003
grep (GNU grep) 2.5.1
linux grep regular-expression locate
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
When I try to search using locate
and grep
something like:
locate A-B | grep .dir
The result is:
.../A-B-C.dir
.../A-B-C.dir/file
.../A-B-C.dir/file1
.../A-B-D.dir
.../A-B-D.dir/file1
...
How to modify grep
or locate
to make the search finished with .dir
and nothing more?
I have quite old system:
Secure Locate 2.7 - Released January 24, 2003
grep (GNU grep) 2.5.1
linux grep regular-expression locate
When I try to search using locate
and grep
something like:
locate A-B | grep .dir
The result is:
.../A-B-C.dir
.../A-B-C.dir/file
.../A-B-C.dir/file1
.../A-B-D.dir
.../A-B-D.dir/file1
...
How to modify grep
or locate
to make the search finished with .dir
and nothing more?
I have quite old system:
Secure Locate 2.7 - Released January 24, 2003
grep (GNU grep) 2.5.1
linux grep regular-expression locate
edited Mar 23 at 15:47
asked Mar 23 at 15:28
XuMuK
34
34
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
If this is a Linux system, then chances are that you locate
supports regular expressions:
locate --regex 'A-B.*.dir$'
If not,
locate 'A-B' | grep '.dir$'
The main point is to anchor the regular expression to the end of the line properly with $
.
Note that both of these variations would also find e.g. /some/path/ABBA-Bootlegs/thing.dir
.
The second option is working. The first results empty line.
â XuMuK
Mar 23 at 15:38
@XuMuK It may be that yourlocate
does not support the--regex
flag then (see the manual on your system).
â Kusalananda
Mar 23 at 15:40
according toman locate
it should work with regex.
â XuMuK
Mar 23 at 15:47
It's easier with the default wildcards anyway:locate '*A-B*.dir'
â Stéphane Chazelas
Mar 23 at 16:32
@StéphaneChazelas in my caseSecure Locate 2.7 - Released January 24, 2003
this is not working. The Linux is too old, but it is impossible to update it.
â XuMuK
Mar 23 at 18:32
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
If this is a Linux system, then chances are that you locate
supports regular expressions:
locate --regex 'A-B.*.dir$'
If not,
locate 'A-B' | grep '.dir$'
The main point is to anchor the regular expression to the end of the line properly with $
.
Note that both of these variations would also find e.g. /some/path/ABBA-Bootlegs/thing.dir
.
The second option is working. The first results empty line.
â XuMuK
Mar 23 at 15:38
@XuMuK It may be that yourlocate
does not support the--regex
flag then (see the manual on your system).
â Kusalananda
Mar 23 at 15:40
according toman locate
it should work with regex.
â XuMuK
Mar 23 at 15:47
It's easier with the default wildcards anyway:locate '*A-B*.dir'
â Stéphane Chazelas
Mar 23 at 16:32
@StéphaneChazelas in my caseSecure Locate 2.7 - Released January 24, 2003
this is not working. The Linux is too old, but it is impossible to update it.
â XuMuK
Mar 23 at 18:32
add a comment |Â
up vote
1
down vote
accepted
If this is a Linux system, then chances are that you locate
supports regular expressions:
locate --regex 'A-B.*.dir$'
If not,
locate 'A-B' | grep '.dir$'
The main point is to anchor the regular expression to the end of the line properly with $
.
Note that both of these variations would also find e.g. /some/path/ABBA-Bootlegs/thing.dir
.
The second option is working. The first results empty line.
â XuMuK
Mar 23 at 15:38
@XuMuK It may be that yourlocate
does not support the--regex
flag then (see the manual on your system).
â Kusalananda
Mar 23 at 15:40
according toman locate
it should work with regex.
â XuMuK
Mar 23 at 15:47
It's easier with the default wildcards anyway:locate '*A-B*.dir'
â Stéphane Chazelas
Mar 23 at 16:32
@StéphaneChazelas in my caseSecure Locate 2.7 - Released January 24, 2003
this is not working. The Linux is too old, but it is impossible to update it.
â XuMuK
Mar 23 at 18:32
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
If this is a Linux system, then chances are that you locate
supports regular expressions:
locate --regex 'A-B.*.dir$'
If not,
locate 'A-B' | grep '.dir$'
The main point is to anchor the regular expression to the end of the line properly with $
.
Note that both of these variations would also find e.g. /some/path/ABBA-Bootlegs/thing.dir
.
If this is a Linux system, then chances are that you locate
supports regular expressions:
locate --regex 'A-B.*.dir$'
If not,
locate 'A-B' | grep '.dir$'
The main point is to anchor the regular expression to the end of the line properly with $
.
Note that both of these variations would also find e.g. /some/path/ABBA-Bootlegs/thing.dir
.
answered Mar 23 at 15:32
Kusalananda
102k13201317
102k13201317
The second option is working. The first results empty line.
â XuMuK
Mar 23 at 15:38
@XuMuK It may be that yourlocate
does not support the--regex
flag then (see the manual on your system).
â Kusalananda
Mar 23 at 15:40
according toman locate
it should work with regex.
â XuMuK
Mar 23 at 15:47
It's easier with the default wildcards anyway:locate '*A-B*.dir'
â Stéphane Chazelas
Mar 23 at 16:32
@StéphaneChazelas in my caseSecure Locate 2.7 - Released January 24, 2003
this is not working. The Linux is too old, but it is impossible to update it.
â XuMuK
Mar 23 at 18:32
add a comment |Â
The second option is working. The first results empty line.
â XuMuK
Mar 23 at 15:38
@XuMuK It may be that yourlocate
does not support the--regex
flag then (see the manual on your system).
â Kusalananda
Mar 23 at 15:40
according toman locate
it should work with regex.
â XuMuK
Mar 23 at 15:47
It's easier with the default wildcards anyway:locate '*A-B*.dir'
â Stéphane Chazelas
Mar 23 at 16:32
@StéphaneChazelas in my caseSecure Locate 2.7 - Released January 24, 2003
this is not working. The Linux is too old, but it is impossible to update it.
â XuMuK
Mar 23 at 18:32
The second option is working. The first results empty line.
â XuMuK
Mar 23 at 15:38
The second option is working. The first results empty line.
â XuMuK
Mar 23 at 15:38
@XuMuK It may be that your
locate
does not support the --regex
flag then (see the manual on your system).â Kusalananda
Mar 23 at 15:40
@XuMuK It may be that your
locate
does not support the --regex
flag then (see the manual on your system).â Kusalananda
Mar 23 at 15:40
according to
man locate
it should work with regex.â XuMuK
Mar 23 at 15:47
according to
man locate
it should work with regex.â XuMuK
Mar 23 at 15:47
It's easier with the default wildcards anyway:
locate '*A-B*.dir'
â Stéphane Chazelas
Mar 23 at 16:32
It's easier with the default wildcards anyway:
locate '*A-B*.dir'
â Stéphane Chazelas
Mar 23 at 16:32
@StéphaneChazelas in my case
Secure Locate 2.7 - Released January 24, 2003
this is not working. The Linux is too old, but it is impossible to update it.â XuMuK
Mar 23 at 18:32
@StéphaneChazelas in my case
Secure Locate 2.7 - Released January 24, 2003
this is not working. The Linux is too old, but it is impossible to update it.â XuMuK
Mar 23 at 18:32
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%2f433092%2fusing-regex-for-locate-and-grep-to-get-only-folders%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