Copy files recursively


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Copy files recursively
# 1  
Old 08-02-2014
Copy files recursively

Hello!
I know what i s recursion, but can't imagine what shoudl be "recursicve copying" of files?

Please, what should mean:
cp -r /home/hope/files/* /home/hope/backup

Can someone helpme with a simple example?
Many thanks!!!
# 2  
Old 08-02-2014
It copies all the files (and directories, which themselves are special files) matching * in /home/hope/files, recursively, to /home/hope/backup

Code:
$ find /home/hope/files
/home/hope/files
/home/hope/files/.d
/home/hope/files/a
/home/hope/files/b/.b1
/home/hope/files/b/b2
/home/hope/files/b/b3
/home/hope/files/c

$ cp -r /home/hope/files/* /home/hope/backup
$ find /home/hope/backup
/home/hope/backup
/home/hope/backup/a
/home/hope/backup/b/b2
/home/hope/backup/b/b3
/home/hope/backup/c

This User Gave Thanks to Scott For This Post:
# 3  
Old 08-02-2014
unix

Aha!
So, files containing .b and .d would be copied too, if it was .* instead of *
Many thanks!!!

What means the word "recursively" exactly here? To be cpied to "themselves" (same file content, same name, I supoose?)
Many thanks!!!
# 4  
Old 08-02-2014
It has nothing to do with the filenames, only the process by which they're copied: Copy everything matching *. If * is a directory, go into it and repeat "copy everything matching [b]*[/b/]". .b, for example, would not be copied because it is not matched by *

Recursive - Definition and More from the Free Merriam-Webster Dictionary
This User Gave Thanks to Scott For This Post:
# 5  
Old 08-02-2014
Hello!
Many thanks!!!
Please, what exactly would:
Code:
$ cp  /home/hope/files/* /home/hope/backup

do then?
# 6  
Old 08-02-2014
It is missing the -r recursive option. What, then, would you expect? The man pages (e.g. man cp) are an inexhaustible reservoir of information on unix commands (and more).
This User Gave Thanks to RudiC For This Post:
# 7  
Old 08-02-2014
It would copy all files (excluding directories, but including the target of symbolic links and other special files) matching * from /home/hope/files to /home/hope/backup.

Please install a Linux, Unix or Cygwin or the likes onto your computer and practice, instead of continually asking these types of questions.
This User Gave Thanks to Scott For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copy files recursively to one single directory

I need to copy a complete directory structure into a new location. But I want to have all files copied into one directory and leave out the directory structure. So all files must be placed in one directory. (4 Replies)
Discussion started by: ReneVL
4 Replies

2. Shell Programming and Scripting

Copy Specific Files Recursively

Is it possible to only copy selected files+its directories when you are copying recursively? find /OriginalFolder/* -type -d \{ -mtime 1 -o -mtime 2 \ } -exec cp -R {} /CopyTo/'hostname'__CopyTo/ \; -print From the above line, I want to only copy *txt and *ini files from /OriginalFolder/* ... (4 Replies)
Discussion started by: apacheLinux
4 Replies

3. Shell Programming and Scripting

How to recursively copy directory only for recent files?

I love the -newerct flag for the Cygwin find command on windows. Can I use "/usr/bin/find . -newerct '3 hours ago'" to conditionally copy a directory tree so that only the files in the directory tree that are younger than 3 hours are copied to my destination directory such that the directory... (4 Replies)
Discussion started by: siegfried
4 Replies

4. Shell Programming and Scripting

Shell script to copy particular file from directories recursively

I have directory path in which there are several sub directories. In all these sub dir there will be one env.cnf file. I want to copy this env.cnf file from each sub dir's and place them in destination path by creating same filename as sub dir_env.cnf. After copying env.cnf files from source... (4 Replies)
Discussion started by: Optimus81
4 Replies

5. Shell Programming and Scripting

ftp script to copy folders recursively

hi all I want a script that will use ftp to copy folder and sub folders from source server to current server. if i use -r switch then it just copies folders for 5 level. (1 Reply)
Discussion started by: kashif.live
1 Replies

6. Red Hat

Copy certain file types recursively while maintaining file structure on destination?

Hi guys, I have just been bothered by a fairly small issue for some time now. I am trying to search (using find -name) for some .jpg files recursively. This is a Redhat environment with bash. I get this job done though I need to copy ALL of them and put them in a separate folder BUT I also... (1 Reply)
Discussion started by: rockf1bull
1 Replies

7. Shell Programming and Scripting

Recursively move directories along with files/specific files

I would like to transfer all files ending with .log from /tmp and to /tmp/archive (using find ) The directory structure looks like :- /tmp a.log b.log c.log /abcd d.log e.log When I tried the following command , it movies all the log files... (8 Replies)
Discussion started by: frintocf
8 Replies

8. UNIX for Dummies Questions & Answers

Need help in moving files recursively

Hi, I have d1,d2,d3 directories / /home/abc/d1 /home/abc/d2 /home/abc/d3 d1,d2 and d3 also have subdirctories. d1-->d11-->d12 d2-->d22-->d23 d3-->d33-->d34 All these directories have files like date_filename.txt so I want to find the files recusively for a particular date from... (1 Reply)
Discussion started by: jagadish_gaddam
1 Replies

9. Shell Programming and Scripting

Copy only files recursively

Hi, find . | xargs -s 47518 can list all the files and directories recursively , is there any possibility to copy only files from directories and subdirectoreis once it is listed. Please help Thans & Regards Uma (3 Replies)
Discussion started by: umapearl
3 Replies

10. Shell Programming and Scripting

Recursively copy only specific files from a directory tree

Hi I am a shell-script newbie and am looking to synchronize certain files in two directory structures. Both these directory-trees are in CVS and so I dont want the CVS directory to be copied over. I want only .sh and .pl files in each subdirectory under these directory trees to be... (3 Replies)
Discussion started by: sharpsharkrocks
3 Replies
Login or Register to Ask a Question