From unknown Fri Jun 20 07:24:24 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#18179 <18179@debbugs.gnu.org> To: bug#18179 <18179@debbugs.gnu.org> Subject: Status: stat doesn't dereference symlinked file name Reply-To: bug#18179 <18179@debbugs.gnu.org> Date: Fri, 20 Jun 2025 14:24:24 +0000 retitle 18179 stat doesn't dereference symlinked file name reassign 18179 coreutils submitter 18179 Tomasz Pala severity 18179 normal tag 18179 notabug thanks From debbugs-submit-bounces@debbugs.gnu.org Sun Aug 03 05:40:21 2014 Received: (at submit) by debbugs.gnu.org; 3 Aug 2014 09:40:21 +0000 Received: from localhost ([127.0.0.1]:55616 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XDsH5-0006aL-UJ for submit@debbugs.gnu.org; Sun, 03 Aug 2014 05:40:20 -0400 Received: from eggs.gnu.org ([208.118.235.92]:49040) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XDrxq-00066Q-1c for submit@debbugs.gnu.org; Sun, 03 Aug 2014 05:20:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XDrxf-0004z5-1u for submit@debbugs.gnu.org; Sun, 03 Aug 2014 05:20:20 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=BAYES_40 autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:49753) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XDrxe-0004yz-Uf for submit@debbugs.gnu.org; Sun, 03 Aug 2014 05:20:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50751) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XDrxa-00007o-0O for bug-coreutils@gnu.org; Sun, 03 Aug 2014 05:20:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XDrxU-0004ry-Vh for bug-coreutils@gnu.org; Sun, 03 Aug 2014 05:20:09 -0400 Received: from pepin.polanet.pl ([193.34.52.2]:59476) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XDrxU-0004nL-QJ for bug-coreutils@gnu.org; Sun, 03 Aug 2014 05:20:04 -0400 Received: by pepin.polanet.pl (Postfix, from userid 1090) id A829E3AEDFFF; Sun, 3 Aug 2014 11:20:01 +0200 (CEST) Date: Sun, 3 Aug 2014 11:20:01 +0200 From: Tomasz Pala To: bug-coreutils@gnu.org Subject: stat doesn't dereference symlinked file name Message-ID: <20140803092001.GA24140@polanet.pl> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-2 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] 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: -4.1 (----) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Sun, 03 Aug 2014 05:40:18 -0400 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: -4.1 (----) ~: touch a ~: ln -s a b ~: stat -c "%n" a a ~: stat -c "%n" b b ~: stat -Lc "%n" b b the last command should return 'a'. To be more verbose: ~: stat b File: `b' -> `a' Size: 1 Blocks: 0 IO Block: 4096 symbolic link Device: 10h/16d Inode: 60112068 Links: 1 ~: stat -L b File: `b' Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: 10h/16d Inode: 60112022 Links: 1 [...] one cannot get the righthand part of dereference only (the same applies to %N). -- Tomasz Pala From debbugs-submit-bounces@debbugs.gnu.org Sun Aug 03 17:39:37 2014 Received: (at 18179) by debbugs.gnu.org; 3 Aug 2014 21:39:37 +0000 Received: from localhost ([127.0.0.1]:56339 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XE3VA-0001j1-M8 for submit@debbugs.gnu.org; Sun, 03 Aug 2014 17:39:36 -0400 Received: from joseki.proulx.com ([216.17.153.58]:41251) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XE3V8-0001ip-Jv; Sun, 03 Aug 2014 17:39:35 -0400 Received: from hysteria.proulx.com (hysteria.proulx.com [192.168.230.119]) by joseki.proulx.com (Postfix) with ESMTP id A977F21835; Sun, 3 Aug 2014 15:39:33 -0600 (MDT) Received: by hysteria.proulx.com (Postfix, from userid 1000) id 983952DC3B; Sun, 3 Aug 2014 15:39:33 -0600 (MDT) Date: Sun, 3 Aug 2014 15:39:33 -0600 From: Bob Proulx To: Tomasz Pala Subject: Re: bug#18179: stat doesn't dereference symlinked file name Message-ID: <20140803153314585532107@bob.proulx.com> References: <20140803092001.GA24140@polanet.pl> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20140803092001.GA24140@polanet.pl> User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 18179 Cc: 18179@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.7 (/) tag 18179 + notabug close 18179 thanks Thanks for the bug report. However this seems to be a misunderstanding of the available print formats. Tomasz Pala wrote: > ~: touch a > ~: ln -s a b > ~: stat -c "%n" a > a > ~: stat -c "%n" b > b > ~: stat -Lc "%n" b > b You need %N to show what you are wanting to show. $ stat -c %N b ‘b’ -> ‘a’ $ stat -Lc %N b ‘b’ > ~: stat -Lc "%n" b > b > the last command should return 'a'. Not quite. The %n returns the file name as handed to stat on the command line. To get the quoted name dereference if a symbolic link then you need the %N format. %N quoted file name with dereference if symbolic link > To be more verbose: > > ~: stat b > File: `b' -> `a' > Size: 1 Blocks: 0 IO Block: 4096 symbolic link > Device: 10h/16d Inode: 60112068 Links: 1 > > ~: stat -L b > File: `b' > Size: 0 Blocks: 0 IO Block: 4096 regular empty file > Device: 10h/16d Inode: 60112022 Links: 1 > [...] > > one cannot get the righthand part of dereference only (the same applies > to %N). I read the above part several times but your meaning was not clear. In any case I see no bug in stat. Perhaps you really want readlink? $ readlink b a $ readlink -f b /tmp/a For what I believe you are doing the typical idiom is to use "readlink" to print the value of the symbolic link. Bob From debbugs-submit-bounces@debbugs.gnu.org Mon Aug 04 14:33:44 2014 Received: (at 18179) by debbugs.gnu.org; 4 Aug 2014 18:33:44 +0000 Received: from localhost ([127.0.0.1]:57560 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XEN4p-00024X-KF for submit@debbugs.gnu.org; Mon, 04 Aug 2014 14:33:44 -0400 Received: from pepin.polanet.pl ([193.34.52.2]:51859) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XEN4m-000246-Jq for 18179@debbugs.gnu.org; Mon, 04 Aug 2014 14:33:42 -0400 Received: by pepin.polanet.pl (Postfix, from userid 1090) id 3958C3AEF200; Mon, 4 Aug 2014 20:33:34 +0200 (CEST) Date: Mon, 4 Aug 2014 20:33:34 +0200 From: Tomasz Pala To: Bob Proulx Subject: Re: bug#18179: stat doesn't dereference symlinked file name Message-ID: <20140804183333.GA31787@polanet.pl> References: <20140803092001.GA24140@polanet.pl> <20140803153314585532107@bob.proulx.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-2 Content-Disposition: inline In-Reply-To: <20140803153314585532107@bob.proulx.com> User-Agent: Mutt/1.5.20 (2009-06-14) X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 18179 Cc: 18179@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.7 (/) On Sun, Aug 03, 2014 at 15:39:33 -0600, Bob Proulx wrote: > misunderstanding of the available print formats. > >> ~: stat -Lc "%n" b >> b > > You need %N to show what you are wanting to show. No, I've mentioned %N later and it's just a shortcut for general state: while dereferencing symlink, all the information come from dereferenced file _except_ it's name. ~: ln -s a b ~: stat -L b File: `b' Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: ah/10d Inode: 26596 Links: 1 Access: (0600/-rw-------) Uid: ( 500/ gotar) Gid: ( 500/ gotar) Access: 2014-08-04 20:12:40.008000499 +0200 Modify: 2014-08-04 20:12:40.008000499 +0200 Change: 2014-08-04 20:12:40.008000499 +0200 Inode 26596 contains file 'a', stat doesn't dereference file name. >> ~: stat -Lc "%n" b >> b >> the last command should return 'a'. > > Not quite. The %n returns the file name as handed to stat on the > command line. But I've ordered to dereference that symlink (-L) first. What makes %n (and only %n) to behave differently than %s or all the other sequences? In different words: what makes %n to evaluate _before_ dereference (-L) unike all the other sequences, which are evaluated _after_? > To get the quoted name dereference if a symbolic link > then you need the %N format. > > %N quoted file name with dereference if symbolic link The problem with %N is: when dereferencing with -L switch, it doesn't work as described: ~: stat -c "%N" b `b' -> `a' ~: stat -Lc "%N" b `b' The later one should print righthand part of the symlink. Anyway, I don't want the quoted filename (especially useless `like this'), I need simply the name. %N is all about quoting and printing reference. > Perhaps you really want readlink? No, as it operates on symlinks only, and I need to get real file. Just take a look at this: ~: stat -c "%n" b b <- this is expected ~: stat -Lc "%n" b b <- this is not, -L is not effective What's the point of returning the same data twice? None. ~: stat -c "%N" b `b' -> `a' <- like described in manual ~: stat -Lc "%N" b `b' <- definitely wrong, where's the dereference value? Notice, I've used 4 different options and got 4 times 'b' and just one 'a' - this itself indicates a problem. best regards, -- Tomasz Pala From unknown Fri Jun 20 07:24:24 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Tue, 02 Sep 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