473,386 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

force cp to overwrite existing directory

bilibytes
128 100+
hi there,

i am fighting against my unix box to be able to copy a directory and replace the destination if already existing.
i'm using "Bash"

i use:

Expand|Select|Wrap|Line Numbers
  1. cp -fR /source/src_directory /destination/dest_directory
what this will do is that it will create a directory like this:
(assuming destination/dest_directory already exists)
Expand|Select|Wrap|Line Numbers
  1. /destination/dest_directory/dest_directory
and i want:

Expand|Select|Wrap|Line Numbers
  1. /destination/dest_directory
if you know how to obtain the last result please let me know, because i wont be able to sleep until then! lol

thank you

best regards

bilibytes
Mar 4 '09 #1
3 46084
bilibytes
128 100+
I came with sort of a patch solution:

in my .profile under the home directory, i created a function: cpForce which looks like this:

cpForce(){
sudo rm -fR $1
sudo cp -fR $1
}


regards.
Mar 4 '09 #2
mac11
256 100+
I think it would be sufficient to do

Expand|Select|Wrap|Line Numbers
  1. cp -fR source/src_directory destination/
That is, don't specify the destination directory, just the path up to it (if that makes sense). So if you have

/source/files/filetocopy
/source/files/filetocopy2
/dest/files

you just do

Expand|Select|Wrap|Line Numbers
  1. cp -fR /source/files /dest
and you end up with

/source/files/filetocopy
/source/files/filetocopy2
/dest/files/filetocopy
/dest/files/filetocopy2

Maybe I'm not understanding your issue though.
Mar 4 '09 #3
bilibytes
128 100+
ok thanks, i now understood the problem.

The first time you copy a folder to another directory, if the folder does not exist in the directory, you have to specify the name of the folder as:

cp -fR /source_directory/folder /destination_directory/folder

and it will copy the /source_directory/folder as /destination_directory/folder.

However the second time, /destination_directory/folder already exists and running the same command will do this:

/destination_directory/folder/folder

so it copies the folder inside the first copied folder.

and that is the weird thing.

but the destination I see that folder must be the final folder -1
however if you want the destination folder to have a different name than the source my alias in the post above works fine.

regards
Mar 7 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Bo Wisén | last post by:
If I want to decide if a file exists I can use 'if dir("c:\test1\test2\testfile.txt")="testfile.txt"'. But now I want my application to decide if a directory exists and, if not, create it. Maybe...
0
by: Zero | last post by:
how to Overwrite Existing Excel File without prompt and quit?
8
by: phobos7 | last post by:
I am trying to create a single .EXE that will upgrade a product by the doing the following: 1) Detect the location of the current installation (DONE) 2) Upgrade the existing config file (DONE)...
2
by: B-Dog | last post by:
Is there a way to make vb.net to overwrite the file when moving? Here is what I'm trying to do: If System.IO.File.Exists(dest) Then 'handle overwrite here If MessageBox.Show("Do you want...
2
by: Frank Jeseit | last post by:
Hi, I have a directory with a webservice project that is not published in IIS. Therefore I'm not able to open the project in VS.NET (2003). My goal is to create a virtual directory in IIS from...
5
by: Andy | last post by:
I thought I could RDP to the web server, open the web.config, make the change, and save it. But this causes IIS to hang, and it never recovers - I have to create a new website in IIS! Should...
1
by: dbruzzese84 | last post by:
I am using an update query which updates data in one table taken from a new weekly table. The only problem that I am having is they are not overwriting each other. it is making duplicate records. ...
7
madhoriya22
by: madhoriya22 | last post by:
Hi, I am getting the data from the CSV file and inserting it to the database. Now while inserting I have to check that some of the data(to be inserted) is already existing in the table or not. If...
5
by: mvelasquez | last post by:
I'm working with crystal reports in my windows app. I have a pre-existing report that I will access dynamically in the application at run time. I set the parameters of the report through the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.