Move multiple files with same name in same directory
I have a directory with multiple files of same name.
Well, you shouldn't. How can you even cat
their contents? (that is, without getting only the first file of the same name each time).
How can I move all files to a new directory (/new) using mv ../new ls File.txt File.txt File1.txt
I'd settle for trying to give them different names:
mv File.txt ../new/File.txt.1
mv File.txt ../new/File.txt.2
and see if you end up with distinct files that way.
Update: The files are being FTPed to an UNIX directory by a source system, which needs to be processed using shell script.
This is overwhelmingly unlikely to result in a situation in which you have multiple files with the same name in the same directory. So don't sweat that case, I guess.
Related videos on Youtube
Dud
Updated on September 18, 2022Comments
-
Dud over 1 year
I have a directory with multiple files of same name.
../directory ls File.txt File.txt File1.txt
How can I move all files to a new directory (/new) using mv
../new ls File.txt File.txt File1.txt
Update: The files are being FTPed to an UNIX directory by a source system, which needs to be processed using shell script. Once done I need to move multiple instances of the same file (if any) to an Archive directory.
And by "processed" all I am doing is Copying it to one Dir. And Archive in another using MV. Using cp n mv only one instance of the file is being processed.
-
Dud over 7 yearsThanks @icarus. Have updated the description with a detailed scenario.
-
icarus over 7 yearsAh, so does this mean that you have a fixed name, e.g. results, which is being pushed in via FTP, and you need to move this to a variable filename like Archive/results.2016.11.27.1315 ?
-
Dud over 7 yearsYes. I need to handle multiple instances of the file (which does has a fixed name). Say suppose I have input.txt with 10 EMP details and I unable to process the data. When the next set of file comes with the same name, I am able to move only one file for processing. The most recent one.
-
icarus over 7 yearsBecause you have a fixed filename, the FTP process will overwrite the previous
input.txt
, so you will only have a single file calledinput.txt
at a time (which will be the most recent one).
-
-
Dud over 7 yearsThe files are being FTPed to an UNIX directory by a source system, which needs to be processed using shell script. Once done I need to move multiple instances of the same file (if any) to an Archive directory.
-
DepressedDaniel over 7 years@Dudul Please update your question with more details of this process.
-
Dud over 7 yearsThanks Daniel. I hope this makes it clearer. Should had put in the description.