ln—creates hard links to files

ln [options] source [dest]
ln [options] source… directory
Options:
[-bdfinsvF] [-S  backup-suffix] [-V {numbered,existing,simple}]
[--version-control={numbered,existing,simple}] [--backup]
[--directory] [--force][--interactive] [--no-dereference] [--symbolic]
[--verbose] [--suffix=backup-suffix] [--help] [--version]

If the last argument names an existing directory, ln links each other given file into a file with the same name in that directory. If only one file is given, it links that file into the current directory. Otherwise, if only two files are given, it links the first onto the second. It is an error if the last argument is not a directory and more than two files are given. Symbolic links are used if crossing a partition.

OPTIONS:

-b, --backup Makes backups of files that are about to be removed.
-d, -F, --directory Allows the superuser to make hard links to directories.
-f, --force Removes existing destination files.
i, --interactive Prompts whether to remove existing destination files.
-n, --no-dereference When the specified destination is a symbolic link to a directory, attempts to replace the symbolic link rather than dereferencing it to create a link in the directory to which it points. This option is most useful in conjunction with --force.
-s, --symbolic Makes symbolic links instead of hard links.
-v, --verbose Prints the name of each file before linking it.
--help Prints a usage message on standard output and exits successfully.
--version Prints version information on standard output then exits successfully.
-S, --suffix backup-suffix The suffix used for making simple backup files can be set with the SIMPLE_BACKUP_SUFFIX environment variable, which can be overridden by this option. If neither of those is given, the default is ~, as it is in emacs.
-V, --version-control {numbered,existing,simple} The type of backups made can be set with the VERSION_CONTROL environment variable.

Example A.35.
1 ls -l
  total 2
					drwxrwsr-x
					2
					ellie    root        1024 Jan 19 18:34 dir
					-rw-rw-r--
					1
					ellie    root          16 Jan 19 18:34 filex
2 % ln filex dir
3 % cd dir
4 % ls -l
  total 1
					-rw-rw-r--
					2
					ellie     root         16 Jan 19 18:34 filex
				

Explanation

  1. The output of the ls command displays a long listing for a directory called dir and a file called filex The number of links on a directory is always at least two, one for the directory itself, and one for its parent. The number of links for a file is always at least one, one to link it to the directory where it was created. When you remove a file, its link count drops to zero.

  2. The ln command creates a hard link. fllex is now linked to the directory, dir as well as the current directory. A link does not create a new file. It simply gives an existing file an additional name or directory where it can be found. If you remove one of the links, you'll still have one left. Any changes made to one of the linked files, results in changes to the other, because they are the same file.

  3. Change to the directory where filex was linked.

  4. The link count for filex is 2. It is the same file but can now be accessed in this directory as well as the parent directory.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.8.8