A program that acts on the contents of a file always acts on the target, not on the symbolic link, because symbolic links have no contents of their own.
A program that acts on the metadata of a file (timestamps, owner, permissions, …) usually acts on the target, but some programs have options to act on the symbolic link instead (for example, chown -h
, touch -h
, …).
A program that acts on a directory entry usually acts on the symbolic link. Operations like renaming and deleting act on a directory entry, whatever it is. There are separate system calls to access the metadata (including the file type) of a file depending on whether the program wishes to follow symbolic links (stat
) or not (lstat
). Some programs that can act on any type of directory entry have options to tell them to act on the target instead of the link when they find a link. For example, many utilities that traverse directories recursively (find
, chown -R
, cp -R
, …) act on symbolic links by default, but follow all symbolic links if you pass the option -L
, and follow the symbolic links on the command line but not symbolic links to directories found during recursive traversal if you pass the option -H
.
If a filename has a trailing slash, then this forces the filename to be interpreted as a directory. If the name is a symbolic link, it will be followed. So mv mylk ~
moves whatever mylk
is (symbolic link or otherwise), while mv mylk/ ~
moves mylk
if it is a directory, or the target if mylk
is a symbolic link to a directory, and complains if mylk
is neither a directory nor a symbolic link to one. This general behavior