[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 683
  • Last Modified:

unix cp command

could I use the cp command to copy recursively a directory to another directory, and over-write what is in the destination directory, so something like

cp -R /source /destination

0
JeffBeall
Asked:
JeffBeall
  • 5
  • 4
  • 2
  • +2
4 Solutions
 
PapertripCommented:
If you want to copy the contents of /source, then just add a * at the end
cp -R /source/* /destination

Open in new window

Without it, the /source directory will be copied into /destination as a subdirectory of it.
0
 
Joseph GanSystem AdminCommented:
Also can add "-p" to preserve ownerid, group id and permission etc.
0
 
JeffBeallAuthor Commented:
so i don't need to do anything special to over write the destination?
i ask because i already ran

cp -R /source /destination

a little while ago
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
PapertripCommented:
No you don't need anything special.

If you ran that command exactly how you typed it, then you will end up with '/destination/source/'
0
 
Joseph GanSystem AdminCommented:
Correct, it will over write everythings in destination directory without asking.
0
 
JeffBeallAuthor Commented:
ok, i'll try it.
0
 
RitBitCommented:
To force overwriting and keep permissions for a recursive copy try this:

cp -Rpf <SOURCE>  <DESTINATION>

R -> Recursive
p -> keep permissions
f -> force overwrite all
0
 
xtermCommented:
No iteration of cp will "merge" the two recursively - the source will always end up inside the destination directory, and I don't think that is what you want.

If you would like the entire contents of foo/*/* to end up IN bar/*/* then do this:

(cd /foo && tar cpf - . ) | (cd /bar && tar xvfp -)
0
 
JeffBeallAuthor Commented:
i don't really need to merge directories. overwriting in this case is fine, so will RitBit's solution work?
0
 
PapertripCommented:
The first answer I gave is sufficient for what you said you need to do, did you try it?
0
 
JeffBeallAuthor Commented:
i did try it, but everything from the source directory ended up not in the destination directory that i wanted, and i ran out of space on my external drive. so in my setup i did this

cp -R /DELTAR /t4mbu

however, maybe i should have done

cp -R /DELTAR /t4mbu/DELTAR

since i ran out of disk space , i thought maybe the command doesn't over right the destination, of course now that i think of it, it didn't have anything to over right, since all the files were in
/t4mbu/DELTAR and not /t4mbu
0
 
PapertripCommented:
cp -R /DELTAR /t4mbu
since all the files were in/t4mbu/DELTAR and not /t4mbu

If you followed my instructions, then the contents of /DELTAR would be under /t4mbu, instead of /t4mbu/DELTAR


If you want to copy the contents of /source, then just add a * at the end
cp -R /source/* /destination

Open in new window

Without it, the /source directory will be copied into /destination as a subdirectory of it.
0
 
JeffBeallAuthor Commented:
thanks for the help.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 5
  • 4
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now