Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 08-17-2011, 10:04 PM   #1
Registered: Jun 2006
Posts: 31

Rep: Reputation: 0
copy multiple directories into another one directory with single cp command

I want to copy multiple directories to another directory,
for example I want to copy directories A,B,C and D to /home/user01/alldirectories.
how should I do with a single cp command?
Old 08-17-2011, 10:19 PM   #2
Registered: Feb 2003
Location: Florida
Distribution: Fedora 18
Posts: 862

Rep: Reputation: 91
As all things it depends. Are all the source directories under the same parent directory? Do you want all subdirectories too? If so do:
cp -r /some/directory/{A,B,C,D} /home/user01/alldirectories
The "-r" option means recurse to all said subdirectories. If you want to copy ALL the directories in the parent directory do:
cp -r /some/directory/* /home/user01/alldirectories
If the directories are not all under the same parent directory, well, you get the idea -- but you can put all the source directories on the same line with the destination directory last, you don't need a new command line for each source directory. I recommend reading the manual for the cp command, you'll find some pretty neat things there. To read the manual just do:
man cp
You can do that for almost any command.

Last edited by SharpyWarpy; 08-17-2011 at 10:25 PM. Reason: a little more info
Old 08-17-2011, 10:23 PM   #3
LQ Newbie
Registered: Apr 2010
Location: Dallas, TX
Distribution: Simply MEPIS, OpenArtist, Ubuntu 10.04, Mint, Elive, Epidemic, Kongoni, Anibus, BackTrack4
Posts: 29

Rep: Reputation: 2
Hi Zeusys,
use the following command to copy multiple directories:

sudo cp -R directory\A/ directory\B/ directory\C/ /home/user01/alldirectories/
That will copy the directory and it's contents into the new directory.


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
[SOLVED] How to copy a file to all subfolders in a directory using a single command? SirTristan Linux - Newbie 7 07-18-2010 11:19 PM
copy one large directory or multiple cp's on the sub directories superc0w Linux - General 7 12-15-2008 02:14 PM
copy all of one filetype found by locate command to a single directory socratesone Linux - Software 3 06-22-2005 01:23 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:38 AM.

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