The ln command is used to create links to files. There are two types of links: hard links and symbolic links. The default link type is hard links. You must use the “-s” option if you want to create symbolic links.

The command format

Ln [parameter][source file or directory][destination file or directory]

Command function

In the Linux file system, there are so-called links, which we can think of as aliases for files, and there are two types of links: Hard link and soft link (symbolic link), hard link means that a file can have multiple names, and the way of soft link is to produce a special file, the content of the file is to point to another file location. Hard links exist in the same file system, while soft links can span different file systems.

Soft connection

  • Soft links exist in the form of paths. Similar to shortcuts in the Windows operating system
  • Soft links can span file systems; hard links cannot
  • A soft link can link to a filename that does not exist
  • A soft link can link to a directory

Hard links

  • Hard link, in the form of a copy of the file. But it doesn’t take up real space.
  • You are not allowed to create hard links for directories
  • Hard links can only be created on the same file system

The command parameter

  • -b Delete, overwrite previously established links
  • – D allows the superuser to make hard links to directories
  • -F Enforcement
  • -i interactive mode, the presence of a file prompts the user whether to overwrite
  • -n treats symbolic links as generic directories
  • -S soft links (symbolic links)
  • -v shows the detailed process
  • -s “-s < trailing backup string >” or “–suffix=< trailing backup string >”
  • -v “-v < backup mode >” or “–version-control=< backup mode >”
  • –help displays help information
  • –version displays version information

torumenz.txtCreate a soft connection

> ls -al
ls -al
total 4
drwxr-xr-x 2 root root  24 Feb 27 22:03 .
drwxr-xr-x 8 root root 299 Feb 26 19:44 ..
-rw-r--r-- 1 root root  22 Feb 27 22:03 rumenz.txt
> ln -s rumenz.txt newrumenz.txt

> ls -al
total 4
drwxr-xr-x 2 root root  45 Feb 27 22:03 .
drwxr-xr-x 8 root root 299 Feb 26 19:44 ..
lrwxrwxrwx 1 root root  10 Feb 27 22:03 newrumenz.txt -> rumenz.txt
-rw-r--r-- 1 root root  22 Feb 27 22:03 rumenz.txt

newrumenz.txtis
rumenz.txtSoft connection, modified
newrumenz.txtThe contents of the file,
rumenz.txtIt will change, it will delete
newrumenz.txt.
rumenz.txtThe content is not affected in any way. But to delete
rumenz.txt.
ls newrumenz.txtWhen,
newrumenz.txtIt changes color or it blinks all the time.

torumenz.txtCreate a hard connection

> ls rumenz.txt oldrumenz.txt > ls -al total 8 drwxr-xr-x 2 root root 45 Feb 27 22:12 . drwxr-xr-x 8 root root 299 Feb 26 shall.. -rw-r--r-- 2 root root 8 Feb 27 22:12 oldrumenz.txt -rw-r--r-- 2 root root 8 Feb 27 22:12 rumenz.txt

Modify the
oldrumenz.txtFile contents,
rumenz.txtThe content will change and be deleted
oldrumenz.txt.
rumenz.txtThe content is not affected in any way. delete
rumenz.txt.
oldrumenz.txtThe content is not affected in any way.

Create a soft connection to a directory (cannot create a hard connection to a directory)

> ln -sv lib lib64
> ls -al
drwxr-xr-x 8 root root   312 Feb 27 22:16 .
drwxr-xr-x 3 root root    17 Jan 29 23:06 ..
drwxr-xr-x 2 root root    27 Feb 27 22:14 lib
lrwxrwxrwx 1 root root     4 Feb 27 22:16 lib64 -> lib/

The original link: https://rumenz.com/rumenbiji/… WeChat official account: entry station