I have multiple subdirectories inside a directory and each of them contains a file with the same name (but different contents). I wish to copy all these files of the same name into a destination directory such that they each have a unique name. The unique names can be differentiated with timestamp, or the directory name can be appended to each file name.
Example:
File 1: A/abc.txt
File 2: B/abc.txt
File 3: C/abc.txt
The destination folder is R
, and it should result in something like this after the copy:
R: A_abc.txt B_abc.txt C_abc.txt
I have tried several variations of the following command but cannot seem to get to the required output:
find . -maxdepth 2 -name '*.txt' -exec cp {} ../R/ ;
Please suggest an approach.
Dhriti Khanna is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.