ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am trying to run a copy command and getting this error.
The issue is I do not know if there is just one file/multiple files at /tst location, So I am using *
If it has only 1 instance it is copying properly to target location, but in this case there are multiple files in source loc.(/tst), so all the cp commands failing
In my source vault, I have 10 dirs example:
/tst/001
/tst/002
..
..
/tst/010
we might not know if there is a pdf file one instance in one of the location OR same file in multiple locations. All that I need to do is copy from source to target
Once again, you're trying to move two files into one filename, which you can't do. So what do you actually want it to do?
You need to define what, in your mind, is the "correct" behavior. What do you want the end result to be? "I don't want it to throw an error" is not a valid answer, since what you're telling it to do is not allowable, it can't run without an error. You need to define your desired behavior before you or anybody else can possibly come up with a solution.
You can't move two files into one file, it won't work. Do you want to move one of them? Which one? Do you want to move both of them to different names? How do you want to name them? If you are ABSOLUTELY POSITIVE that the files are and always will be identical, then you can just grab the first one, but are you SURE this assumption will always hold? What if they're different? What do you want it to do?
"You can't move two files into one file, it won't work. Do you want to move one of them? Which one? Do you want to move both of them to different names? How do you want to name them? If you are ABSOLUTELY POSITIVE that the files are and always will be identical, then you can just grab the first one, but are you SURE this assumption will always hold? What if they're different? What do you want it to do? "
If it is not sure that "the files are and always will be identical", is anyway to check it, if it is identical then copy one file (the first one), if not give some warning and option to copy source_file(s) to target_file_# (where # is 0, 1, 2 ...)
thanks, but it is manual if using diff -q file1 file2 . Is anyway using script to copy file (with wildcard *) and inform us whether it is different and the script is continued to copy the file1 if same, or copy file1 to target_0 and copy file2 to target_1
And then you immediately see the problem, if you provide more than one file as "source", the "destination" _must_ be a directory.
So if you want to copy all occurrences of said file to that location, find would be your friend in this:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.