bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#18681: cp Specific fail example


From: Bob Proulx
Subject: bug#18681: cp Specific fail example
Date: Fri, 10 Oct 2014 17:36:16 -0600
User-agent: Mutt/1.5.23 (2014-03-12)

Polehn, Mike A wrote:
> Did a search for 'cp -I' and found it for root:
> 
> address@hidden ~]# find /root -type f -print |xargs grep -Hn "cp i"
> /root/.bashrc:6:alias cp='cp -i'
> /root/.cshrc:6:alias cp 'cp -i'
> /root/.tcshrc:6:alias cp 'cp -i'

It might be easier to guess that there is an alias and look for it. :-)

  # alias cp
  alias cp='cp -i'

  # type cp
  ls is aliased to `cp -i'

> But there is still an error for interactive:
> 
> address@hidden src]# cp -f -r dpdk-1.7.1/* dpdk/

Since you know that "cp" in the above is "cp -i" then you know the
command is actually "cp -i -f -r dpdk-1.7.1/* dpdk/" which you don't
want there.  Try it without the alias in play.

The normal way in a /bin/sh derived environment is to simply quote the
command.  If you quote the command then it won't do alias expansion.
The usual method of quoting is with a backslash.

  # \cp -f -r dpdk-1.7.1/* dpdk/

However the canonical method is to use "env" since the above doesn't
work in csh derived shells.  Therefore you will find suggestions to
use env to wrap the command and avoid alias expansion like this.  It
is often offered when we don't know if you are using a sh or csh
derived command line shell.  (This env trick is one I learned on this
list some years ago.)

  # env cp -f -r dpdk-1.7.1/* dpdk/

And of course you can always unalias the command too.

  # unalias cp

> It is a good idea as root not to be overwriting files, so I can
> understand the "cp -i" usage for root.

Personally I simply realize that the tools are sharp kitchen knives
and I always handle sharp kitchen knives carefully.  Trying to put
safety shields on them simply gets in the way.  It tends to cause
problems such as you are seeing here.  I usually remove those aliases
on systems I administer.

> However, some of the reason for using root is to do something that
> you may not be able to do as a normal user. So being able to
> override the -i with a -f would be highly desirable.

Right.  And you can.  You have the power.  Just do it.  By avoiding
the alias with \cp (or the env trick) and then you won't have the -i
in play.  Or remove the alias from the environment.

There is the burden upon the root superuser that they have great
power.  With great power comes great responsibility.  Being root means
you are a pilot not a passenger.  There is an old saying in flying,
"Fly the airplane.  Don't let the airplane fly you."  Hopefully the
meaning is obvious even to the non-pilot.

Meanwhile...  I would be one of those suggesting that perhaps you
should try using rsync instead of cp.  The cp command is lean and mean
by comparison to rsync (and should stay that way).  But rsync has many
attractive features for doing large copies.

Bob





reply via email to

[Prev in Thread] Current Thread [Next in Thread]