LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 04-14-2011, 10:21 AM   #1
linuxman2
LQ Newbie
 
Registered: Apr 2011
Posts: 2

Rep: Reputation: 0
How does Linux cp command determine the source and destination locations in command?


When you run the following cp command in the BASH terminal, how does Linux know which files are the source and which are the destination when copying multiple files from one location to another?

Example:
cp /etc/services /etc/motd /etc/fstab /etc/hosts /home/fred/my_dir

How does Linux know that the services, motd, fstab, and hosts files are the source and the /home/fred/my_dir is the destination?

This question came up in a Linux class and I was not sure of the answer. I was thinking it is based on the source path entered ending with a file path and the destination being a directory, but was not sure.

Thank you.
 
Old 04-14-2011, 10:28 AM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,653

Rep: Reputation: 536Reputation: 536Reputation: 536Reputation: 536Reputation: 536Reputation: 536
Because that's how it was coded. There can be only one destination.

Code:
CP(1)                                     User Commands                                     CP(1)

NAME
       cp - copy files and directories

SYNOPSIS
       cp [OPTION]... [-T] SOURCE DEST
       cp [OPTION]... SOURCE... DIRECTORY
       cp [OPTION]... -t DIRECTORY SOURCE...

DESCRIPTION
       Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.
 
Old 04-14-2011, 10:48 AM   #3
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Main: Gentoo Others: What fits the task
Posts: 15,653
Blog Entries: 2

Rep: Reputation: 4097Reputation: 4097Reputation: 4097Reputation: 4097Reputation: 4097Reputation: 4097Reputation: 4097Reputation: 4097Reputation: 4097Reputation: 4097Reputation: 4097
Quote:
Originally Posted by linuxman2 View Post
I was thinking it is based on the source path entered ending with a file path and the destination being a directory, but was not sure.
At first, AlucardZero is totally right with his answer.
Just a side note, you can also copy multiple directories into one target directory. for example:
Code:
cp -r /etc /home /mnt/backup
which will copy the /etc and /home directories to a (previously mounted) backup directory.
 
Old 04-14-2011, 12:28 PM   #4
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714
Quote:
Originally Posted by linuxman2 View Post
When you run the following cp command in the BASH terminal, how does Linux know which files are the source and which are the destination when copying multiple files from one location to another?
The last file is the destination, all the files before that are the sources.
 
Old 04-14-2011, 08:13 PM   #5
linuxman2
LQ Newbie
 
Registered: Apr 2011
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks

Thanks for the quick reply.

That is what I thought but I just wanted to confirm it.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] copying files from multiple locations to one destination mahmoodn Linux - General 3 02-21-2011 10:33 AM
how to copy drive using dd and tee command parallely? source code of dd command mdfakkeer Linux - Software 1 02-10-2010 02:31 PM
how to store command history using HISTFILE in 2 locations? emzvargas Programming 4 05-21-2009 07:33 AM
Determine Linux distro from command line? Rotwang Linux - General 1 01-05-2007 02:25 PM
traceroute command AND repeating the destination in output dan99 Linux - Networking 1 01-22-2005 11:00 PM


All times are GMT -5. The time now is 12:26 PM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration