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
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
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
Try this to recreate:
Code:touch /tmp/file touch file cp -f file /tmp
Try doing this:
Does it work if you include the trailing slash? I'm at work and don't have access to a *NIX box.Code:touch /tmp/file touche file cp -f file /tmp/
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
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.
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]$
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
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!
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]
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
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.Originally Posted by rotis23
Several Linux distros do that to prevent overwriting files in places like '/' with commands like 'cp * /' issued by newbies.