Searching for files within subdirectories?
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I have a tree of parent folder and subfolders. The subdirectories have similar names. I would like to search for files stored in the sub-directories. How can I do that?
For example:
Parent-Directory
Sub-Directory 1
input save bad
Sub-Directory 2
input save bad
Sub-Directory 3
input save bad
Each of the sub-directories contain three folders named (input, save and bad). I only would like to search for files within the bad subdirectories.
grep solaris
add a comment |Â
up vote
0
down vote
favorite
I have a tree of parent folder and subfolders. The subdirectories have similar names. I would like to search for files stored in the sub-directories. How can I do that?
For example:
Parent-Directory
Sub-Directory 1
input save bad
Sub-Directory 2
input save bad
Sub-Directory 3
input save bad
Each of the sub-directories contain three folders named (input, save and bad). I only would like to search for files within the bad subdirectories.
grep solaris
2
Please update the question with information about what you want to search for in those directories.
â Kusalananda
Sep 19 at 12:08
2
Hi @James Hete. The question was not clear. I made few edits. Do you approve the revisions that I had made on the question? meaning are the edits correct and it really stands for the objective of the question? Kindly, what do you mean by "Main directory"? I assume it is the parent folder that include three sub folders? What are "input save bad" stands for ? are these files or sub-sub folders?
â Goro
Sep 19 at 13:11
Doesls */*/bad/
work to your satisfaction?
â DopeGhoti
Sep 19 at 16:13
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a tree of parent folder and subfolders. The subdirectories have similar names. I would like to search for files stored in the sub-directories. How can I do that?
For example:
Parent-Directory
Sub-Directory 1
input save bad
Sub-Directory 2
input save bad
Sub-Directory 3
input save bad
Each of the sub-directories contain three folders named (input, save and bad). I only would like to search for files within the bad subdirectories.
grep solaris
I have a tree of parent folder and subfolders. The subdirectories have similar names. I would like to search for files stored in the sub-directories. How can I do that?
For example:
Parent-Directory
Sub-Directory 1
input save bad
Sub-Directory 2
input save bad
Sub-Directory 3
input save bad
Each of the sub-directories contain three folders named (input, save and bad). I only would like to search for files within the bad subdirectories.
grep solaris
grep solaris
edited Sep 19 at 13:14
Goro
6,16652762
6,16652762
asked Sep 19 at 10:59
James Hete
1
1
2
Please update the question with information about what you want to search for in those directories.
â Kusalananda
Sep 19 at 12:08
2
Hi @James Hete. The question was not clear. I made few edits. Do you approve the revisions that I had made on the question? meaning are the edits correct and it really stands for the objective of the question? Kindly, what do you mean by "Main directory"? I assume it is the parent folder that include three sub folders? What are "input save bad" stands for ? are these files or sub-sub folders?
â Goro
Sep 19 at 13:11
Doesls */*/bad/
work to your satisfaction?
â DopeGhoti
Sep 19 at 16:13
add a comment |Â
2
Please update the question with information about what you want to search for in those directories.
â Kusalananda
Sep 19 at 12:08
2
Hi @James Hete. The question was not clear. I made few edits. Do you approve the revisions that I had made on the question? meaning are the edits correct and it really stands for the objective of the question? Kindly, what do you mean by "Main directory"? I assume it is the parent folder that include three sub folders? What are "input save bad" stands for ? are these files or sub-sub folders?
â Goro
Sep 19 at 13:11
Doesls */*/bad/
work to your satisfaction?
â DopeGhoti
Sep 19 at 16:13
2
2
Please update the question with information about what you want to search for in those directories.
â Kusalananda
Sep 19 at 12:08
Please update the question with information about what you want to search for in those directories.
â Kusalananda
Sep 19 at 12:08
2
2
Hi @James Hete. The question was not clear. I made few edits. Do you approve the revisions that I had made on the question? meaning are the edits correct and it really stands for the objective of the question? Kindly, what do you mean by "Main directory"? I assume it is the parent folder that include three sub folders? What are "input save bad" stands for ? are these files or sub-sub folders?
â Goro
Sep 19 at 13:11
Hi @James Hete. The question was not clear. I made few edits. Do you approve the revisions that I had made on the question? meaning are the edits correct and it really stands for the objective of the question? Kindly, what do you mean by "Main directory"? I assume it is the parent folder that include three sub folders? What are "input save bad" stands for ? are these files or sub-sub folders?
â Goro
Sep 19 at 13:11
Does
ls */*/bad/
work to your satisfaction?â DopeGhoti
Sep 19 at 16:13
Does
ls */*/bad/
work to your satisfaction?â DopeGhoti
Sep 19 at 16:13
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
3
down vote
Your question is not clear, but I assume you would like to find files in the subdirectory "BAD", you can run this command in the main directory:
find . -maxdepth 2 -type d -name "BAD"
or use
find . -name "*BAD*" -type f -o -name "*BAD*" -type d
explanation
the -o command ors the arguments after the filepath completely, such that find . -name "string" -type f -o -type d computes find . (-name "BAD" -type f) -o (-type d).
Most users prefer something that looks like:
find . -name "*BAD*" -type f -o -name "*BAD*" -type d
which computes as
find . (-name "*BAD*" -type f) -o (-name "*BAD*" -type d)
-name "BAD" searches for names that contain the string string anywhere in them
For simplicity:
find . -maxdepth 2 -o -name "*BAD*"
1
but what if "input" and "save" were also subdirectories? Nothing in the current answer limits the search to subdirectories named "BAD"
â Jeff Schaller
Sep 19 at 12:34
updadte the answer
â Shervan
Sep 19 at 12:38
2
Just a separate side note: if you feel a question isn't yet clear, the right thing to do is to ask for clarification. I know you're a few points short of the ability to comment on any post, so next-best would be to wait for others to request the clarification (or, more specifically, for the OP to edit in such clarification).
â Jeff Schaller
Sep 19 at 12:40
1
Understood! There's a lot to learn -- and I'm still learning! It just saves time and effort when we (ask) and answer questions that are clear and answerable.
â Jeff Schaller
Sep 19 at 12:43
1
I think your answer is on its way to being usable; it looks like the last sentence got cut off? I'd suggest using "BAD" instead of "string" so that it directly answers the OP. Also, it seems you're trying to find "files -or directories" whose name contains the string, in which case I'd suggest simplifying it by removing the -type tests.
â Jeff Schaller
Sep 19 at 12:56
 |Â
show 2 more comments
up vote
2
down vote
Assuming you want to do a recursive search using find
in each of the bad
directories that are a level below directory called Main Directory
:
find 'Main Directory'/*/bad ...rest of find options...
I've left the rest of the find
options out because you never say what you want to search for.
find
is able to take more than one directory as the starting point for its search. Here, we give it a filename globbing pattern that will be expanded by the shell to the paths of the various bad
directories.
Assuming you just want to print the pathnames of all the (regular) files in or beneath those directories:
find 'Main Directory'/*/bad -type f
If the bad
directories do not have any subdirectories that you need to look inside, and if the number of files that you need to process is not many thousands, you would be able to just use
'Main Directory'/*/bad/*
(where the final *
is assumed to match the filenames of the files you need to process) with whatever utility you need to use. For example, with ls
:
ls 'Main Directory'/*/bad/*
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
Your question is not clear, but I assume you would like to find files in the subdirectory "BAD", you can run this command in the main directory:
find . -maxdepth 2 -type d -name "BAD"
or use
find . -name "*BAD*" -type f -o -name "*BAD*" -type d
explanation
the -o command ors the arguments after the filepath completely, such that find . -name "string" -type f -o -type d computes find . (-name "BAD" -type f) -o (-type d).
Most users prefer something that looks like:
find . -name "*BAD*" -type f -o -name "*BAD*" -type d
which computes as
find . (-name "*BAD*" -type f) -o (-name "*BAD*" -type d)
-name "BAD" searches for names that contain the string string anywhere in them
For simplicity:
find . -maxdepth 2 -o -name "*BAD*"
1
but what if "input" and "save" were also subdirectories? Nothing in the current answer limits the search to subdirectories named "BAD"
â Jeff Schaller
Sep 19 at 12:34
updadte the answer
â Shervan
Sep 19 at 12:38
2
Just a separate side note: if you feel a question isn't yet clear, the right thing to do is to ask for clarification. I know you're a few points short of the ability to comment on any post, so next-best would be to wait for others to request the clarification (or, more specifically, for the OP to edit in such clarification).
â Jeff Schaller
Sep 19 at 12:40
1
Understood! There's a lot to learn -- and I'm still learning! It just saves time and effort when we (ask) and answer questions that are clear and answerable.
â Jeff Schaller
Sep 19 at 12:43
1
I think your answer is on its way to being usable; it looks like the last sentence got cut off? I'd suggest using "BAD" instead of "string" so that it directly answers the OP. Also, it seems you're trying to find "files -or directories" whose name contains the string, in which case I'd suggest simplifying it by removing the -type tests.
â Jeff Schaller
Sep 19 at 12:56
 |Â
show 2 more comments
up vote
3
down vote
Your question is not clear, but I assume you would like to find files in the subdirectory "BAD", you can run this command in the main directory:
find . -maxdepth 2 -type d -name "BAD"
or use
find . -name "*BAD*" -type f -o -name "*BAD*" -type d
explanation
the -o command ors the arguments after the filepath completely, such that find . -name "string" -type f -o -type d computes find . (-name "BAD" -type f) -o (-type d).
Most users prefer something that looks like:
find . -name "*BAD*" -type f -o -name "*BAD*" -type d
which computes as
find . (-name "*BAD*" -type f) -o (-name "*BAD*" -type d)
-name "BAD" searches for names that contain the string string anywhere in them
For simplicity:
find . -maxdepth 2 -o -name "*BAD*"
1
but what if "input" and "save" were also subdirectories? Nothing in the current answer limits the search to subdirectories named "BAD"
â Jeff Schaller
Sep 19 at 12:34
updadte the answer
â Shervan
Sep 19 at 12:38
2
Just a separate side note: if you feel a question isn't yet clear, the right thing to do is to ask for clarification. I know you're a few points short of the ability to comment on any post, so next-best would be to wait for others to request the clarification (or, more specifically, for the OP to edit in such clarification).
â Jeff Schaller
Sep 19 at 12:40
1
Understood! There's a lot to learn -- and I'm still learning! It just saves time and effort when we (ask) and answer questions that are clear and answerable.
â Jeff Schaller
Sep 19 at 12:43
1
I think your answer is on its way to being usable; it looks like the last sentence got cut off? I'd suggest using "BAD" instead of "string" so that it directly answers the OP. Also, it seems you're trying to find "files -or directories" whose name contains the string, in which case I'd suggest simplifying it by removing the -type tests.
â Jeff Schaller
Sep 19 at 12:56
 |Â
show 2 more comments
up vote
3
down vote
up vote
3
down vote
Your question is not clear, but I assume you would like to find files in the subdirectory "BAD", you can run this command in the main directory:
find . -maxdepth 2 -type d -name "BAD"
or use
find . -name "*BAD*" -type f -o -name "*BAD*" -type d
explanation
the -o command ors the arguments after the filepath completely, such that find . -name "string" -type f -o -type d computes find . (-name "BAD" -type f) -o (-type d).
Most users prefer something that looks like:
find . -name "*BAD*" -type f -o -name "*BAD*" -type d
which computes as
find . (-name "*BAD*" -type f) -o (-name "*BAD*" -type d)
-name "BAD" searches for names that contain the string string anywhere in them
For simplicity:
find . -maxdepth 2 -o -name "*BAD*"
Your question is not clear, but I assume you would like to find files in the subdirectory "BAD", you can run this command in the main directory:
find . -maxdepth 2 -type d -name "BAD"
or use
find . -name "*BAD*" -type f -o -name "*BAD*" -type d
explanation
the -o command ors the arguments after the filepath completely, such that find . -name "string" -type f -o -type d computes find . (-name "BAD" -type f) -o (-type d).
Most users prefer something that looks like:
find . -name "*BAD*" -type f -o -name "*BAD*" -type d
which computes as
find . (-name "*BAD*" -type f) -o (-name "*BAD*" -type d)
-name "BAD" searches for names that contain the string string anywhere in them
For simplicity:
find . -maxdepth 2 -o -name "*BAD*"
edited Sep 19 at 13:02
answered Sep 19 at 11:32
Shervan
1659
1659
1
but what if "input" and "save" were also subdirectories? Nothing in the current answer limits the search to subdirectories named "BAD"
â Jeff Schaller
Sep 19 at 12:34
updadte the answer
â Shervan
Sep 19 at 12:38
2
Just a separate side note: if you feel a question isn't yet clear, the right thing to do is to ask for clarification. I know you're a few points short of the ability to comment on any post, so next-best would be to wait for others to request the clarification (or, more specifically, for the OP to edit in such clarification).
â Jeff Schaller
Sep 19 at 12:40
1
Understood! There's a lot to learn -- and I'm still learning! It just saves time and effort when we (ask) and answer questions that are clear and answerable.
â Jeff Schaller
Sep 19 at 12:43
1
I think your answer is on its way to being usable; it looks like the last sentence got cut off? I'd suggest using "BAD" instead of "string" so that it directly answers the OP. Also, it seems you're trying to find "files -or directories" whose name contains the string, in which case I'd suggest simplifying it by removing the -type tests.
â Jeff Schaller
Sep 19 at 12:56
 |Â
show 2 more comments
1
but what if "input" and "save" were also subdirectories? Nothing in the current answer limits the search to subdirectories named "BAD"
â Jeff Schaller
Sep 19 at 12:34
updadte the answer
â Shervan
Sep 19 at 12:38
2
Just a separate side note: if you feel a question isn't yet clear, the right thing to do is to ask for clarification. I know you're a few points short of the ability to comment on any post, so next-best would be to wait for others to request the clarification (or, more specifically, for the OP to edit in such clarification).
â Jeff Schaller
Sep 19 at 12:40
1
Understood! There's a lot to learn -- and I'm still learning! It just saves time and effort when we (ask) and answer questions that are clear and answerable.
â Jeff Schaller
Sep 19 at 12:43
1
I think your answer is on its way to being usable; it looks like the last sentence got cut off? I'd suggest using "BAD" instead of "string" so that it directly answers the OP. Also, it seems you're trying to find "files -or directories" whose name contains the string, in which case I'd suggest simplifying it by removing the -type tests.
â Jeff Schaller
Sep 19 at 12:56
1
1
but what if "input" and "save" were also subdirectories? Nothing in the current answer limits the search to subdirectories named "BAD"
â Jeff Schaller
Sep 19 at 12:34
but what if "input" and "save" were also subdirectories? Nothing in the current answer limits the search to subdirectories named "BAD"
â Jeff Schaller
Sep 19 at 12:34
updadte the answer
â Shervan
Sep 19 at 12:38
updadte the answer
â Shervan
Sep 19 at 12:38
2
2
Just a separate side note: if you feel a question isn't yet clear, the right thing to do is to ask for clarification. I know you're a few points short of the ability to comment on any post, so next-best would be to wait for others to request the clarification (or, more specifically, for the OP to edit in such clarification).
â Jeff Schaller
Sep 19 at 12:40
Just a separate side note: if you feel a question isn't yet clear, the right thing to do is to ask for clarification. I know you're a few points short of the ability to comment on any post, so next-best would be to wait for others to request the clarification (or, more specifically, for the OP to edit in such clarification).
â Jeff Schaller
Sep 19 at 12:40
1
1
Understood! There's a lot to learn -- and I'm still learning! It just saves time and effort when we (ask) and answer questions that are clear and answerable.
â Jeff Schaller
Sep 19 at 12:43
Understood! There's a lot to learn -- and I'm still learning! It just saves time and effort when we (ask) and answer questions that are clear and answerable.
â Jeff Schaller
Sep 19 at 12:43
1
1
I think your answer is on its way to being usable; it looks like the last sentence got cut off? I'd suggest using "BAD" instead of "string" so that it directly answers the OP. Also, it seems you're trying to find "files -or directories" whose name contains the string, in which case I'd suggest simplifying it by removing the -type tests.
â Jeff Schaller
Sep 19 at 12:56
I think your answer is on its way to being usable; it looks like the last sentence got cut off? I'd suggest using "BAD" instead of "string" so that it directly answers the OP. Also, it seems you're trying to find "files -or directories" whose name contains the string, in which case I'd suggest simplifying it by removing the -type tests.
â Jeff Schaller
Sep 19 at 12:56
 |Â
show 2 more comments
up vote
2
down vote
Assuming you want to do a recursive search using find
in each of the bad
directories that are a level below directory called Main Directory
:
find 'Main Directory'/*/bad ...rest of find options...
I've left the rest of the find
options out because you never say what you want to search for.
find
is able to take more than one directory as the starting point for its search. Here, we give it a filename globbing pattern that will be expanded by the shell to the paths of the various bad
directories.
Assuming you just want to print the pathnames of all the (regular) files in or beneath those directories:
find 'Main Directory'/*/bad -type f
If the bad
directories do not have any subdirectories that you need to look inside, and if the number of files that you need to process is not many thousands, you would be able to just use
'Main Directory'/*/bad/*
(where the final *
is assumed to match the filenames of the files you need to process) with whatever utility you need to use. For example, with ls
:
ls 'Main Directory'/*/bad/*
add a comment |Â
up vote
2
down vote
Assuming you want to do a recursive search using find
in each of the bad
directories that are a level below directory called Main Directory
:
find 'Main Directory'/*/bad ...rest of find options...
I've left the rest of the find
options out because you never say what you want to search for.
find
is able to take more than one directory as the starting point for its search. Here, we give it a filename globbing pattern that will be expanded by the shell to the paths of the various bad
directories.
Assuming you just want to print the pathnames of all the (regular) files in or beneath those directories:
find 'Main Directory'/*/bad -type f
If the bad
directories do not have any subdirectories that you need to look inside, and if the number of files that you need to process is not many thousands, you would be able to just use
'Main Directory'/*/bad/*
(where the final *
is assumed to match the filenames of the files you need to process) with whatever utility you need to use. For example, with ls
:
ls 'Main Directory'/*/bad/*
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Assuming you want to do a recursive search using find
in each of the bad
directories that are a level below directory called Main Directory
:
find 'Main Directory'/*/bad ...rest of find options...
I've left the rest of the find
options out because you never say what you want to search for.
find
is able to take more than one directory as the starting point for its search. Here, we give it a filename globbing pattern that will be expanded by the shell to the paths of the various bad
directories.
Assuming you just want to print the pathnames of all the (regular) files in or beneath those directories:
find 'Main Directory'/*/bad -type f
If the bad
directories do not have any subdirectories that you need to look inside, and if the number of files that you need to process is not many thousands, you would be able to just use
'Main Directory'/*/bad/*
(where the final *
is assumed to match the filenames of the files you need to process) with whatever utility you need to use. For example, with ls
:
ls 'Main Directory'/*/bad/*
Assuming you want to do a recursive search using find
in each of the bad
directories that are a level below directory called Main Directory
:
find 'Main Directory'/*/bad ...rest of find options...
I've left the rest of the find
options out because you never say what you want to search for.
find
is able to take more than one directory as the starting point for its search. Here, we give it a filename globbing pattern that will be expanded by the shell to the paths of the various bad
directories.
Assuming you just want to print the pathnames of all the (regular) files in or beneath those directories:
find 'Main Directory'/*/bad -type f
If the bad
directories do not have any subdirectories that you need to look inside, and if the number of files that you need to process is not many thousands, you would be able to just use
'Main Directory'/*/bad/*
(where the final *
is assumed to match the filenames of the files you need to process) with whatever utility you need to use. For example, with ls
:
ls 'Main Directory'/*/bad/*
edited Sep 19 at 14:20
answered Sep 19 at 12:05
Kusalananda
108k14209332
108k14209332
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%2f469987%2fsearching-for-files-within-subdirectories%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
2
Please update the question with information about what you want to search for in those directories.
â Kusalananda
Sep 19 at 12:08
2
Hi @James Hete. The question was not clear. I made few edits. Do you approve the revisions that I had made on the question? meaning are the edits correct and it really stands for the objective of the question? Kindly, what do you mean by "Main directory"? I assume it is the parent folder that include three sub folders? What are "input save bad" stands for ? are these files or sub-sub folders?
â Goro
Sep 19 at 13:11
Does
ls */*/bad/
work to your satisfaction?â DopeGhoti
Sep 19 at 16:13