LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 12-21-2011, 01:28 AM   #1
jeyachandran1988
LQ Newbie
 
Registered: Dec 2011
Posts: 6

Rep: Reputation: Disabled
How to copy files using command line in Linux


Hi

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

Thanks in advance
 
Old 12-21-2011, 01:32 AM   #2
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297
Hi,

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.
Code:
scp file(s)/wildcard user@host:/path
Kind regards,

Eric
 
Old 12-21-2011, 01:32 AM   #3
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,

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
Code:
me@mymachine% scp file1.foo file2.bar file3.baz alsome@myothermache:
HTH,

Evo2.
 
1 members found this post helpful.
Old 12-21-2011, 01:39 AM   #4
jeyachandran1988
LQ Newbie
 
Registered: Dec 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
Hi EricTRA

Thanks for your reply

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

Please do the needful

Thanks
 
Old 12-21-2011, 01:46 AM   #5
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297
Hello,

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.

Kind regards,

Eric
 
2 members found this post helpful.
Old 12-21-2011, 11:18 AM   #6
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,070

Rep: Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897
Quote:
Originally Posted by jeyachandran1988 View Post

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...
 
Old 12-21-2011, 12:19 PM   #7
Satyaveer Arya
Senior Member
 
Registered: May 2010
Location: Palm Island
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,420

Rep: Reputation: 305Reputation: 305Reputation: 305Reputation: 305
Hello Jeyachandran,

Using this command for an example in my case you can copy all files excluding .FOO and .BAR files:

Quote:
[root@stg02 ~]# rsync -avze ssh --exclude='*.FOO' --exclude='*.BAR' /var/www/sarg/weekly/* <dest._IPAdd.>:/logs/Linux_Server_Logs/sarg/Dec-2011/weekly/
This above command is for copying and then after copying you can delete particular files and can keep one whichever you want...

Last edited by Satyaveer Arya; 12-21-2011 at 12:20 PM.
 
1 members found this post helpful.
Old 12-21-2011, 01:01 PM   #8
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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
Use SSL shared keys to avoid password re-entry.

--- rod.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: xclip Does Copy-and-Paste on the Linux Command Line LXer Syndicated Linux News 0 07-03-2009 01:00 AM
Copy select files with command line Storyman Linux - Newbie 5 01-23-2007 03:35 AM
How to copy files via command line from Redhat to windows chris28 Linux - Networking 5 01-23-2006 11:55 PM
Copy text from command line Duukkis Linux - General 8 08-25-2003 01:29 PM
copy a cd from the command line illtbagu Linux - General 32 02-09-2003 07:08 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration