GNU bug report logs -
#16889
erratic behavior of cp command i.e while copying files (using *) from one directory to another directory
Previous Next
Reported by: Anil Kumar <linuxdeveloper7 <at> gmail.com>
Date: Wed, 26 Feb 2014 16:45:01 UTC
Severity: normal
Tags: notabug
Done: Pádraig Brady <P <at> draigBrady.com>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
tag 16889 notabug
close 16889
thanks
On 02/26/2014 01:36 PM, Anil Kumar wrote:
> I have observed, one erratic behavior of cp command i.e while copying
> files (using *) from one directory to another directory if
> we miss destination directory then cp command copies content of 1st
> file into 2nd file of same source directory instead of giving any
> error.
Thanks for the bug report, however, there's nothing we can
do about this in coreutils cp(1). See below.
> Here is the scenario:
>
> #ls -l
> total 8
> drwxr-xr-x 2 root root 4096 Feb 26 17:34 ddir
> drwxr-xr-x 2 root root 4096 Feb 26 17:36 sdir
>
>
> # echo "hello" > sdir/hello.txt
> # echo "bye" > sdir/bye.txt
>
> # cat sdir/hello.txt
> hello
>
> # cat sdir/bye.txt
> bye
>
> # cp sdir/*.txt
>
> # cat sdir/hello.txt
> bye
>
> # cat sdir/bye.txt
> bye
The point is that cp(1) does not even see the '*.txt' pattern.
Instead, the invoking shell substitutes the pattern and passes
the actual file names to 'cp'.
To get and idea what happens, you can put echo before 'cp':
$ echo cp sdir/*.txt
cp sdir/bye.txt sdir/hello.txt
Given the above command, cp detects that both files are regular
files, and therefore copies the content of sdir/bye.txt to
sdir/hello.txt.
BTW: this case is similar to the one explained in our FAQ:
http://www.gnu.org/software/coreutils/faq/coreutils-faq.html#ls-_002da-_002a-does-not-list-dot-files
As this is desired behavior, I'm tagging this issue as not a bug,
and I'm marking it as done.
If there are still open points, feel free to continue the discussion.
Have a nice day,
Berny
This bug report was last modified 11 years and 143 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.