Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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 need to copy files in linux server to another Linux server using command line but i need to one file alone but i need to copy rest of the files in one command
I'm having a hard time understanding what you mean. Do you need to copy one file or all files? Whatever you need to copy over from one Linux server to another, assuming SSH is installed and running, you could use scp which is part of the openssh package.
I guess you've already discovered how to use scp for a single file. scp can also copy recursively (ie a whole directory tree). Have a look at the -r option in the scp man page. You might also like to have a look at the rsync command. Finally you can simply list multiple files on the local file system.
Eg
Nobody here will 'do the needful' for you my friend. You're the one that needs to put in the work. As indicated by Evo2, read the man pages for scp and rsync. Either of those commands can do the job. By reading the man pages and trying for yourself you'll learn a lot more then when we give you a ready made solution, which by the way is not the way LQ works. Normal processing would be that you try it yourself and if you fail and don't find an answer, then you turn to us to point you in the right direction.
Actually I need to copy folder or files b/w two linux server. For example i need to copy 95 folders or files out of 100 in command line
Well, in schematic (overview), you have a choice of about two ways, and a number of sub-variants.
One of them is to set up some kind of regular expression that matches only the files that you want to copy.
The other is to copy all of the files, and delete the ones that you don't want.
The second of those two is often regarded as unsophisticated, but may well be massively easier to set up, in some particular circumstance, and in that context, people, me included, can find sophistication to be an overrated virtue. You must make your own determination on what you think about this, and how it applies to your particular situation.
Regarding the first method, it is almost entirely dependant on the patterns in the names whether this is easy to achieve, because you have to be able to write patterns which match one set of files and not the other set. As you have told us nothing about the 'patterns' (assuming some patterns exist) aspect, it is not something that we can do anything about. (Oh, and if you have made the mistake of allowing spaces and strange characters into the filenames, that will increase the degree of difficulty, a little.)
One minor variant that you might want to consider is to copy all of the files that you want to copy from one machine to another into a new sub-directory. This way, you can easily check that the correct files are queued up for processing. And, if you do employ the 'copy all, delete a few' method (method two), then doing the deletion on a dedicated sub-directory is a tactic that can make it less likely that you accidentally delete a wanted file. assuming that you always keep track of which directory you are in, of course...
It sounds like this is something you want to do repeatedly. If so, create a text file containing the names of each file that you need to copy, one filename per line. Then, you can use it as input to a looping script that copies iteratively.
Code:
while read sourcefile; do scp "$sourcefile" someuser@destinationServer; done < yourFileList.txt
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.