From debbugs-submit-bounces@debbugs.gnu.org Wed Feb 26 11:44:53 2014 Received: (at submit) by debbugs.gnu.org; 26 Feb 2014 16:44:53 +0000 Received: from localhost ([127.0.0.1]:41491 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WIhbI-0002PA-0s for submit@debbugs.gnu.org; Wed, 26 Feb 2014 11:44:52 -0500 Received: from eggs.gnu.org ([208.118.235.92]:34170) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WIdjR-0003wR-4F for submit@debbugs.gnu.org; Wed, 26 Feb 2014 07:37:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WIdjQ-0004ju-1b for submit@debbugs.gnu.org; Wed, 26 Feb 2014 07:37:00 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.3 required=5.0 tests=BAYES_40, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:50828) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WIdjP-0004jp-VN for submit@debbugs.gnu.org; Wed, 26 Feb 2014 07:36:59 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35886) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WIdjP-0001DR-51 for bug-coreutils@gnu.org; Wed, 26 Feb 2014 07:36:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WIdjM-0004ih-DS for bug-coreutils@gnu.org; Wed, 26 Feb 2014 07:36:59 -0500 Received: from mail-ie0-x230.google.com ([2607:f8b0:4001:c03::230]:34355) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WIdjM-0004hd-7G for bug-coreutils@gnu.org; Wed, 26 Feb 2014 07:36:56 -0500 Received: by mail-ie0-f176.google.com with SMTP id y20so70402ier.7 for ; Wed, 26 Feb 2014 04:36:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=trsDjY20mXOcZLWVuxGHLOlQmxZb99ocYsPEEcbirYg=; b=NooxNbtzgUO96QRwxYHoprGIyK41fiDiQe8Gtlej5JvbyMZBP0zhcsN8CGBaBj6E31 Mzut+waHAN9kiUmEFUGUP9LnCf456E5SPW8+yT9f81zIEPS6D8G+u1Orj9W9/VhqXVeC UWO65qCF1OW+9wO55AdORimA4TYnJNrd9kptzxuOZf+WZbMSa/F8oUxCxaQFMP75kVLI A4zPIK/wirUTmcN4HdllJf9hUZAfJCtUGOY+SaMpWVcS6sn8AuLQJGhsVFTU/bUKET3V OCGRu+csYdjJVu55kW1hVftRdjvO6V04crty/AP1uMZ/hhzXUCGByltPQGwswIIKNChY 8WxA== MIME-Version: 1.0 X-Received: by 10.50.73.199 with SMTP id n7mr2526119igv.35.1393418215000; Wed, 26 Feb 2014 04:36:55 -0800 (PST) Received: by 10.64.243.6 with HTTP; Wed, 26 Feb 2014 04:36:54 -0800 (PST) Date: Wed, 26 Feb 2014 18:06:54 +0530 Message-ID: Subject: erratic behavior of cp command i.e while copying files (using *) from one directory to another directory From: Anil Kumar To: bug-coreutils@gnu.org Content-Type: text/plain; charset=ISO-8859-1 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -3.8 (---) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Wed, 26 Feb 2014 11:44:50 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.8 (---) 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. Here is strace output command "strace cp sdir/*" stat("sdir/hello.txt", {st_mode=S_IFREG|0644, st_size=6, ...}) = 0 stat("sdir/bye.txt", {st_mode=S_IFREG|0644, st_size=4, ...}) = 0 stat("sdir/hello.txt", {st_mode=S_IFREG|0644, st_size=6, ...}) = 0 open("sdir/bye.txt", O_RDONLY) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=4, ...}) = 0 open("sdir/hello.txt", O_WRONLY|O_TRUNC) = 4 fstat(4, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0 fadvise64(3, 0, 0, POSIX_FADV_SEQUENTIAL) = 0 read(3, "bye\n", 65536) = 4 write(4, "bye\n", 4) = 4 read(3, "", 65536) = 0 close(4) = 0 close(3) = 0 lseek(0, 0, SEEK_CUR) = -1 ESPIPE (Illegal seek) close(0) = 0 close(1) = 0 close(2) = 0 exit_group(0) = ? From debbugs-submit-bounces@debbugs.gnu.org Wed Feb 26 11:57:39 2014 Received: (at 16889) by debbugs.gnu.org; 26 Feb 2014 16:57:39 +0000 Received: from localhost ([127.0.0.1]:41540 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WIhnf-0002p1-7G for submit@debbugs.gnu.org; Wed, 26 Feb 2014 11:57:39 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47644) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WIhnc-0002op-Lo; Wed, 26 Feb 2014 11:57:37 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s1QGvXJL021679 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 26 Feb 2014 11:57:34 -0500 Received: from [10.36.116.81] (ovpn-116-81.ams2.redhat.com [10.36.116.81]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s1QGvVGI004434 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 26 Feb 2014 11:57:33 -0500 Message-ID: <530E1CFB.2010209@draigBrady.com> Date: Wed, 26 Feb 2014 16:57:31 +0000 From: =?ISO-8859-1?Q?P=E1draig_Brady?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 MIME-Version: 1.0 To: Anil Kumar Subject: Re: bug#16889: erratic behavior of cp command i.e while copying files (using *) from one directory to another directory References: In-Reply-To: X-Enigmail-Version: 1.6 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: 16889 Cc: 16889@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) 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. From debbugs-submit-bounces@debbugs.gnu.org Wed Feb 26 12:03:13 2014 Received: (at submit) by debbugs.gnu.org; 26 Feb 2014 17:03:13 +0000 Received: from localhost ([127.0.0.1]:41550 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WIht2-0004Ak-MQ for submit@debbugs.gnu.org; Wed, 26 Feb 2014 12:03:13 -0500 Received: from eggs.gnu.org ([208.118.235.92]:34832) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WIdnq-00044I-FZ for submit@debbugs.gnu.org; Wed, 26 Feb 2014 07:41:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WIdnp-0006Eh-9h for submit@debbugs.gnu.org; Wed, 26 Feb 2014 07:41:34 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: * X-Spam-Status: No, score=1.1 required=5.0 tests=BAYES_50, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:50204) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WIdnp-0006Ec-6g for submit@debbugs.gnu.org; Wed, 26 Feb 2014 07:41:33 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36532) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WIdno-0002G8-1T for bug-coreutils@gnu.org; Wed, 26 Feb 2014 07:41:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WIdnm-0006Dd-T8 for bug-coreutils@gnu.org; Wed, 26 Feb 2014 07:41:31 -0500 Received: from mail-ig0-x235.google.com ([2607:f8b0:4001:c05::235]:51829) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WIdnm-0006DU-Nx for bug-coreutils@gnu.org; Wed, 26 Feb 2014 07:41:30 -0500 Received: by mail-ig0-f181.google.com with SMTP id h18so600219igc.2 for ; Wed, 26 Feb 2014 04:41:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=tlezgp+/UuVLPIVVQUWK7X57aDCBD2yPzJq8iZ/TGmM=; b=onWwBEL+uHKZDPda/geFrO2McG17jikWDhjOxdrYmtHcbpa7W7o/7dv0OkWz3Q3WJ0 xs/KXhdEa2okrqnjMe+uZL7d/iiKBwdwFUeA+tziRR1T4cjxrIfsHD3wYIeG6nyPJeym 0fR1DxWEpaRppy8fjwR7LF+7HguLf1rtFWp9MOJ8SJjImRb0R+WU40KhUopu6ukMLzJY Adrh7RPcB2ZGGi37H/Vod1eo3e8Sl9APxGpwRN1A9xzUYTapiY1xGKJTTUWb/HiXzy7a /f7msjpcLKkXkFF4VGs9Xzv+U+BuJSD5O5/yoNOILlXhVA9bHpLK1be+nD4VGIAYIyNq uyKA== MIME-Version: 1.0 X-Received: by 10.42.246.8 with SMTP id lw8mr4950656icb.22.1393418490069; Wed, 26 Feb 2014 04:41:30 -0800 (PST) Received: by 10.64.243.6 with HTTP; Wed, 26 Feb 2014 04:41:30 -0800 (PST) In-Reply-To: References: Date: Wed, 26 Feb 2014 18:11:30 +0530 Message-ID: Subject: Re: erratic behavior of cp command i.e while copying files (using *) from one directory to another directory From: Anil Kumar To: bug-coreutils@gnu.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -3.8 (---) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Wed, 26 Feb 2014 12:03:11 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.8 (---) Here is version info of cp command =3D=3D=3D=3D=3D=3D=3D cp --version cp (GNU coreutils) 8.20 Copyright (C) 2012 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later . This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Written by Torbj=F6rn Granlund, David MacKenzie, and Jim Meyering.' On Wed, Feb 26, 2014 at 6:06 PM, Anil Kumar wro= te: > 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. > > Here is strace output command "strace cp sdir/*" > > stat("sdir/hello.txt", {st_mode=3DS_IFREG|0644, st_size=3D6, ...}) =3D 0 > stat("sdir/bye.txt", {st_mode=3DS_IFREG|0644, st_size=3D4, ...}) =3D 0 > stat("sdir/hello.txt", {st_mode=3DS_IFREG|0644, st_size=3D6, ...}) =3D 0 > open("sdir/bye.txt", O_RDONLY) =3D 3 > fstat(3, {st_mode=3DS_IFREG|0644, st_size=3D4, ...}) =3D 0 > open("sdir/hello.txt", O_WRONLY|O_TRUNC) =3D 4 > fstat(4, {st_mode=3DS_IFREG|0644, st_size=3D0, ...}) =3D 0 > fadvise64(3, 0, 0, POSIX_FADV_SEQUENTIAL) =3D 0 > read(3, "bye\n", 65536) =3D 4 > write(4, "bye\n", 4) =3D 4 > read(3, "", 65536) =3D 0 > close(4) =3D 0 > close(3) =3D 0 > lseek(0, 0, SEEK_CUR) =3D -1 ESPIPE (Illegal seek) > close(0) =3D 0 > close(1) =3D 0 > close(2) =3D 0 > exit_group(0) =3D ? From debbugs-submit-bounces@debbugs.gnu.org Wed Feb 26 12:10:59 2014 Received: (at 16889) by debbugs.gnu.org; 26 Feb 2014 17:10:59 +0000 Received: from localhost ([127.0.0.1]:41554 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WIi0Z-0004NA-2h for submit@debbugs.gnu.org; Wed, 26 Feb 2014 12:10:59 -0500 Received: from moutng.kundenserver.de ([212.227.126.131]:62605) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WIi0W-0004My-Lt for 16889@debbugs.gnu.org; Wed, 26 Feb 2014 12:10:57 -0500 Received: from [10.0.2.15] (gw.camline.com [62.153.148.194]) by mrelayeu.kundenserver.de (node=mreue005) with ESMTP (Nemesis) id 0LvNfb-1XICpJ30rb-010ZxR; Wed, 26 Feb 2014 18:10:54 +0100 Message-ID: <530E201E.4040304@bernhard-voelker.de> Date: Wed, 26 Feb 2014 18:10:54 +0100 From: Bernhard Voelker User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 MIME-Version: 1.0 To: Anil Kumar , 16889@debbugs.gnu.org Subject: Re: bug#16889: erratic behavior of cp command i.e while copying files (using *) from one directory to another directory References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:bbn08p4TL9axLqtIW4OumZ3EW95UX3ZvTOJmkX7Zwaj GpXfEzP+CV9yZFX8L+6+HrbgxJrVSox1PStXBXDzpKzIRZ78Cs oTzdAeO9kCAtE8TEy5S2kViGCE/OHYkEnTuIHscg/UrPixCHHI WpcJs0Mpi/ZLCODJS6Ko0ZAKw8Ykrf1uEdVhcgbw5RtUL4IMQG Vxdu1eRRoBMpbgvbCEVPOC8a9AEu6W78JUnYj9YMufLTj4exLB Mv2UelELp7QwuJmavCBKSNV+pQqmydYskDvuzGnhhWzf0Utce/ wfiI1sooIM9dlfFsgYMDErpYFDXDjJqtHcS6ZvasYi4xHwsA2U cY/ujK8i+tldPrup5/Hs8kzi0heJr0UztWDrIaL0B X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 16889 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) 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 From debbugs-submit-bounces@debbugs.gnu.org Wed Feb 26 14:53:13 2014 Received: (at 16889) by debbugs.gnu.org; 26 Feb 2014 19:53:13 +0000 Received: from localhost ([127.0.0.1]:41818 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WIkXZ-0004FZ-2y for submit@debbugs.gnu.org; Wed, 26 Feb 2014 14:53:13 -0500 Received: from joseki.proulx.com ([216.17.153.58]:59291) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WIkXV-0004FP-OL for 16889@debbugs.gnu.org; Wed, 26 Feb 2014 14:53:10 -0500 Received: from hysteria.proulx.com (hysteria.proulx.com [192.168.230.119]) by joseki.proulx.com (Postfix) with ESMTP id 4061821228; Wed, 26 Feb 2014 12:53:08 -0700 (MST) Received: by hysteria.proulx.com (Postfix, from userid 1000) id 0D7B72DC8A; Wed, 26 Feb 2014 12:53:07 -0700 (MST) Date: Wed, 26 Feb 2014 12:53:07 -0700 From: Bob Proulx To: Anil Kumar Subject: Re: bug#16889: erratic behavior of cp command i.e while copying files (using *) from one directory to another directory Message-ID: <20140226195307.GA4344@hysteria.proulx.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 16889 Cc: 16889@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) 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. Others have already replied about this topic. But I wanted to mention the GNU extension -t, --target-directory=DIRECTORY option. The documentation says: ... cp [OPTION]... -t DIRECTORY SOURCE... * If the --target-directory (-t) option is given, or failing that if the last file is a directory and the --no-target-directory (-T) option is not given, cp copies each SOURCE file to the specified directory, using the SOURCEs names. -t DIRECTORY --target-directory=DIRECTORY Specify the destination DIRECTORY. *Note Target directory::. Using it can sometimes be useful at times to make commands simpler and more clear about what is wanted. This also allows the target directory to be specified with the command and an unknown number of files to follow on the command line. This is most useful when using commands such as 'find' and others. The documentation goes into some detail about using it that way. I will include the entire "Target directory" section at the bottom for further reference. Bob 2.8 Target directory ==================== The `cp', `install', `ln', and `mv' commands normally treat the last operand specially when it is a directory or a symbolic link to a directory. For example, `cp source dest' is equivalent to `cp source dest/source' if `dest' is a directory. Sometimes this behavior is not exactly what is wanted, so these commands support the following options to allow more fine-grained control: `-T' `--no-target-directory' Do not treat the last operand specially when it is a directory or a symbolic link to a directory. This can help avoid race conditions in programs that operate in a shared area. For example, when the command `mv /tmp/source /tmp/dest' succeeds, there is no guarantee that `/tmp/source' was renamed to `/tmp/dest': it could have been renamed to `/tmp/dest/source' instead, if some other process created `/tmp/dest' as a directory. However, if `mv -T /tmp/source /tmp/dest' succeeds, there is no question that `/tmp/source' was renamed to `/tmp/dest'. In the opposite situation, where you want the last operand to be treated as a directory and want a diagnostic otherwise, you can use the `--target-directory' (`-t') option. `-t DIRECTORY' `--target-directory=DIRECTORY' Use DIRECTORY as the directory component of each destination file name. The interface for most programs is that after processing options and a finite (possibly zero) number of fixed-position arguments, the remaining argument list is either expected to be empty, or is a list of items (usually files) that will all be handled identically. The `xargs' program is designed to work well with this convention. The commands in the `mv'-family are unusual in that they take a variable number of arguments with a special case at the _end_ (namely, the target directory). This makes it nontrivial to perform some operations, e.g., "move all files from here to ../d/", because `mv * ../d/' might exhaust the argument space, and `ls | xargs ...' doesn't have a clean way to specify an extra final argument for each invocation of the subject command. (It can be done by going through a shell command, but that requires more human labor and brain power than it should.) The `--target-directory' (`-t') option allows the `cp', `install', `ln', and `mv' programs to be used conveniently with `xargs'. For example, you can move the files from the current directory to a sibling directory, `d' like this: ls | xargs mv -t ../d -- However, this doesn't move files whose names begin with `.'. If you use the GNU `find' program, you can move those files too, with this command: find . -mindepth 1 -maxdepth 1 \ | xargs mv -t ../d But both of the above approaches fail if there are no files in the current directory, or if any file has a name containing a blank or some other special characters. The following example removes those limitations and requires both GNU `find' and GNU `xargs': find . -mindepth 1 -maxdepth 1 -print0 \ | xargs --null --no-run-if-empty \ mv -t ../d The `--target-directory' (`-t') and `--no-target-directory' (`-T') options cannot be combined. From unknown Fri Aug 15 18:15:53 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Thu, 27 Mar 2014 11:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator