Linux commandline add map structure as prefix to files.
Hello,
I am trying to get the grasp of linux commandline, but this problem I just can't solve. I would like to merge multiple folders, possibly containing files that may cause duplicate names, into one. To prevent dupes, I would like to have part of the map structure prepended to the file names. At least, that seemed the most obvious solution. So I would like: ./map1/a.dat ~> ./map1_a.dat ./map1/b.dat ~> ./map1_b.dat ./map2/a.dat ~> ./map2_a.dat (no duplicate filename :)) and trivially: ./a.dat -> ./a.dat and so on, for all maps within ./ . How should i go about this? ~ Boomhenk |
I will direct you to the "find" command first. This will list the files (as a path name). Be sure to only look for regular files.
Next, the output of that will be files like ./map/a.dat. (you can avoid the leading ./ if you specify map as the directory to process). This can be piped to a loop to process each name - replacing the "/" with a "_", you now have the original name, and the replacement; at which point you can use the mv <orginalname> <replacementname>... If you use the mv command, the directory tree processed will be empty of anything except other directories. |
All times are GMT -5. The time now is 10:05 PM. |