Hitachi

JP1 Version 11 JP1/Advanced Shell Description, User's Guide, Reference, and Operator's Guide 


8.4.20 ln command (creates a link file for a file or directory)

Syntax

Syntax 1
ln [-f] [-i] [-L] [-n] [-P] [-s] [-T] [-v] [--follow={yes | no}] 
   [--no-exist-directory] [--no-exist-file] link-destination-path-name ... [target]
Syntax 2
ln [-f] [-i] [-L] [-n] [-P] [-s] [-v] [--follow={yes | no}]
   [--no-exist-directory] [--no-exist-file] -t target-directory-name link-destination-path-name ...

Description

This command creates a link file for a file or directory. This command creates a hard link or symbolic link according to the specification of the -s option.

If you create a symbolic link with the ln command, the operation must be executed as a user having the administrative role for creating symbolic links. A user who has the administrative role for creating symbolic links cannot create a symbolic link. In addition, a user who does not have the administrative role for creating symbolic links cannot create a symbolic link in an environment where user account control (UAC) is enabled. When creating a symbolic link in an environment where UAC is enabled, the administrator privilege needs to be granted to assign to the user the administrative role for creating symbolic links.

For syntax 1, a link file is created for the path specified for the argument target. If the argument target is a directory, a link file is created in the directory.

For syntax 2, a link file is created in the target directory.

Arguments

-f

--force

If the file specified for the argument target already exists, a link file is created after removing the existing file.

If the command is specified with the -i option, the specification of the -i option will be valid.

However, you can enable the option that was last specified by specifying LAST for the ADSH_CMDLN_OPT_I_F environment variable.

-i

--interactive

If there is a file specified for the argument target, whether to delete the file is asked. If the reply character from the standard input starts with y or Y, the existing file is deleted and a link file is created. If other characters are used for the reply and the standard input cannot be used, the process is interrupted.

If this command is specified with the -f option, the specification of the -i option will be valid.

However, you can enable the option that was last specified by specifying LAST for the ADSH_CMDLN_OPT_I_F environment variable.

-L

--logical

If a symbolic link is specified for the argument link destination path name, the symbolic link is followed and a hard link for the entity indicated by the link destination is created. However, no hard link is created if the file the link destination points to does not exist.

This option is a valid option when creating a hard link. If this command is specified with the -s option, the specification is ignored.

If neither the -L option nor -P option are specified, the -L option is considered as being specified.

When the -L option and -P option are specified simultaneously, the options specified last become valid.

-n

--no-dereference

This is a meaningless option. The specification is ignored.

--follow={yes | no}

This is the option used for selecting the behavior when a symbolic link for a directory is specified for the argument target.

If yes is selected, the symbolic link for the directory specified for the argument target is followed and a link file is created in the directory of the link destination.

If no is specified, the symbolic link for the directory specified for the argument target is not followed and the option is handled as a link file name.

If the --follow option is not specified, yes is considered to be specified.

-P

--physical
  • In Windows, Linux, and Solaris

    If a symbolic link is specified for the argument link destination path name, a hard link for a the symbolic link itself is created without following the symbolic link.

    This option is a valid option when creating a hard link. If this command is specified with the -s option, the specification is ignored.

    If neither the -L option nor -P option are specified, the -L option is considered as being specified.

    When the -L option and -P option are specified simultaneously, the options specified last become valid.

  • In AIX and HP-UX

    The specification is ignored and the behavior will be the same as when the -L option has been specified.

-s

--symbolic

Creates a symbolic link for the file or directory specified as the argument link destination path name.

If the -s option is not specified, a hard link is created. However, the following hard links cannot be created:

  • The target specified for the argument link destination path name does not exist.

  • Hard links for a directory

  • In UNIX: Files having a different file system

  • In Windows: Files having a different drive letter

If the -s option is specified, a symbolic link is created.

In UNIX

A symbolic link can be created regardless of the existence of the target specified for the argument link destination path name.

In Windows

Symbolic links cannot be created if the target that is specified for the argument link destination path name does not exist. When creating a symbolic link in a state where the target specified for the argument link destination path name does not exist, specify the --no-exist-directory option or the --no-exist-file option.

The created hard link will inherit access permissions.

Access permissions for symbolic links that are created are as follows:

  • In UNIX: Grants full control to all users.

  • Windows: Grants full control to Everyone upon inheriting access permissions of the directory being created

-t target-directory-name

--target-directory = target-directory-name

Specify the directory for which the link file is to be created. If any of the following cases occurs, an error will result:

  • The target directory name is simultaneously specified with the -T option.

  • A path that is neither the directory nor a symbolic link for a directory has been specified for the target directory name.

  • A directory that does not exist has been specified for the target directory name.

  • This option has been specified multiple times.

-T

--no-target-directory

The symbolic link for the directory specified for the argument target is not followed and the option is handled as a link file name.

If any of the following conditions are met, an error occurs:

  • The directory having the same name as that specified for the argument target exists.

  • The target directory name is simultaneously specified with the -t option.

-v

--verbose

The argument link destination path name and the link file to be created are output to the standard output. The output formats are as follows:

  • When creating a hard link

    `Argument link destination path name' => `Link file to be created'

  • When creating a symbolic link

    `Argument link destination path name' -> `Link file to be created'

--no-exist-directory
In Windows

When this option is specified, a symbolic link for a directory is created if the file or directory specified for the argument link destination path name does not exist when creating a symbolic link.

Specify this option to create a symbolic link for the directory in advance in a state where a symbolic link pointing to the directory does not exist.

If any of the following conditions are met, this option is ignored:

- The file or directory specified for the argument link destination path exists.

- The -s option is not specified.

When the --no-exist-directory option and --no-exist-file option are specified simultaneously, the options specified last become valid.

In UNIX

The specification is ignored.

--no-exist-file
In Windows

When this option is specified, a symbolic link for a file is created if the file or directory specified for the argument link destination path name does not exist when creating a symbolic link.

Specify this option to create a symbolic link for the file in advance in a state where a symbolic link pointing to the file does not exist.

If any of the following conditions are met, this option is ignored:

- The file or directory specified for the argument link destination path exists.

- The -s option is not specified.

When the --no-exist-file option and --no-exist-directory option are specified simultaneously, the options specified last become valid.

In UNIX

The specification is ignored.

link-destination-path-name

Specify the file path name or directory path name that the link file being created will point to. Multiple link destination path names can be specified. When specifying 2 or more link destination path names, specify a directory for the argument target or specify a directory by using the -t option with syntax 2.

target

Specifies the link file name to be created or the directory name in which the link file will be created.

If a link file name is specified, the link file is created with the specified file name. If a name for the directory in which to create the link file is specified, a link file having the same name as the file specified for the argument link destination path name is created in the specified directory.

If the specification of the target is omitted, a link file is created in the current directory.

If a symbolic link for the directory is specified, track the symbolic link and create the symbolic link for the entity indicated by the link destination. However, the following options can be specified to handle the target as a link file name without following the symbolic link:

  • -T option

  • Specify no for the --follow option.

  • Specify No for the ADSH_CMDLN_FOLLOW environment variable.

Return codes

Return code

Meaning

0

Normal termination.

1 or more

Termination with an error.

Notes

Notes common to all platforms

Notes for the UNIX edition only

Hard links cannot be created for the following items:

Notes for the Windows edition only

Examples

Creating a hard link for a file.

C:\TEMP>%ADSH_OSCMD_DIR%ln test.txt hlink.txt

C:\TEMP>%ADSH_OSCMD_DIR%ls -l
total 714
-rw------- 2 Administrators  357 Jun 01 15:05 hlink.txt
-rw------- 2 Administrators  357 Jun 01 15:05 test.txt

Omitting the argument target and creating a hard link for a file.

C:\TEMP>%ADSH_OSCMD_DIR%ln testdir\new.txt
C:\TEMP>%ADSH_OSCMD_DIR%ls -l
total 3572
-rw------- 2 Administrators  3572 Jun 04 11:19 new.txt
drwx------ 1 Administrators       Jun 04 11:19 testdir

C:\TEMP>%ADSH_OSCMD_DIR%ls -l testdir
total 3572
-rw------- 2 70247321 3572 Jun 04 11:19 new.txt

Creating a symbolic link for a file.

C:\TEMP>%ADSH_OSCMD_DIR%ln -s test.txt slink.txt

C:\TEMP>%ADSH_OSCMD_DIR%ls -l
total 357
lrw------- 1 Administrators    0 Jun 01 15:07 slink.txt
-> test.txt -rw------- 1 Administrators  357 Jun 01 15:05 test.txt

Creating a symbolic link for a directory.

C:\TEMP>%ADSH_OSCMD_DIR%ln -s testdir slinkdir

C:\TEMP>%ADSH_OSCMD_DIR%ls -l
total 0
lrw------- 1 Administrators  0 Jun 01 15:08 slinkdir -> testdir
drwx------ 1 Administrators    Jun 01 15:05 testdir

The option error message is displayed. This message might vary depending on the platform in which the command is being executed. The following shows an example for Windows:

C:\TEMP>%ADSH_OSCMD_DIR%ln -z
ln:  illegal option -- z
usage:  ln [-f] [-i] [-L] [-n] [-P] [-s] [-T] [-v] [--follow={yes | no}]
          [--no-exist-directory] [--no-exist-file] linkpath ... [target]
          ln [-f] [-i] [-L] [-n] [-P] [-s] [-v] [--follow={yes | no}]
          [--no-exist-directory] [--no-exist-file] -t target_directory linkpath ...