Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

On the regular file.

6 views
Skip to first unread message

Hongyi Zhao

unread,
Apr 12, 2015, 2:57:00 AM4/12/15
to
Hi all,

Then `man test' give the following notes:

---------------------------
-e FILE
FILE exists
-f FILE
FILE exists and is a regular file
-h FILE
FILE exists and is a symbolic link (same as -L)
-L FILE
FILE exists and is a symbolic link (same as -h)
----------------------------

In the above description, -h/-L are used for justification a symbolic
link; but I've tried the -f/-e for both a file and its symbolic link,
they will return true for both case.

So what's the meaning of `a regular file' in this context?

Regards
--
.: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.

Janis Papanagnou

unread,
Apr 12, 2015, 3:18:23 AM4/12/15
to
On 12.04.2015 08:56, Hongyi Zhao wrote:
> Hi all,
>
> Then `man test' give the following notes:
>
> ---------------------------
> -e FILE
> FILE exists
> -f FILE
> FILE exists and is a regular file
> -h FILE
> FILE exists and is a symbolic link (same as -L)
> -L FILE
> FILE exists and is a symbolic link (same as -h)
> ----------------------------
>
> In the above description, -h/-L are used for justification a symbolic
> link; but I've tried the -f/-e for both a file and its symbolic link,
> they will return true for both case.
>
> So what's the meaning of `a regular file' in this context?

I interpret it as:
-e is a general test (that is true also for, e.g., directories)
-f there's a regular file behind that name (either directly or
indirectly through a link)."
-h/-L (not sure there is any difference between those two), but
this is a further specialization, specifically to test
symbolic links

So you have a test hierarchy (more generlized or more specialized):
-e
-f
-h
-L
-d
...


Janis

>
> Regards
>

Hongyi Zhao

unread,
Apr 12, 2015, 3:59:08 AM4/12/15
to
Thanks a lot for your hints.

It's my first time to know that the `-e' can test a directory. And I've
tried it and the result is *yes*!

Regards

>
>
> Janis

Thomas 'PointedEars' Lahn

unread,
Apr 12, 2015, 6:49:41 AM4/12/15
to
Hongyi Zhao wrote:

> Then `man test' give the following notes:
>
> ---------------------------
> -e FILE
> FILE exists
> -f FILE
> FILE exists and is a regular file
> -h FILE
> FILE exists and is a symbolic link (same as -L)
> -L FILE
> FILE exists and is a symbolic link (same as -h)
> ----------------------------
>
> In the above description, -h/-L are used for justification a symbolic
> link;

_detection_, not justification

> but I've tried the -f/-e for both a file and its symbolic link,
> they will return true for both case.

No, the “test” command _exits with a status code of success_ in both cases,
most certainly 0 (as that is required by POSIX).

> So what's the meaning of `a regular file' in this context?

In Unix/POSIX, *everything* is a file – including directories. “Regular
files” are files that are neither ([symbolic] links to) directories nor
([symbolic] links to) special files (like *b*lock special files/devices such
as /dev/sda, and *c*haracter special files/devices such as /dev/null):

<http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_164>

You are getting the same result for a regular file and a symlink (symbolic
link) to it with “-f” because then test(1) resolves the symlink to the
regular file. On a symlink to a directory or /dev/null (character device),
my “test -f” (on Debian GNU/Linux, a Bash built-in) exits with status 1
(failure = “not a regular file”). This is POSIX-compliant behavior:

<http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html>

--
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.

Kaz Kylheku

unread,
Apr 12, 2015, 9:57:07 AM4/12/15
to
On 2015-04-12, Hongyi Zhao <hongy...@gmail.com> wrote:
> link; but I've tried the -f/-e for both a file and its symbolic link,
> they will return true for both case.
>
> So what's the meaning of `a regular file' in this context?

On my Ubuntu system, the man page goes on to say this:

"Except for -h and -L, all FILE-related tests dereference symbolic links."

Hongyi Zhao

unread,
Apr 12, 2015, 10:00:13 AM4/12/15
to
Thanks a lot for you notes.
0 new messages