I want to rename file name with its parent folder name, adding the folder name before the current name.
for example:
Folder structure
SOCH NC KT 633-ROYAL BLUE-MULTI
|
| 1.jpg
|
| 2.jpg
|
| 3.jpg
Expected Result
SOCH NC KT 633-ROYAL BLUE-MULTI
|
|_SOCH NC KT 633-ROYAL BLUE-MULTI1.jpg
|
|_SOCH NC KT 633-ROYAL BLUE-MULTI2.jpg
|
|_SOCH NC KT 633-ROYAL BLUE-MULTI3.jpg
SOCH NC KT 710-BLACK-MULTI
Could anyone advise how this can be done in a .sh file? Is there any utility is available to do the operation?
find . -mindepth 2 -maxdepth 2 -type f -exec rename -n 's/(.*)\//$1\/$1/' {} \;
instead. This is adapted from https://askubuntu.com/a/1081902/301745 – wjandrea Oct 08 '18 at 13:54|
(pipe), to avoid escaping slashes:'s|(.*)/|$1/$1|'
– wjandrea Oct 08 '18 at 14:01