473,399 Members | 2,278 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,399 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 46089
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.