How to write a script/command line that runs through multiple sub-directories?
Hello!
I am currently trying to write a command/script that goes thought multiple directories and execute the same file conversion command. The data structure is as follow: The main directory, raw-data, contains 100 sub-directories (100 subjects folders), each with three sub-directories, the last of which contains the files I am trying to convert (raw-data/subj001/023/12/3) I face the following problem. The package I am currently using sends output only to the working directory. Therefore, I was hoping that I could get some help with what to include in a command line or a script that would continuously change the working directory so that the output of each subject will be send back to the same directory the input came from. I came up with something like this: find . -mindepth 4 -type d -exec tractor -d -r -b preproc RunStages:1 Interactive:FALSE'{}' \; I don`t have much linux scripting experience so your help will be much appreciated. |
Since you want to change to the directory you might want to do a for loop:
find . -mindepth 4 -type d -exec tractor -d -r -b preproc RunStages:1 Interactive:FALSE'{}' \; for dir in $(find . -mindepth 4 -type d) do echo DIRECTORY is $dir cd $dir tractor -d -r -b preproc RunStages:1 Interactive:FALSE done The above would show you what directory it found then cd to that directory then run your tractor command. Since I'm not familiar with the command "tractor" I'm not sure what it expects. Do you give it the directory name or the names of the files in the directory? You may need to add the directory name (e.g. "./" or "$(PWD)) to your command and/or the file spec (e.g. if all files it might be $(PWD)/*). |
I believe this will work.
Code:
find `pwd` -mindepth 4 -type d | xargs -I {} bash -c 'cd {}; tractor -d -r -b preproc RunStages:1 Interactive:FALSE;' To break it down: Code:
find `pwd` -mindepth 4 -type d Code:
| xargs -I {} Code:
bash -c Code:
'cd {}; tractor -d -r -b preproc RunStages:1 Interactive:FALSE;' |
Quote:
|
Quote:
|
All times are GMT -5. The time now is 06:14 AM. |