0

I want to rename file name with it’s parent folder name, adding folder name before file name.

Folder Structure:

1

A.jpg
B.jpg
C.jpg

2

A.jpg
B.jpg
C.jpg

Expected results:

1

1A.jpg
1B.jpg
1C.jpg

2

2A.jpg
2B.jpg
2C.jpg

How can this be done with Unix?

1
  • What did you try so far? Commented Nov 8, 2023 at 17:15

1 Answer 1

1

In the zsh shell (available on most Unices since 1991, though zmv was only added in 2000):

autoload -Uz zmv
zmv '(*)/(*.jpg)' '$1/$1$2'
2
  • It renamed the files but put all files in folder 1. Can it keep files in their individual folders after renaming? Commented Nov 8, 2023 at 18:39
  • My mistake. Actually is does keep them in folders. This is exactly what I needed. Thank You! Commented Nov 8, 2023 at 20:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .