1

I have a main directory called like "Experiment", where I keep several subfolders like "time_data", then several subfolders "bacterial_strain"and in the end "drug concentration" that is written like "0,5 mM". So the final path is:

/Experiment/time_data/bacterial_strain/0,5 mM

I want to rename all the directories in all subdirectories from "0,5 mM" to "0,7 mM"

I tried to run several different pipelines as:

find . -type d | grep 0,5 | mv "0,5 mM/" "0,7 mM/"

or

grep -r "0,5 mM" "/path_to_Experiment_folder" | mv 0,5\ mM 0,7\ mM

But Terminal gives the same mistake:

mv: rename 0,5 mM to 0,7 mM: No such file or directory

Please, help me, how to change the pipeline in order to do that?

makkreker
  • 31
  • 6

3 Answers3

2

You can try something like this:

find . -depth -type d -name "0,5mM*" -exec mv {} 
Experiment/time_data/bacterial_strain/drug_concentration/0,7mM \;

Things worth noting:

  1. I noted that your last subfolder name contains a space 0,5 mM. find command using space and executing an -exec mv with space did not work for me. I am not sure why. For testing purpose I removed the space character and the above command works, also its a single like command which I just separated for visibility, I am sure that will be figured out, but nevertheless ;).
  2. I have used the entire path to rename the last file 0,5mM. I supposed all your directories depths are the same, if not then you can probably explore the -depth option a little further.
  3. If you have different depths directories or different names to rename, you can also encapsulate the above command in a script and run it on the parent directory.

I hope this works for you.

Hemang
  • 390
  • 3
  • 20
0

This should work:

$ find . -type d -name 0,5\ mM -print | while read dir ; do mv -v "${dir}" "${dir/0,5/0,7}" ; done
mauro
  • 5,730
  • 2
  • 26
  • 25
0

Another way is:

for f in Experiment/*/*/0,5\ mM; do nf=$(dirname "$f")/0,7\ mM; mv "$f" "$nf"; done

or (if you have also files with '0,5 mM' name which you do not want to rename):

for f in Experiment/*/*/0,5\ mM; do if [ -d "$f" ]; then nf=$(dirname "$f")/0,7\ mM; mv "$f" "$nf"; fi; done

Here you can find other ways to do this.

Community
  • 1
  • 1
boorg
  • 146
  • 4