I am quite new at using Linux and the terminal and I am stuck with something.
I have about 50 parent folders, all containing subfolders. One subfolder is called filtered_feature_bc_matrix. In an other subfolder, there are some .mtx or .tsv files, that I would like to move in the filtered_feature_bc_matrix subfolder.
So my architecture is like that
Mother_folder(containing all the 50 parent folders) ->
parent_folder
->filtered_feature_bc_matrix
->other_subfolder
->other_subsubfolder
files.mtx
I tried:
for dir in ./; do
$(find . -type f -name *.mtx -exec mv {} "./$dir/filtered_feature_bc_matrix" \;);
done
I succeed if I cd inside the parent folder, but I have 50 of them, so I would like to understand how to automate this task.
But I cannot specify the target directory properly, and that drives me crazy ;-)
I hope I am clear!
Camille
Edit:
And when I execute the code, I have the file matrix.mtx actually moved not in the subfolder I want, but in the mother_folder and renames filtered_feature_bc_matrix...
-name *.mtxwill expand to all files in the current directory that match this glob, you probably want-name '*.mtx'to prevent that.$()is also unneccesary, as will try to execute whatever is returned as a command.find ., butfind "$dir"instead. I recommend using shellcheck.net