I’m not entirely sure how to word the question but I want to pass a file argument in terminal that will search a directory and every possible subdirectory working it’s way through the whole file tree. At the moment, I’m passing ~/Classes/**/*
but I’m not sure that is working correctly
Asked
Active
Viewed 429 times
0

Killian
- 936
- 3
- 14
- 28
-
What do you want to find? Files with a specific name? Directories with a specific name? Files containing something? – Mark Setchell Aug 07 '14 at 09:36
-
Sorry, I should have said, the file tree is for an iOS app, but all it contains are folders and then obj-c files, so I'm basically looking for anything that is a file and not a directory – Killian Aug 07 '14 at 09:38
-
possible duplicate of [How to count all the lines of code in a directory recursively?](http://stackoverflow.com/questions/1358540/how-to-count-all-the-lines-of-code-in-a-directory-recursively) – tripleee Aug 07 '14 at 09:43
-
Not an excellent duplicate but you should easily find hundreds of similar questions. – tripleee Aug 07 '14 at 09:43
-
How would I pass this search as an argument in a command like this? `java -jar ~/Downloads/simian-2.3.35/bin/simian-2.3.35.jar files ~/Classes/**/* ` – Killian Aug 07 '14 at 09:46
2 Answers
0
Use find -type d
:
find ~Classes -type d
If ~
represents the home directory, you have to add an extra slash (/
) on it.
find ~/Classes -type d
If using bash, you'd need to enable globstar
and add /
to target directories:
shopt -s globstar
printf '%s\n' ~/Classes/**/*/

konsolebox
- 72,135
- 12
- 99
- 105
-
Given the additional comment just now, you should have `-type f` instead. – tripleee Aug 07 '14 at 09:39
-
-
I'm not sure does this work when passing it into what I'm trying to do. I'm trying to run simian, a CPD detector on my project so the overall command I'm running is `java -jar ~/Downloads/simian-2.3.35/bin/simian-2.3.35.jar files ~/Classes/**/* `. This seems to be going to the first level of subdirectories, but I'm trying to get it to search all of them – Killian Aug 07 '14 at 09:42
-
@Killian Did you enable `globstar`? Unfortunately the solution could also match directories. If you're sure about using it, and that you're really using bash and can enable globstar, I'd make updates. Anyway as first step, please try enabling `globstar` first as I instructed. – konsolebox Aug 07 '14 at 09:58
0
If you want to run this:
java -jar ~/Downloads/simian-2.3.35/bin/simian-2.3.35.jar files ~/Classes/**/*
you can do this:
java -jar ~/Downloads/simian-2.3.35/bin/simian-2.3.35.jar files $(find ....)
Original Answer
Basically use the find
command:
find ~/Classes -type f # find, starting in your "Classes" directory, all files
find ~ -type f # find, starting in your HOME directory, all files
find ~ -type d # find, starting in your HOME directory, all directories
find ~ -name "*fred*" -type f # find all files whose name contains "fred" anywhere in them
find ~ -iname "*FRED*" -type f # find all files whose name contains "fred" or "FRED" or "Fred" anywhere in them

Mark Setchell
- 191,897
- 31
- 273
- 432
-
How would I pass this search as an argument in a command like this? `java -jar ~/Downloads/simian-2.3.35/bin/simian-2.3.35.jar files ~/Classes/**/*` – Killian Aug 07 '14 at 09:58
-
Put the command I suggested inside `$()`. I have amended my answer. – Mark Setchell Aug 07 '14 at 09:59