Tips for remembering the order of parameters for ln?

I go by "ln is like cp. The 'source' needs to come first."


I use the following: ln has a one-argument form (2nd form listed in the manpage) in which only the target is required (because how could ln work at all without knowing the target) and ln creates the link in the current directory. The two-argument form is an addition to the one-argument form, thus the target is always the first argument.


Most Unices document the ln command as

ln source target

(I'm omitting options etc. here)

Examples:

  • The POSIX standard

    ln [-fs] [-L|-P] source_file target_file
    
  • OpenBSD:

    ln [-fhLnPs] source [target]
    
  • NetBSD and FreeBSD

    ln [-L | -P | -s [-F]] [-f | -iw] [-hnv] source_file [target_file]
    
  • macOS

    ln [-Ffhinsv] source_file [target_file]
    
  • Solaris

    /usr/bin/ln [-fns] source_file [target]
    
  • AIX

    ln [ -f | -n ] [ -s ] SourceFile [ TargetFile ]
    

The GNU ln manual calls the source target and the target linkname.

  • GNU manual for ln

    ln [option]… [-T] target linkname
    

Ignoring the GNU choice of words, the ln utility follows the same sort of semantics as e.g. mv and cp in that the target is what is created from the source.

Therefore,

ln -s a b

would create the symbolic link b pointing to a.

Note also that when creating symbolic links, the source is simply a string representing what the symbolic link should point at. There is usually no check made to validate that it points to anything useful:

$ ln -s "hello world" README.txt
$ ls -l
total 0
lrwxr-xr-x  1 kk  wheel  11 Sep 15 11:39 README.txt -> hello world

Tags:

Symlink

Ln