Let's say, under this directory:
/home/data/
There are 100 folders, the name of these folders are 24538_7#1
, 24538_7#2
, 24538_7#3
... to 24538_7#384
.
In each folder, there are many files and folders.
The names of the desired file in each folder is Aligned.out.sam
The desired folder for renamed files is /home/SAM
How can I copy all these files to the new folder(/home/SAM
) and rename them properly as 24538_7#1.sam
, 24538_7#2.sam
, 24538_7#3.sam
......?
I tried doing it by the command below but it didn't work:
mv /home/data/*/Aligned.out.sam /home/SAM/*.sam
*.sam
in the target. If there are no files in the target directory, a file called*.sam
will be created there and each source file will overwrite it in turn. With anmv
command this means that you will lose all your files apart from the last. If a.sam
file exists in the target directory, each source file will overwrite it, as before. If multiple.sam
files exist in the target directory, then all the source files and all the target files except the last will overwrite the last, so you will also lose existing.sam
files in the target, apart from the second last.*
won't work in the second invocation in that command, as bash has no idea you want each name on the left side to be the same as on the right side. Using a variable in a loop allows you to say "for each directory, copy the file and rename it to match the originating directory".mv
command too, but it didn't work.