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
stop
On 02/26/2014 12:36 PM, Anil Kumar wrote:
> Hello
>
> 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.
>
> 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
>
> [Anil] Not sure, why "cp sdir/*.txt" command has copied data of
> bye.txt into hello.txt ? I think, its not desired behavior.
> 'cp' command should have produced error e.g destination is missing etc .
>
> One more example of similar behavior:
> # echo "hello" > sdir/hello.txt
> # echo "bye" > sdir/bye.txt
>
> # cat sdir/hello.txt
> hello
>
> # cat sdir/bye.txt
> bye
>
> # cp sdir/*
>
> # cat sdir/hello.txt
> bye
>
> # cat sdir/bye.txt
> bye
>
> [Anil]Here again "bye" has been copied into hello.txt which is not
> desired behavior.
So cp doesn't expand the sdir/* itself.
The shell does that and just passes the separate arguments to cp.
This is a disadvantage of the globbing being done by the shell,
but there are advantages to.
thanks,
Pádraig.
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.