bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Does [ -f FILE ] have a bug on testing a symlink ?


From: Stephane Chazelas
Subject: Re: Does [ -f FILE ] have a bug on testing a symlink ?
Date: Tue, 10 Feb 2015 21:25:04 +0000
User-agent: Mutt/1.5.21 (2010-09-15)

2015-02-09 14:59:06 -0700, Bob Proulx:
[...]
> The idea is that symlinks should be completely transparent and
> invisible to most applications.  The idea is that when normal things
> are run they don't realize they are using a symlink.  Behavior would
> be exactly the same as if it were a regular file system link.  That is
> what is happening in your test case.  The symlink references an
> existing file, is a regular file and exists, therefore the status is
> true.
[...]

Note the discrepancy with "find" though.

With find, -type f will not match on symlinks to regular files
(unless you also use -L/-follow).

If you actually want to find regular files after resolving
symlinks, without resolving symlinks when walking down the
directory tree, that's where it becomes cumbersome.

POSIXly, you have to resort to the test command:

find . -exec test -f {} \; -print

With GNU find, you can use -xtype:

find . -xtype f

GNU find's -printf still doesn't give information on the target
of  the symlink.

-- 
Stephane



reply via email to

[Prev in Thread] Current Thread [Next in Thread]