0

By way of example, I have a directory structure like this:

$ \ls -F
dir/  lnk@

$ \ls -F dir
FILE

$ \ls -l lnk
lrwxrwxrwx 1 user group d Mon hh:mm lnk -> dir

My ls command is aliased. I am using \ls to get standard behavior (I think).

The question is

When using the -F option with ls, why does appending a slash to the symlink name affect the behavior of ls?

$ \ls -F lnk
lnk@

\ls -F lnk/
FILE

Without the /, the symlink itself is listed with an @ indicator/flag/classifier; with the /, the files in the directory that the symlink references are listed with indicators (FILE is a regular file).

I'm not sure whether to call the behavior with no options consistent or inconsistent:

$ \ls lnk
FILE

\ls lnk/
FILE

I am not finding an explanation for this in man ls.

Similar Posts

Using ls command with symbolic links

Show contents of symbolic link

References

Trailing slashes on symbolic links to directories

The IEEE and the Open Group (2004) "Pathname Resolution" subsection 4.11 in The Open Group Base Specifications Issue 6

The IEEE and the Open Group (2018a) "Pathname Resolution" subsection 4.13 in The Open Group Base Specifications Issue 7

The IEEE and the Open Group (2018b) "ls"

3
  • @KamilMaciorowski RE "Trailing slashes on..." yes, partially.
    – Ana Nimbus
    Commented Oct 20, 2022 at 13:15
  • The texts you quote under "Postscript" seem to tell the answer. You could post those as an actual answer below.
    – ilkkachu
    Commented Oct 20, 2022 at 15:30
  • 1
    @ilkkachu Re "...post those as an actual answer...": DONE.
    – Ana Nimbus
    Commented Oct 20, 2022 at 17:56

2 Answers 2

2

In short, because lnk and lnk/ refer to different files.

The Long Answer

After reviewing IEEE and The Open Group (2018a), It seems my question misunderstood pathname resolution. In particular: 1) lnk/ is equivalent to lnk/. Therefore lnk and lnk/ name different files.

If a symbolic link is encountered during pathname resolution, the behavior shall depend on whether the pathname component is at the end of the pathname and on the function being performed.

Although I do not find the behavior of \ls -F lnk or \ls lnk specified in the man page, I do find it in The IEEE and the Open Group (2018b):

If one or more of the -d, -F, or -l options are specified, and neither the -H nor the -L option is specified, for each operand that names a file of type symbolic link to a directory, ls shall write the name of the file as well as any requested, associated information. If none of the -d, -F, or -l options are specified, or the -H or -L options are specified, for each operand that names a file of type symbolic link to a directory, ls shall write the names of files contained within the directory as well as any requested, associated information.

0

Do not know the official answer, but:

  • There is a name "lnk" in the directory. I do not know what that is.
  • ls -F lnk - Show me a type of that name
  • ls -F lnk/ - Here is a path, show me all files in the specified path, with type marks
  • ls lnk/ - Here is a path, show me all files in the specified path
  • ls lnk - I allow OS to determine what that file is and asking to show the most logical info for it

Please note: I do not care in this case is it a link or not. I am thinking in terms of "name" and "path" only.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .