Script to open all subdirectories of a single directory and then run a command (help)
Just as the title says, I am trying to write a very simple script that will go to every subdirectory of a single directory and run a command (lets call it make_ndx).
I know I can write this the long way with in a text document with something like: cd /"the directory"/"the 1st subdirectory" make_ndx cd .. cd "the 2nd subdirectory" cd .. Alternatively, I also tried: for i in 'find /path/somemorepath -type d -mindepth 1'; do cd $i; make_ndx -f *.gro; done which returns me with the error cd: find: no such file or directory. But if I run the find command by itself to test if I am calling the right directories, it gives me the exactly the output I am looking for. Any ideas? Should I just write the find results to a file and loop through the contents of the file (which seems a little bit like overkill) or am I just making a simple typographical mistake and I am just not seeing it? Any and all help is great. Thanks. Thanks for the help. |
backticks (not single quotes)"
Code:
for i in `find /path/somemorepath -type d -mindepth 1`; do cd $i; make_ndx -f *.gro; done |
Try changing cd $i to echo cd $i to see what find is generating.
In case find gives directories with whitespace characters in the name it is safer to use cd "$i" than cd $i. |
Quote:
The backtick is easily confused with a single quote". |
Thanks that fixed the problem.
As a follow-up, not that I have this working, I want to look into just one subdirectory whose name is repeated within the set of subdirectories...ok this is kind of convoluted so maybe I'll put it this way: I am interested in looking at only a set of subdirectories with the same name (i.e. I have a set of directories that have another set of directories in them with the same name. Like a set of directories that are months, and then inside of them there are directories called days and I only want to look at day 30 of every month) I try a simple script: for i in `find /year/ -type d -mindepth 1`; do; if [ $i = "30"]; then; command_of_some_sort; fi; done Any ideas? Thanks for all of your help |
[untested]
Code:
find . -type d -mindepth 1 -name 30 -exec cd '{}' \; |
I would also add that unless make_ndx is creating / referencing files in the directory you are in, you do not
need to change into the directory. |
Hi Euler2,
Check out the following link..... http://www.linuxquestions.org/questi...-error-789971/ Hope this helps |
All times are GMT -5. The time now is 04:16 PM. |