bug-coreutils
[Top][All Lists]
Advanced

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

bug#20603: Possible bug in cp


From: Bernhard Voelker
Subject: bug#20603: Possible bug in cp
Date: Tue, 19 May 2015 08:02:50 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0

On 05/19/2015 07:21 AM, Chris Puttick wrote:
> The expansion & consequences of my typo understood! However, given the
> risks inherent in this edge case (directory only has 2 files in it)
> and the unlikelihood of someone wanting to change a directory
> containing 2 different files into a directory containing 2 identical
> but differently named files, it would be great if the cp command to
> check, when the source and destination directories are the same, the
> file count in that directory and issue a warning before continuing if
> the file count =2.

If there was such a check, a warning wouldn't have helped you - as
the command would have proceeded with overwriting the file anyway.
Second, how should cp know when the user really wants to do that?
We'd have to special case this, too.  Third, such a check would be
racy.  After all, we won't add such a construct.  cp(1) performed
exactly the option you told it to do.

But there is other help:
I rather suggest that you to consider using the -n or -i option:

  -i, --interactive            prompt before overwrite (overrides a previous -n
                                  option)

  -n, --no-clobber             do not overwrite an existing file (overrides
                                 a previous -i option)

You can even set an alias for it like this in your profile:
  alias cp='\cp -n'

Or, if in doubt, pass the command line to echo before executing,
by which you would see what would happen:

  $ echo cp /some/dir/file*
  cp /some/dir/file1 /some/dir/file2

Have a nice day,
Berny





reply via email to

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