Interactive solution in Linux: vidir
. See this answer of mine.
Sole vidir
doesn't descend into subdirectories. You need
find . | vidir -
or like
find . | EDITOR=kate vidir -
Then use the "search and replace" feature of your text editor to make the desired changes. Save the text file (do not change its name) and exit the editor. Done.
Note every file and directory has its own independent line. If you need to rename a directory named version2
to version3
, it's important to make the change in its line and in all the lines associated with its subdirectories and files within. If you miss just one object then you will end up with two directories: version2
and version3
(so there will be mkdir
involved). Make sure you are permitted to rename/move all objects you want to alter. Even if you get two directories in place of one, this can still be resolved by running vidir
again (although one of the directories may have wrong ownership/permissions because it's newly created).
A directory you want to rename should precede its content. Fortunately find .
works this way (unless one uses -depth
, so don't use -depth
).
On the other hand if vidir
doesn't list any deeper content (e.g. you used find
with -maxdepth
) then you don't need to worry about it. Renaming a directory whose content is not on the list will work as if you used mv
.
In any case it's relatively easy to make changes you ask for. Many depends on the chosen editor: searching with regex, highlighting changes, undoing – features like these may get handy.
I find vidir
useful in cases like yours mainly because it allows me to make sure the resulting paths are really what I want, before any renaming/moving occurs. If I mess anything up, I can abort without saving changes.
Test the solution and get familiar with the tool by working on some expendable directory first. Notice what happens when there's a name conflict. Experiment and adjust the approach to your needs.
2Note that there are two different
rename
commands with totally different meaning of the arguments. – choroba – 2017-09-14T07:40:18.203what if it is only part of the file name. i.e. "JS-sample2.txt" to "patient1-sample2.txt" – Kirt – 2017-09-14T19:38:43.440