C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 07-05-2004, 10:44 AM   #1
Registered User
 
Join Date: Aug 2002
Posts: 351
OT:force overwrite with cp

Can anyone please tell me how to force overwrite with the cp command [on linux] on the command-line.

The following do not work:

-f
--force
--remove-destination

Any ideas?

rotis23
rotis23 is offline   Reply With Quote
Old 07-05-2004, 10:50 AM   #2
C++ Developer
 
XSquared's Avatar
 
Join Date: Jun 2002
Location: UWaterloo
Posts: 2,718
According to the man page, -f should work. What's the entire command you're using?
__________________
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
XSquared is offline   Reply With Quote
Old 07-05-2004, 10:57 AM   #3
Registered User
 
Join Date: Aug 2002
Posts: 351
Try this to recreate:

Code:
touch /tmp/file
touch file
cp -f file /tmp
rotis23 is offline   Reply With Quote
Old 07-05-2004, 11:09 AM   #4
C++ Developer
 
XSquared's Avatar
 
Join Date: Jun 2002
Location: UWaterloo
Posts: 2,718
Try doing this:
Code:
touch /tmp/file
touche file
cp -f file /tmp/
Does it work if you include the trailing slash? I'm at work and don't have access to a *NIX box.
__________________
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
XSquared is offline   Reply With Quote
Old 07-05-2004, 02:49 PM   #5
Registered User
 
Join Date: Aug 2002
Posts: 351
No difference with trailing slashes.

It's a permissions thing.

If I create the file as a user in /tmp I can cp without a confirmation (even without a -f).

But if you su to root, confirmation is required.

I still confused.
rotis23 is offline   Reply With Quote
Old 07-05-2004, 02:50 PM   #6
Registered User
 
Join Date: Aug 2002
Posts: 351
example:
Code:
[rotis23@cabbage rotis23]$ touch /tmp/file
[rotis23@cabbage rotis23]$ cp file /tmp
[rotis23@cabbage rotis23]$ su
Password:
[root@cabbage rotis23]# cp file /tmp
cp: overwrite `/tmp/file'? y
[root@cabbage rotis23]# exit
exit
[rotis23@cabbage rotis23]$ cp file /tmp
[rotis23@cabbage rotis23]$
rotis23 is offline   Reply With Quote
Old 07-05-2004, 03:02 PM   #7
C++ Developer
 
XSquared's Avatar
 
Join Date: Jun 2002
Location: UWaterloo
Posts: 2,718
Code:
mlawrence@xanthus mlawrence $ touch /tmp/file
mlawrence@xanthus mlawrence $ touch file
mlawrence@xanthus mlawrence $ cp file /tmp
mlawrence@xanthus mlawrence $ su -
Password:
xanthus root # touch file
xanthus root # cp file /tmp
xanthus root # exit
logout
mlawrence@xanthus mlawrence $ cp file /tmp
mlawrence@xanthus mlawrence $
__________________
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
XSquared is offline   Reply With Quote
Old 07-05-2004, 03:24 PM   #8
Registered User
 
Join Date: Aug 2002
Posts: 351
Weird - I tried 'su -' but still no difference.

I've tested using redhat 8 and 9. What unix are you using XSquared.

BTW vegetables are the new mythological creatures!
rotis23 is offline   Reply With Quote
Old 07-05-2004, 04:13 PM   #9
End Of Line
 
Hammer's Avatar
 
Join Date: Apr 2002
Posts: 6,240
Show us an "ls -al" for that file before and after.
Check your umask settings for each user. These will affects the default file permissions for new files.
>>cp -f source target
should do you. Can you show the output for it failing?
__________________
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
Hammer is offline   Reply With Quote
Old 07-05-2004, 06:41 PM   #10
C++ Developer
 
XSquared's Avatar
 
Join Date: Jun 2002
Location: UWaterloo
Posts: 2,718
I'm runnin' Gentoo with a 2.6.5 kernel. Just for reference, I've included the ls -al before and after.

Code:
Before:
-rw-r--r--  1 mlawrence users 0 Jul  5 20:42 /tmp/file

After:
-rw-r--r--  1 mlawrence users 0 Jul  5 20:42 /tmp/file
__________________
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
XSquared is offline   Reply With Quote
Old 07-06-2004, 07:11 AM   #11
Registered User
 
Join Date: Aug 2002
Posts: 351
Found the problem - alias!!

cp is aliased to 'cp -i'!!
Code:
[root@cabbage cmasters]# alias
alias cp='cp -i'
rotis23 is offline   Reply With Quote
Old 07-06-2004, 10:47 AM   #12
Registered User
 
linuxdude's Avatar
 
Join Date: Mar 2003
Location: Louisiana
Posts: 926
Quote:
Originally Posted by rotis23
Found the problem - alias!!

cp is aliased to 'cp -i'!!
Code:
[root@cabbage cmasters]# alias
alias cp='cp -i'
yeah Redhet does that, would have never remembered that.
linuxdude is offline   Reply With Quote
Old 07-06-2004, 11:11 AM   #13
.
 
Join Date: Nov 2003
Posts: 293
Several Linux distros do that to prevent overwriting files in places like '/' with commands like 'cp * /' issued by newbies.
jim mcnamara is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
using the cp command in a program in os x peateargriffin C Programming 22 04-08-2006 11:52 PM
how to overwrite the text in *.txt SuperNewbie C# Programming 4 11-10-2003 09:01 AM
Add not overwrite to a file Bones C++ Programming 7 10-03-2003 09:56 AM
Overwrite data in a file SMurf Windows Programming 5 12-16-2002 01:40 PM
File opens, but won't overwrite Brown Drake C++ Programming 0 11-23-2001 08:31 AM


All times are GMT -6. The time now is 02:32 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22