How do I show all the files in a directory with a name containing a number?
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
How do I show all the files in a directory with a name contain a number? I tried
ls [0-9] textfiles
(textfiles
) is my directory.
This is how my Linux pocket guide shows me. I am just trying to display all the files that contain a number in the name. I have actually tried about 20+ variations that I found in my book and online.
linux ls
New contributor
add a comment |Â
up vote
1
down vote
favorite
How do I show all the files in a directory with a name contain a number? I tried
ls [0-9] textfiles
(textfiles
) is my directory.
This is how my Linux pocket guide shows me. I am just trying to display all the files that contain a number in the name. I have actually tried about 20+ variations that I found in my book and online.
linux ls
New contributor
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
How do I show all the files in a directory with a name contain a number? I tried
ls [0-9] textfiles
(textfiles
) is my directory.
This is how my Linux pocket guide shows me. I am just trying to display all the files that contain a number in the name. I have actually tried about 20+ variations that I found in my book and online.
linux ls
New contributor
How do I show all the files in a directory with a name contain a number? I tried
ls [0-9] textfiles
(textfiles
) is my directory.
This is how my Linux pocket guide shows me. I am just trying to display all the files that contain a number in the name. I have actually tried about 20+ variations that I found in my book and online.
linux ls
linux ls
New contributor
New contributor
edited 3 hours ago
fixer1234
16.9k144176
16.9k144176
New contributor
asked 4 hours ago
StPatrick
61
61
New contributor
New contributor
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
4
down vote
You probably want something like
ls textfiles/*[0-9]*
or (if "textfiles
is my directory" means you're inside the directory):
ls *[0-9]*
Note these commands don't restrict themselves to regular files. Directories, symlinks, named pipes and other entries may match. In broad Unix context all these are "files" and such matching is done with respect to their names only. To tell regular files apart, you need another tool like find
.
I'm surprised any guide advised you ls [0-9] textfiles
as it makes little sense in the context of your question.
To decode *[0-9]*
refer to man 7 glob
or e.g. this article, Standard Wildcards (globbing patterns) section. It's worth noticing in the above cases it's the shell (not ls
!) that expands the given pattern.
Thank you. This worked great.
â StPatrick
3 hours ago
@StPatrick Please take our quick tour to learn what you can do with an answer that solves your problem.
â Kamil Maciorowski
3 hours ago
add a comment |Â
up vote
0
down vote
Find also works, and can display only files, for example in the current dir (.)
find . -type f -name *[0-9]*
It's recursive by default.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
You probably want something like
ls textfiles/*[0-9]*
or (if "textfiles
is my directory" means you're inside the directory):
ls *[0-9]*
Note these commands don't restrict themselves to regular files. Directories, symlinks, named pipes and other entries may match. In broad Unix context all these are "files" and such matching is done with respect to their names only. To tell regular files apart, you need another tool like find
.
I'm surprised any guide advised you ls [0-9] textfiles
as it makes little sense in the context of your question.
To decode *[0-9]*
refer to man 7 glob
or e.g. this article, Standard Wildcards (globbing patterns) section. It's worth noticing in the above cases it's the shell (not ls
!) that expands the given pattern.
Thank you. This worked great.
â StPatrick
3 hours ago
@StPatrick Please take our quick tour to learn what you can do with an answer that solves your problem.
â Kamil Maciorowski
3 hours ago
add a comment |Â
up vote
4
down vote
You probably want something like
ls textfiles/*[0-9]*
or (if "textfiles
is my directory" means you're inside the directory):
ls *[0-9]*
Note these commands don't restrict themselves to regular files. Directories, symlinks, named pipes and other entries may match. In broad Unix context all these are "files" and such matching is done with respect to their names only. To tell regular files apart, you need another tool like find
.
I'm surprised any guide advised you ls [0-9] textfiles
as it makes little sense in the context of your question.
To decode *[0-9]*
refer to man 7 glob
or e.g. this article, Standard Wildcards (globbing patterns) section. It's worth noticing in the above cases it's the shell (not ls
!) that expands the given pattern.
Thank you. This worked great.
â StPatrick
3 hours ago
@StPatrick Please take our quick tour to learn what you can do with an answer that solves your problem.
â Kamil Maciorowski
3 hours ago
add a comment |Â
up vote
4
down vote
up vote
4
down vote
You probably want something like
ls textfiles/*[0-9]*
or (if "textfiles
is my directory" means you're inside the directory):
ls *[0-9]*
Note these commands don't restrict themselves to regular files. Directories, symlinks, named pipes and other entries may match. In broad Unix context all these are "files" and such matching is done with respect to their names only. To tell regular files apart, you need another tool like find
.
I'm surprised any guide advised you ls [0-9] textfiles
as it makes little sense in the context of your question.
To decode *[0-9]*
refer to man 7 glob
or e.g. this article, Standard Wildcards (globbing patterns) section. It's worth noticing in the above cases it's the shell (not ls
!) that expands the given pattern.
You probably want something like
ls textfiles/*[0-9]*
or (if "textfiles
is my directory" means you're inside the directory):
ls *[0-9]*
Note these commands don't restrict themselves to regular files. Directories, symlinks, named pipes and other entries may match. In broad Unix context all these are "files" and such matching is done with respect to their names only. To tell regular files apart, you need another tool like find
.
I'm surprised any guide advised you ls [0-9] textfiles
as it makes little sense in the context of your question.
To decode *[0-9]*
refer to man 7 glob
or e.g. this article, Standard Wildcards (globbing patterns) section. It's worth noticing in the above cases it's the shell (not ls
!) that expands the given pattern.
edited 3 hours ago
answered 3 hours ago
Kamil Maciorowski
21.8k155072
21.8k155072
Thank you. This worked great.
â StPatrick
3 hours ago
@StPatrick Please take our quick tour to learn what you can do with an answer that solves your problem.
â Kamil Maciorowski
3 hours ago
add a comment |Â
Thank you. This worked great.
â StPatrick
3 hours ago
@StPatrick Please take our quick tour to learn what you can do with an answer that solves your problem.
â Kamil Maciorowski
3 hours ago
Thank you. This worked great.
â StPatrick
3 hours ago
Thank you. This worked great.
â StPatrick
3 hours ago
@StPatrick Please take our quick tour to learn what you can do with an answer that solves your problem.
â Kamil Maciorowski
3 hours ago
@StPatrick Please take our quick tour to learn what you can do with an answer that solves your problem.
â Kamil Maciorowski
3 hours ago
add a comment |Â
up vote
0
down vote
Find also works, and can display only files, for example in the current dir (.)
find . -type f -name *[0-9]*
It's recursive by default.
add a comment |Â
up vote
0
down vote
Find also works, and can display only files, for example in the current dir (.)
find . -type f -name *[0-9]*
It's recursive by default.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Find also works, and can display only files, for example in the current dir (.)
find . -type f -name *[0-9]*
It's recursive by default.
Find also works, and can display only files, for example in the current dir (.)
find . -type f -name *[0-9]*
It's recursive by default.
answered 11 mins ago
Xen2050
9,47931536
9,47931536
add a comment |Â
add a comment |Â
StPatrick is a new contributor. Be nice, and check out our Code of Conduct.
StPatrick is a new contributor. Be nice, and check out our Code of Conduct.
StPatrick is a new contributor. Be nice, and check out our Code of Conduct.
StPatrick is a new contributor. Be nice, and check out our Code of Conduct.
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%2fsuperuser.com%2fquestions%2f1369028%2fhow-do-i-show-all-the-files-in-a-directory-with-a-name-containing-a-number%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