Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a requirement where I need to validate the nested folder structure.

Ex: I have 3 folders: test1, test2, test3 (Practically there can be anynumber of such folders). Now all these folders should contain folder like V1, V2... like that ('V' followed by number). Under this folder (V1... ), there should be only two folders names 'dummy1' and 'dummy2'.

So all these checks should be done recursively until all the folders like test 1... test2... Are checked.

share|improve this question
add comment

4 Answers

You could use the find command. Find recurses through a directory structure doing things to each file/directory. You can limit it to directories with the -type flag.

find start_dir -type d -print

To actually validate all have the structure I think you are going to have to write a script looking at this list - and I think you would have to do this in a more powerful scripting language than shell e.g. perl, python, ruby, tcl.

share|improve this answer
    
I agree but the requirement is on shell script only...if possible can you please tell me ...after finding the directory how to use the cd command recursively on that –  Ankit Apr 18 '11 at 10:50
    
This command will list all the directories so no need to recurse any more. You then need to process the output - why only a shell script as that is an artifical limit - any more than two lines in shell I write in something else. –  Mark Apr 18 '11 at 11:01
    
will you be able to help me on this by writng it on another scripting tool..provided i will be able to execute it on putty.. –  Ankit Apr 18 '11 at 11:09
add comment

Another option is the simple tree command.

Just do

tree directory/

then 'validate' the output of that.

share|improve this answer
    
can you please tell me on how to validate that recursively...as i need to have a shell script which will take care of all this in one shot. –  Ankit Apr 18 '11 at 10:56
    
Oh, then I guess a bunch of bash "for loops" with varying tests is what you want if you want the validation done automatically. I don't know how stringent you want things though? Can test1 ONLY contain V{1..X} or is a file 'readme.txt' in there also permissable etc. etc.? –  PriceChild Apr 18 '11 at 11:15
    
well it will contain only V(1..X) –  Ankit Apr 18 '11 at 11:26
    
But then what about consecutive numbers... can you have V1, V2, V5, V9000 etc. ? I don't like your question I'm afraid, it isn't really a question but a request for us to do your work and write you a script. Using standard bash loops like 'for' and 'if' should make this reasonably easy. –  PriceChild Apr 18 '11 at 11:42
add comment

Try using the below command:

find . -name dummy1 -exec echo "Hello, '{}'" \;
find . -name dummy2 -exec echo "Hello, '{}'" \;

this gives the output along with the PWD.

share|improve this answer
add comment

positive test:

find test* -maxdepth 1 -type d -regex ".*/V[0-9]+" 
find test* -mindepth 2 -maxdepth 2 -type d -regex ".*/V[0-9]+/dummy[12]" 

negative test:

find test* -maxdepth 1 -type d -not -regex ".*/V[0-9]+" 
find test* -mindepth 2 -maxdepth 2 -type d -not -regex ".*/V[0-9]+/dummy[12]" 
share|improve this answer
    
thanks a lot for your help..it worked that way....what if i want to store this results in a file... thanks ANkit –  Ankit Apr 19 '11 at 7:25
    
find test* -maxdepth 1 -type d -regex ".*/V[0-9]+" > list1 –  user unknown Apr 19 '11 at 13:41
    
yeah i did the same thing some thing like find test* -maxdepth 1 -type d -regex ".*/V[0-9]+" -print > filename..... –  Ankit Apr 20 '11 at 5:42
    
thanks for your help... –  Ankit Apr 20 '11 at 5:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.