Fedora Linux Support Community & Resources Center

Go Back   FedoraForum.org > Fedora 17/18 > Using Fedora
FedoraForum Search

Forgot Password? Join Us!

Using Fedora General support for current versions. Ask questions about Fedora and it's software that do not belong in any other forum.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 4th October 2011, 07:18 PM
Jakes9x Offline
Registered User
 
Join Date: Sep 2011
Posts: 6
windows_xp_2003firefox
How to copy more then two files to a directory using cp command

If there is a Directory A another directory B is sub dir. of A
B contains two files named - fil1 and fil2
I am currently in Dir. A

I want to copy it to dir Z ... the path of Z is A/X/Z


for copying single file ... fil1 in this case will be copied to dir Z
Code:
cp B/fil1  X/Z
source destination

But what if we want to copy fil1 and fil2 at the same time. Is it possible using cp command?
cp B/fil1 fil2 X/Z this doesn't work

Last edited by Jakes9x; 4th October 2011 at 07:21 PM.
Reply With Quote
  #2  
Old 4th October 2011, 07:21 PM
cazo Offline
Registered User
 
Join Date: Sep 2005
Location: Redneck Riviera
Posts: 333
linuxchrome
Re: How to copy more then two files to a directory using cp command

cp B/fil1 B/fil2 X/Z
Reply With Quote
  #3  
Old 4th October 2011, 07:23 PM
jpollard Offline
Registered User
 
Join Date: Aug 2009
Location: Waldorf, Maryland
Posts: 6,105
linuxfedorafirefox
Re: How to copy more then two files to a directory using cp command

cp B/* X/Z

will copy all files in B.

the * can be replaced with other pattern match operators such as
B/file[12] , which specifies B/file1 B/file2.

This is mostly a shell operation, but the cp commands only takes a list of files/directories to a target directory if more than one file is specified.

The man utilitity is your friend, try "man cp"
Reply With Quote
  #4  
Old 4th October 2011, 07:46 PM
sea's Avatar
sea Online
"Shells" (of a sub world)
 
Join Date: May 2011
Location: Helvetic Federation (Swissh)
Age: 33
Posts: 2,607
linuxfedorafirefox
Re: How to copy more then two files to a directory using cp command

PHP Code:
#!/bin/bash
tocopy="/path/to/file1 /path/to/file2"
targetdir=/some/dest/ination
  
for thisfile in $tocopy ; do
    
cp $thisfile to $targetdir
  done 
just change filenames and targetdir and copy paste to terminal.
__________________
Fedora Manual: http://docs.fedoraproject.org
Script-Tools: https://sourceforge.net/projects/script-tools/
sudo st tweak repo toggle fedora-rawhide ; st iso dl-fed -respin && st iso usb

Last edited by sea; 4th October 2011 at 07:49 PM.
Reply With Quote
  #5  
Old 4th October 2011, 07:57 PM
jpollard Offline
Registered User
 
Join Date: Aug 2009
Location: Waldorf, Maryland
Posts: 6,105
linuxfedorafirefox
Re: How to copy more then two files to a directory using cp command

sea, What for?

The cp command already does this.

Your "solution" is longer than the problem.
Reply With Quote
  #6  
Old 4th October 2011, 08:02 PM
sea's Avatar
sea Online
"Shells" (of a sub world)
 
Join Date: May 2011
Location: Helvetic Federation (Swissh)
Age: 33
Posts: 2,607
linuxfedorafirefox
Re: How to copy more then two files to a directory using cp command

Didnt know that, as i didnt read cazo's post close enough.
__________________
Fedora Manual: http://docs.fedoraproject.org
Script-Tools: https://sourceforge.net/projects/script-tools/
sudo st tweak repo toggle fedora-rawhide ; st iso dl-fed -respin && st iso usb
Reply With Quote
  #7  
Old 4th October 2011, 08:43 PM
stevea's Avatar
stevea Offline
Registered User
 
Join Date: Apr 2006
Location: Ohio, USA
Posts: 8,300
linuxfedorafirefox
Re: How to copy more then two files to a directory using cp command

Quote:
Originally Posted by cazo View Post
cp B/fil1 B/fil2 X/Z
Or ....
cp B/fil{1,2} X/Z # does the same as above using shell expansion
or
cp B/fil* X/Z # copies all files matching B/fil*
__________________
None are more hopelessly enslaved than those who falsely believe they are free.
Johann Wolfgang von Goethe
Reply With Quote
  #8  
Old 4th October 2011, 09:40 PM
bodhi.zazen's Avatar
bodhi.zazen Offline
Registered User
 
Join Date: Jul 2006
Location: Montana
Posts: 731
windows_xp_2003firefox
Re: How to copy more then two files to a directory using cp command

There is also the -r option to copy, the man page can be very informative.
__________________
If it is not broken, tweak it... If you break Fedora you get to keep both pieces :p
Reply With Quote
Reply

Tags
command, copy, directory, files

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
help! cannot copy to directory of usr>src lizongyin Using Fedora 2 4th January 2009 08:47 PM


Current GMT-time: 00:19 (Thursday, 23-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat