how do I display file names that contain two characters and one of them is c?
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I tried doing ls [a-z][a-z]
but it doesn't seem to be working.
linux bash shell filenames command
add a comment |Â
up vote
2
down vote
favorite
I tried doing ls [a-z][a-z]
but it doesn't seem to be working.
linux bash shell filenames command
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I tried doing ls [a-z][a-z]
but it doesn't seem to be working.
linux bash shell filenames command
I tried doing ls [a-z][a-z]
but it doesn't seem to be working.
linux bash shell filenames command
linux bash shell filenames command
edited 25 mins ago
Jeff Schaller
33.5k850112
33.5k850112
asked 30 mins ago
amendeep singh
233
233
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
6
down vote
accepted
With bash, set the glob settings so that missing matches don't trigger an error:
shopt -u failglob # missing matches are just dropped
shopt -s nullglob # missing matches don't report a failure
ls ?c c?
Question-mark is a glob character representing a single character. Since you want two-character filenames, one of them has to be a c
, and so it's either the first character or the last character.
With shopt -s dotglob
this would also surface a file named .c
.
If there are no matching files, setting these shell options causes all of the arguments to be removed, resulting in a bare ls
-- listing anything/everything by default.
Use this, instead:
shopt -s nullglob ## drop any missing globs
set -- ?c c? ## populate the $@ array with (any) matches
if [ $# -gt 0 ] ## if there are some, list them
ls -d "$@"
fi
You may also want to usenullglob
?
â Kusalananda
19 mins ago
and failglob; thanks, @Kusalananda!
â Jeff Schaller
16 mins ago
thanks that was what i needed
â amendeep singh
15 mins ago
erm, not quite -- failglob removes the error but also removes everything (thus listing everything) if there are no matches
â Jeff Schaller
15 mins ago
add a comment |Â
up vote
3
down vote
Try this
ls -d c?
or
ls -d ?c
Use the ? wildcard for file globbing, it represent the number of characters you want to search for. Change c position whether at beginning or at end.
The -d flag will prevent ls
displaying the content of subdirectories that match the pattern.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
6
down vote
accepted
With bash, set the glob settings so that missing matches don't trigger an error:
shopt -u failglob # missing matches are just dropped
shopt -s nullglob # missing matches don't report a failure
ls ?c c?
Question-mark is a glob character representing a single character. Since you want two-character filenames, one of them has to be a c
, and so it's either the first character or the last character.
With shopt -s dotglob
this would also surface a file named .c
.
If there are no matching files, setting these shell options causes all of the arguments to be removed, resulting in a bare ls
-- listing anything/everything by default.
Use this, instead:
shopt -s nullglob ## drop any missing globs
set -- ?c c? ## populate the $@ array with (any) matches
if [ $# -gt 0 ] ## if there are some, list them
ls -d "$@"
fi
You may also want to usenullglob
?
â Kusalananda
19 mins ago
and failglob; thanks, @Kusalananda!
â Jeff Schaller
16 mins ago
thanks that was what i needed
â amendeep singh
15 mins ago
erm, not quite -- failglob removes the error but also removes everything (thus listing everything) if there are no matches
â Jeff Schaller
15 mins ago
add a comment |Â
up vote
6
down vote
accepted
With bash, set the glob settings so that missing matches don't trigger an error:
shopt -u failglob # missing matches are just dropped
shopt -s nullglob # missing matches don't report a failure
ls ?c c?
Question-mark is a glob character representing a single character. Since you want two-character filenames, one of them has to be a c
, and so it's either the first character or the last character.
With shopt -s dotglob
this would also surface a file named .c
.
If there are no matching files, setting these shell options causes all of the arguments to be removed, resulting in a bare ls
-- listing anything/everything by default.
Use this, instead:
shopt -s nullglob ## drop any missing globs
set -- ?c c? ## populate the $@ array with (any) matches
if [ $# -gt 0 ] ## if there are some, list them
ls -d "$@"
fi
You may also want to usenullglob
?
â Kusalananda
19 mins ago
and failglob; thanks, @Kusalananda!
â Jeff Schaller
16 mins ago
thanks that was what i needed
â amendeep singh
15 mins ago
erm, not quite -- failglob removes the error but also removes everything (thus listing everything) if there are no matches
â Jeff Schaller
15 mins ago
add a comment |Â
up vote
6
down vote
accepted
up vote
6
down vote
accepted
With bash, set the glob settings so that missing matches don't trigger an error:
shopt -u failglob # missing matches are just dropped
shopt -s nullglob # missing matches don't report a failure
ls ?c c?
Question-mark is a glob character representing a single character. Since you want two-character filenames, one of them has to be a c
, and so it's either the first character or the last character.
With shopt -s dotglob
this would also surface a file named .c
.
If there are no matching files, setting these shell options causes all of the arguments to be removed, resulting in a bare ls
-- listing anything/everything by default.
Use this, instead:
shopt -s nullglob ## drop any missing globs
set -- ?c c? ## populate the $@ array with (any) matches
if [ $# -gt 0 ] ## if there are some, list them
ls -d "$@"
fi
With bash, set the glob settings so that missing matches don't trigger an error:
shopt -u failglob # missing matches are just dropped
shopt -s nullglob # missing matches don't report a failure
ls ?c c?
Question-mark is a glob character representing a single character. Since you want two-character filenames, one of them has to be a c
, and so it's either the first character or the last character.
With shopt -s dotglob
this would also surface a file named .c
.
If there are no matching files, setting these shell options causes all of the arguments to be removed, resulting in a bare ls
-- listing anything/everything by default.
Use this, instead:
shopt -s nullglob ## drop any missing globs
set -- ?c c? ## populate the $@ array with (any) matches
if [ $# -gt 0 ] ## if there are some, list them
ls -d "$@"
fi
edited 10 mins ago
answered 23 mins ago
Jeff Schaller
33.5k850112
33.5k850112
You may also want to usenullglob
?
â Kusalananda
19 mins ago
and failglob; thanks, @Kusalananda!
â Jeff Schaller
16 mins ago
thanks that was what i needed
â amendeep singh
15 mins ago
erm, not quite -- failglob removes the error but also removes everything (thus listing everything) if there are no matches
â Jeff Schaller
15 mins ago
add a comment |Â
You may also want to usenullglob
?
â Kusalananda
19 mins ago
and failglob; thanks, @Kusalananda!
â Jeff Schaller
16 mins ago
thanks that was what i needed
â amendeep singh
15 mins ago
erm, not quite -- failglob removes the error but also removes everything (thus listing everything) if there are no matches
â Jeff Schaller
15 mins ago
You may also want to use
nullglob
?â Kusalananda
19 mins ago
You may also want to use
nullglob
?â Kusalananda
19 mins ago
and failglob; thanks, @Kusalananda!
â Jeff Schaller
16 mins ago
and failglob; thanks, @Kusalananda!
â Jeff Schaller
16 mins ago
thanks that was what i needed
â amendeep singh
15 mins ago
thanks that was what i needed
â amendeep singh
15 mins ago
erm, not quite -- failglob removes the error but also removes everything (thus listing everything) if there are no matches
â Jeff Schaller
15 mins ago
erm, not quite -- failglob removes the error but also removes everything (thus listing everything) if there are no matches
â Jeff Schaller
15 mins ago
add a comment |Â
up vote
3
down vote
Try this
ls -d c?
or
ls -d ?c
Use the ? wildcard for file globbing, it represent the number of characters you want to search for. Change c position whether at beginning or at end.
The -d flag will prevent ls
displaying the content of subdirectories that match the pattern.
add a comment |Â
up vote
3
down vote
Try this
ls -d c?
or
ls -d ?c
Use the ? wildcard for file globbing, it represent the number of characters you want to search for. Change c position whether at beginning or at end.
The -d flag will prevent ls
displaying the content of subdirectories that match the pattern.
add a comment |Â
up vote
3
down vote
up vote
3
down vote
Try this
ls -d c?
or
ls -d ?c
Use the ? wildcard for file globbing, it represent the number of characters you want to search for. Change c position whether at beginning or at end.
The -d flag will prevent ls
displaying the content of subdirectories that match the pattern.
Try this
ls -d c?
or
ls -d ?c
Use the ? wildcard for file globbing, it represent the number of characters you want to search for. Change c position whether at beginning or at end.
The -d flag will prevent ls
displaying the content of subdirectories that match the pattern.
answered 23 mins ago
Goro
6,61052865
6,61052865
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%2f473511%2fhow-do-i-display-file-names-that-contain-two-characters-and-one-of-them-is-c%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