LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 09-01-2011, 02:49 PM   #1
zeusys
Member
 
Registered: Jun 2006
Posts: 31

Rep: Reputation: 0
Question how to select and copy multiple directories


Hi
I want to copy multiple directories with one cp command.

Code:
-rw-r--r--. 1 1000 1000 37040 Jul 10 20:01 cherrytree.pot
drwxr-xr-x. 3 1000 1000  4096 Jul 10 20:37 cs
-rw-r--r--. 1 1000 1000 51954 Jul 10 20:06 cs.po
drwxr-xr-x. 3 1000 1000  4096 Jul 10 20:37 de
-rw-r--r--. 1 1000 1000 51185 Jul 10 20:05 de.po
drwxr-xr-x. 3 1000 1000  4096 Jul 10 20:37 es
-rw-r--r--. 1 1000 1000 52367 Jul 10 20:07 es.po
drwxr-xr-x. 3 1000 1000  4096 Jul 10 20:37 fr
-rw-r--r--. 1 1000 1000 53069 Jul 10 20:08 fr.po
-rwxr-xr-x. 1 1000 1000   178 Jun 29 01:15 i18n_create_lang_file.sh
-rwxr-xr-x. 1 1000 1000   731 Jun 29 01:27 i18n_po_to_mo.py
-rwxr-xr-x. 1 1000 1000   477 Jun 29 01:27 i18n_pot_to_updated_po.py
-rwxr-xr-x. 1 1000 1000   338 Jun 29 01:15 i18n_update_pot.sh
drwxr-xr-x. 3 1000 1000  4096 Jul 10 20:37 it
-rw-r--r--. 1 1000 1000 51754 Jul 10 20:02 it.po
drwxr-xr-x. 3 1000 1000  4096 Jul 10 20:37 pl
-rw-r--r--. 1 1000 1000 50930 Jul 10 20:10 pl.po
drwxr-xr-x. 3 1000 1000  4096 Jul 10 20:37 ru
-rw-r--r--. 1 1000 1000 60808 Jul 10 20:07 ru.po
drwxr-xr-x. 3 1000 1000  4096 Jul 10 20:37 uk
-rw-r--r--. 1 1000 1000 59566 Jul 10 20:08 uk.po
As you see,there are both files and directories.I need to copy only directories and I want to copy these directories simultaneously(with one cp command).
I know it would be done by using xargs,but I don't know how to use it.

Is there any way to achieve this goal?
please guide me.
thank you
 
Old 09-01-2011, 03:03 PM   #2
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
@ Reply

Hi there,

You can do that using following command:

cp -arv directory1 directory2 directory3 /destination-directory

Make sure that you run this command from the location where the source directories are located.

I hope this helps.
 
Old 09-01-2011, 03:05 PM   #3
zeusys
Member
 
Registered: Jun 2006
Posts: 31

Original Poster
Rep: Reputation: 0
Thank you
Is there any solution by using xargs command?
 
Old 09-01-2011, 03:16 PM   #4
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
@ Reply

Yes there is a way but a bit confusing. The one mentioned above is easy. If you still want to try then following is the command:

Code:
find / -name name_of_destination_directory -print | xargs /bin/cp -arv source_directory1_with_full_path source_directory2_with_full_path source_directory3_with_full_path
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy files from multiple directories into one directory MadRabbit Linux - Newbie 8 02-07-2014 07:56 PM
copy one large directory or multiple cp's on the sub directories superc0w Linux - General 7 12-15-2008 02:14 PM
Copy one file to multiple vhost directories thetawaverider Linux - Newbie 5 03-24-2006 04:57 PM
Copy one file to multiple directories cmfarley19 Linux - General 9 11-10-2004 12:57 PM
find and copy files into multiple directories avargas22 Linux - Newbie 2 04-01-2004 11:11 AM


All times are GMT -5. The time now is 07:52 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration