From Social Sloth, 5 Months ago, written in Plain Text.
  1. i have this directory structure:
  2.  
  3. .
  4. └── a
  5.     ├── b
  6.     │   └── a
  7.     └── e
  8.         ├── d
  9.         └── e
  10.             └── a (is a file)
  11.  
  12. i want to rename directories with name a to test to get:
  13. .
  14. └── test
  15.     ├── b
  16.     │   └── test
  17.     └── e
  18.         ├── d
  19.         └── e
  20.             └── test (is a file)
  21.  
  22. with this command i can accomplish this: (but see below)
  23.  
  24. find . -name test-depth -exec sh -c 'x="{}";
  25. newname=$(echo $(dirname $(realpath "$x")));
  26. newname=$newname/a;
  27. mv "$x" "$newname"' \;
  28.  
  29. BUT i want to read the directory to rename and the new name throught user input but doesnt work because new_name variable inside for doesnt get the value user inputs: WHY??
  30.  
  31. echo directory
  32.        
  33. read directory
  34.        
  35. echo old_name
  36.        
  37. read old_name
  38.        
  39. echo new_name
  40.        
  41. read new_name
  42.  
  43. find $directory -name $old_name -depth -exec sh -c '
  44.  
  45.         x="{}";
  46.  
  47.         newfullname=$(echo $(dirname $(realpath "$x")));
  48.  
  49.         newfullname=$newfullname/"$new_name";
  50.         mv "$x" "$newfullname"' \; # important "' \;
  51. }
  52.  
captcha