Copy the files in directory and sub folders as it is to another directory.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copy the files in directory and sub folders as it is to another directory.
# 1  
Old 02-22-2013
Bug Copy the files in directory and sub folders as it is to another directory.

How to copy files from one directory to another directory with the subfolders copied.

If i have folder1/sub1/sub2/* it needs to copy files to folder2/sub1/sub2/*.
I do not want to create sub folders in folder2.
Can copy command create them automatically?


I tried cp -a and cp -R but did not work.

Thanks,
# 2  
Old 02-22-2013
Like this? This one-liner will find all files recursively under folder1/ and copy them into folder2/ without creating sub-folders.
Code:
find ./folder1/ -type f -exec cp {} ./folder2/ \;

This User Gave Thanks to balajesuri For This Post:
# 3  
Old 02-22-2013
It has to create sub folders.

i m using the command
find /directory1/sub1/ -name $file -exec cp -p {} /directory2/lib/ \;

but in the "sub1" folder i have subfolders and files, which are copied as all files in the single folder "lib" but not creating the subfolders present in the "sub1". I need those subfolders also to be created and copied.
# 4  
Old 02-22-2013
Quote:
Originally Posted by santosh2626
If i have folder1/sub1/sub2/* it needs to copy files to folder2/sub1/sub2/*.
I do not want to create sub folders in folder2.
Quote:
Originally Posted by santosh2626
It has to create sub folders.
i m using the command
find /directory1/sub1/ -name $file -exec cp -p {} /directory2/lib/ \;

but in the "sub1" folder i have subfolders and files, which are copied as all files in the single folder "lib" but not creating the subfolders present in the "sub1". I need those subfolders also to be created and copied.
Contradicting requirements.

And surprising that cp -R didn't work.
Code:
cp -R directory1/sub1 directory2/lib

This User Gave Thanks to balajesuri For This Post:
# 5  
Old 02-22-2013
Sorry that i did not put that in a clear way. I do not want to create the folders by myself. I want the copy command to create itself the subfolders and copy the files.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cpio all *.txt-files out of folders to just one directory

I need a hint for reading manpage (I did rtfm really) of cpio to do this task as in the headline described. I want to put all files of a certain type, lets say all *.txt files or any other format. Spread in more than hundreds of subdirectories in one directory I would like to select them and just... (3 Replies)
Discussion started by: 1in10
3 Replies

2. Shell Programming and Scripting

How to delete all the files and folders inside all the directories except some specific directory?

hi, i have a requirement to delete all the files from all the directories except some specific directories like archive and log. for example: there are following directories such as A B C D Archive E Log F which contains some sub directories and files. The requirement is to delete all the... (7 Replies)
Discussion started by: Little
7 Replies

3. Shell Programming and Scripting

How to copy a directory without specific files?

Hi I need to copy a huge directory with thousands of files onto another directory but without *.WMV files (and without *.wmv - perhaps we need to use *.). Pls advise how can I do that. Thanks (17 Replies)
Discussion started by: reddyr
17 Replies

4. Shell Programming and Scripting

Find and copy these files to particular directory

RedHat Enterprise Linux 5.4 I have some files with the extension .cdp in several directories in various mountpoints(filesystems) . I would like to find and copy all these files into a single directory /u03/diagnore/data. How can I do this ? (3 Replies)
Discussion started by: kraljic
3 Replies

5. UNIX for Dummies Questions & Answers

Copy files into another directory

I have a folder will a lot of documents (pdf, xls, doc etc.) which users have uploaded but only 20% of them are currently linking from my html files. So my goal is to copy only the files which are linked in my html files from my Document directory into another directory. Eg: My documents exist... (5 Replies)
Discussion started by: ankitha
5 Replies

6. UNIX for Dummies Questions & Answers

[SOLVED] Delete files and folders under given directory

I have a requirement to delete the files and folders under a given directory. my directory structure is like this.. Data | A(Directory) |_PDF(Directory)----pdf files |_XML()Directory --xml files |--files | B(Directory) |_PDF(Directory)----pdf files |_XML()Directory --xml files ... (1 Reply)
Discussion started by: ramse8pc
1 Replies

7. UNIX for Dummies Questions & Answers

How to copy all files into the same directory

Dear All, Again I have another simple question. :confused: I want to write a csh which can copy all files of a current directory with a new name in the same directory, I mean: If I have tree bird apple as files in a directory I want to give ,say number 007 as argument to my csh and it copies... (3 Replies)
Discussion started by: dreamer0085
3 Replies

8. UNIX for Advanced & Expert Users

mv OR cp many files from 1 big directory with sub folders all to 1 spot?

Hello All. I am trying to do this from a terminal prompt on my mac.... I have 100 folders all named different things. Those 100 folders are inside ~/Desktop/Pictures directory. Each of the 100 folders are uniquely named. The image files inside of each folder only have some similarities. ... (1 Reply)
Discussion started by: yoyoyo777
1 Replies

9. Shell Programming and Scripting

Copy files from one directory to another

Hi when copy the files from one directory to another as like below,it is tried to copy *. as a file. cp /home/rha/*. My objective is to copy all the files (don't care about case sensitive), Thanks in advance for your valuable reply. (1 Reply)
Discussion started by: HAA
1 Replies

10. Shell Programming and Scripting

Copy files from one directory to another

I need to copy about 13 Tb of data from one directory and subdirectories to the other (another mount point). If I run this as a cron, say between 10 pm and 7 am, not all of the files will be copied over. Is there a way of 'resuming' the copy the following evenings until all files are copied over? (0 Replies)
Discussion started by: hd2006
0 Replies
Login or Register to Ask a Question