Find statement for multiple folder names
Through other posts, I think I'll finally be able to knock out a problem I'm having if someone can help me tweak a find statement, as I only know how to do very simple ones.
right now i'm doing a find . -type d -iname "z*" to find all folders who's name starts with z or Z. Is there a way I could with one command find all folders who's name starts with the letters M through Z, without having to do the same command over and over and just changing the letter each time? |
for loop will help you. some docs: http://tldp.org/LDP/abs/html/
|
I kind get what the for loop would do, like automate the switching of the letters. But can I do it right in that find command somehow too?
|
i don't remember if you can do it in the find command, and don't forget for is command, too. actually for ia a command, find is an awesome program.
|
I tried reading the for loop stuff, and I definitely think that's over my head. Perhaps I'd be better just manually doing it for each letter.
|
it's easier than you think but scripting specially bash scripting is annoying thing to learn.
|
I'll have to read up on it when I get some time. good to know that such a thing exists, luckily there aren't that many letter in the alphabet so I'll do this one by hand for now.
|
Code:
bash-3.1# find / -type d -regextype posix-awk -iregex .*/x* |
Thanks, i'll use it as an example once i read up on for loops
|
Code:
find -iname [m-z]\* -type d |
Quote:
|
Quote:
Otherwise the shell would interpret it, and you may end up with fewer hits than you were after, or an error message, depending on how many directories in the current working directory match [m-z]*. Here's an example from a tmp-directory ... Code:
$ ls -p |
Thanks for providing the examples, it makes sense now, and even shows why I need to do [m-z] rather than [mz]. I'd rather learn with guidance than just get an answer than no feedback as to why that solves my problem, you would never learn that way. Appreciate the time Tinkster!
|
Most welcome. Just trying to live up to the statement in my sig :}
|
@GrapefruiTgirl: that's probably because '*' in most regex engines means zero or more instances of the preceding character ...
;) |
All times are GMT -5. The time now is 07:44 AM. |