Renaming files with its path name

filenamesrename

I have a .bdf file inside subfolders. All the .bdf have the same name: Loads.bdf

Example:

/home/user/folderxx/folderxxx/Load.bdf
/home/user/folderxx/folderxxx/Load.bdf

I need to find (and copy to a new folder) all Load.bdf files and rename them with its path name.

Example:
After the intended operation, it should show something like this.

folder001_folderAAA_Load.bdf
folder002_folderBBB_Load.bdf

Best Answer

I would use the mcp tool from the mmv ("multiple move") package for that:

mcp '/home/user/*/*/Load.bdf' '#1_#2_Load.bdf'

The #1, #2 etc. in the second string will be replaced by the contents of the corresponding 1st, 2nd etc. wildcard from the first string. Note that the path is in single quotes so that the wildcards are interpreted by mcp, not by the shell.

With the command shown, the files will be copied to the current directory. If you replace mcp with mmv, the files will be moved instead.

Related Question