GNU bug report logs -
#20603
Possible bug in cp
Previous Next
Reported by: Chris Puttick <cputtick <at> gmail.com>
Date: Mon, 18 May 2015 15:45:06 UTC
Severity: normal
Tags: notabug
Done: Assaf Gordon <assafgordon <at> gmail.com>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
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
This bug report was last modified 6 years and 219 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.