LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-15-2008, 09:35 AM   #1
webaccounts
Member
 
Registered: May 2008
Location: Columbus Ohio
Distribution: CentOS 5.9/6.4 x64
Posts: 44

Rep: Reputation: 19
cp command allows prompts to overwrite


Does anyone know why cp always prompts me to overwrite files. According to the man file, -i is for prompting.

I'm using:
Linux lnxapp 2.6.23.15-80.fc7 #1 SMP Sun Feb 10 17:29:10 EST 2008 i686 i686 i386 GNU/Linux

Code:
[root@lnxapp modules]# cp -rf fckeditor /var/www/html/chapters/chapter-test2/modules
cp: overwrite `/var/www/html/chapters/chapter-test2/modules/fckeditor/uninstall.php'?
 
Old 05-15-2008, 09:41 AM   #2
DotHQ
Member
 
Registered: Mar 2006
Location: Ohio, USA
Distribution: Red Hat, Fedora, Knoppix,
Posts: 545

Rep: Reputation: 33
I've noticed that also. Specifically when I'm root. I just did a little test to verify that if I'm not root I do not get prompted.
Not an explanation just an observation.
 
Old 05-15-2008, 09:49 AM   #3
webaccounts
Member
 
Registered: May 2008
Location: Columbus Ohio
Distribution: CentOS 5.9/6.4 x64
Posts: 44

Original Poster
Rep: Reputation: 19
Quote:
Originally Posted by DotHQ View Post
I've noticed that also. Specifically when I'm root. I just did a little test to verify that if I'm not root I do not get prompted.
Not an explanation just an observation.
Thanks for the quick response.
Never noticed that, but that is the same for me. With a normal user, no prompt, with root, it always prompts.

Is there a parameter for root to not prompt then?
 
Old 05-15-2008, 09:55 AM   #4
SlowCoder
Member
 
Registered: Oct 2004
Location: Southeast, U.S.A.
Distribution: Fedora (Desktop), CentOS (Server), Knoppix (Diags)
Posts: 934

Rep: Reputation: 38
This is a security measure for the root account, given its godly powers over your machine.

Take a look inside root's .bashrc file. You should find an alias to cp that includes the -i option. Remark that line to make cp operate like a normal user.
 
Old 05-15-2008, 10:06 AM   #5
webaccounts
Member
 
Registered: May 2008
Location: Columbus Ohio
Distribution: CentOS 5.9/6.4 x64
Posts: 44

Original Poster
Rep: Reputation: 19
Perfect! Thanks Slowcoder!

I can see why they do it now for root. Maybe I'm thinking cp, rm, & mv should prompt by default and have a parameter to skip the prompt. Seems to make more sense that way.
 
Old 05-15-2008, 10:19 AM   #6
SlowCoder
Member
 
Registered: Oct 2004
Location: Southeast, U.S.A.
Distribution: Fedora (Desktop), CentOS (Server), Knoppix (Diags)
Posts: 934

Rep: Reputation: 38
Quote:
Originally Posted by webaccounts View Post
Perfect! Thanks Slowcoder!

I can see why they do it now for root. Maybe I'm thinking cp, rm, & mv should prompt by default and have a parameter to skip the prompt. Seems to make more sense that way.
Yep, but they don't by default. Even if they did, the aliases in root's .bashrc forcibly cause the commands to question your actions, no matter what options you send to the commands. Not as important for normal users, as all they can mess with are things they have permissions to.

On another note, the aliases allow you to change the default behavior of any commands. So, if you've got a certain command that you're always setting parameters on, you can give it an alias. The name of the alias itself does not have to be the same as the command itself.

For instance,
Code:
alias cpi='cp -i -v'
would give allow you to issue "cpi" as a command that runs "cp -i -v".

Just another way Linux rocks!
 
Old 05-15-2008, 12:00 PM   #7
pdtpatrick
LQ Newbie
 
Registered: Mar 2008
Posts: 11

Rep: Reputation: 0
here's what i'd try

Im not no expert at linux but check your alias, your cp might be set to cp -i in the alias and if you wish, you would change that warning but i dont see why anyone would want to change it considering the mess you would be if you were to delete something by invoking the wrong command .. ha.

Just like rm is probably set to rm -i as well.
 
Old 05-15-2008, 01:44 PM   #8
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by SlowCoder View Post
Yep, but they don't by default. Even if they did, the aliases in root's .bashrc forcibly cause the commands to question your actions, no matter what options you send to the commands. Not as important for normal users, as all they can mess with are things they have permissions to.
I think it's a bad thing - what if you happen to get
access to a box that (for whatever reason!) doesn't
have that alias defined?

There's nothing that should replace your sanchin when
dealing with anything as root; particularly not aliases
that lull you into a false sense of safety.



Cheers,
Tink
 
Old 05-15-2008, 03:38 PM   #9
SlowCoder
Member
 
Registered: Oct 2004
Location: Southeast, U.S.A.
Distribution: Fedora (Desktop), CentOS (Server), Knoppix (Diags)
Posts: 934

Rep: Reputation: 38
Quote:
Originally Posted by Tinkster View Post
I think it's a bad thing - what if you happen to get
access to a box that (for whatever reason!) doesn't
have that alias defined?

There's nothing that should replace your sanchin when
dealing with anything as root; particularly not aliases
that lull you into a false sense of safety.

Cheers,
Tink
I agree it's a bad thing that the default is to auto-overwrite/delete without confirmation. I was saying that it would be logical thinking that a command would operate with effectively the same behavior no matter what account it is executed with. So, being that it doesn't require confirmation as normal user, one might assume the same as root.

I rather think it could be a good idea to place the aliases in normal user's .bashrc files, except that (I believe) the -i overrides the -f, so would render -f nonfunctional. So, I suppose maybe the best solution would be to recompile cp/rm/mv so that -i is default.

P.S. What's a 'sanchin'?
 
Old 05-15-2008, 08:24 PM   #10
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by SlowCoder View Post
P.S. What's a 'sanchin'?
Term from bushido. I've been taught that it literally translates
to "three battles", and that it means a state of alertness, hightened
awareness. It's a stance in Karate, and also the name of a kata.


Cheers,
Tink
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cp command: how can I make it not automatically overwrite files? hamish Linux - Software 6 11-18-2006 11:30 AM
BASH: How to answer command prompts using redirects ?? swedish_lunacy Linux - Newbie 1 07-25-2006 02:28 AM
FTP Command For Overwrite kegwell Linux - General 0 07-18-2004 02:25 PM
FREE Coloured custom command prompts!!!!! =) Hegemon Linux - General 8 01-20-2003 04:34 PM


All times are GMT -5. The time now is 02:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration