cp command.
hi,
I have two questions regarding to cp i.e copy command. 1- I have a folder which have thousands of files and few directories.I want to copy same folder in another location like "my_dir" where only files should only copy in it not the directories. 2- If I want to copy a file from another linux machine over LAN suppose PC-1 want to opy the data from PC-2 then what should be the command ? thanks, gardenair |
Hi
I recommend you look into backup software, like rsync. man page, http://linux.die.net/man/1/rsync tutorial, 15 examples including networks http://www.thegeekstuff.com/2010/09/...mand-examples/ wiki http://en.wikipedia.org/wiki/Rsync regards Glenn |
You can do a recursive copy which will get "everything" from one direcotry to another; e.g.,
Code:
cp -pr my_dir . Code:
!#/bin/bash To copy between two machines, the easiest way is with scp -- so you need to have SSH access between the two machines. Set that up first if it's not already in place, then on your local machine get into a directory where you want to have the copied file tree and Code:
cd the_directory It would be a good idea to review the manual pages for cp and scp. Hope this helps some. |
For the first question, you could use the find command. ie : find start_dir -type f | xargs -I'{} cp {} my_dir
This will find all files from the start_dir downwards and copy them to my_dir. You will lose the original directory hierarchy. Is this what you meant? The only problem would be if you have 2 files with the same name but not in the same sub-directory. For the second question, you can use scp. |
thanks for the replies. Well scp successfully work & it copy files over lan. The question is if we want to copy files & folder as well then which command should we use ?
|
Quote:
The copy utilities (cp and scp to name two) support recursive copy; that is, walk a tree and copy it in its entirety. You could see what a tree looks like with the tree utility -- it walks a directory tree and shows all content -- that's what recursive means. Hope this helps some. |
well i am again repeating my questions. Over the LAN we can copy files using scp command.If we also want to copy a directory from a remote pc on LAN what command should i use.
I try scp command but it only copy files. thanks, garenair |
Quote:
You first asked for a command to copy all the files to ONE directory, and tronayne gave it to you. Want to copy everything, as is?? Use the commands given as they are. Code:
cp -R /some/directory/* /some/destination/ |
In short, if the 'copying' is local disk to local disk (includes nfs, cifs mts), then use 'cp', else (for remote ie across LAN/WAN/internet) use scp.
You should read these pages http://linux.die.net/man/1/cp http://linux.die.net/man/1/scp |
Thanks for the reply.chrism01 very shory & have meaningfull reply regarding to cp and scp command.
For backup things I normally use tar command which compress the files & keep it in a single file.rsync is a new command in Linux.What is a main difference between rsync and tar command and in which situation we can use rsync or tar command ? The mainthing which i read from web sites given below is rsync is used for remotely backup. gardenair |
Quote:
Quote:
Quote:
|
All times are GMT -5. The time now is 10:30 PM. |