Link files for Linux

Source: Internet
Author: User

Link files for Linux
========================================

The Linux link file is broken into hard link files and soft link files (symbolic link)

Note: There are two restrictions on hard links: (1) cannot cross the file system, (2) cannot link to a directory

ln
Command format:
ln [-S] [source file] [destination file]
The no-s option is a hard link
Plus-s option is to create a soft link

Example:
Hard Links
[Email protected] tmp]# mkdir Ln
[[Email protected] tmp]# CD LN
[Email protected] ln]# cp/etc/passwd.
[email protected] ln]# LL
Total Dosage 4
-rw-r--r--1 root root 1314 June 20:48 passwd
[Email protected] ln]# Du-sk
4.
[Email protected] ln]# LN passwd passwd-hard
[email protected] ln]# LL
Total Dosage 8
-rw-r--r--2 root root 1314 June 20:48 passwd
-rw-r--r--2 root root 1314 June 20:48 Passwd-hard
[[email protected] ln]# du-sk//du command used to calculate the size of a file or directory-K is expressed in kilobytes
4.
[[email protected] ln]# ll-i passwd passwd-hard//Hard link source file and destination file Inode consistent
50769012-rw-r--r--2 root root 1314 June 21:04 passwd
50769012-rw-r--r--2 root root 1314 June 21:04 Passwd-hard

[Email protected] ln]# rm-f passwd
[email protected] ln]# LL
Total Dosage 4
-rw-r--r--1 root root 1314 June 20:48 Passwd-hard
[Email protected] ln]# Du-sk
4.

[Email protected] ln]# mkdir 123
[[Email protected] ln]# LN 123 456//Hard link Cannot link directory
LN: "123": Do not allow hard links to be directed to the directory

Soft links
[Email protected] tmp]# mkdir Ln-soft
[Email protected] tmp]# CD ln-soft/
[Email protected] ln-soft]#!CP
CP/ETC/PASSWD./
[Email protected] ln-soft]# ln-s passwd passwd-soft
[email protected] ln-soft]# LL
Total Dosage 4
-rw-r--r--1 root root 1314 June 20:54 passwd
lrwxrwxrwx 1 root root 6 June 20:54 Passwd-soft-passwd
[[email protected] ln-soft]# ll-i passwd passwd-soft//Soft link source file and destination file Inode inconsistency.
17423155-rw-r--r--1 root root 1314 June 21:06 passwd
17423157lrwxrwxrwx 1 root root 6 June 25 21:06Passwd-soft-passwd
[Email protected] ln-soft]# head-n1 Passwd-soft
Root:x:0:0:root:/root:/bin/bash
[Email protected] ln-soft]# head-n1 passwd
Root:x:0:0:root:/root:/bin/bash
[Email protected] ln-soft]# rm-f passwd
[Email protected] ln-soft]# head-n1 Passwd-soft
Head: Unable to open "Passwd-soft" read data: No file or directory
[email protected] ln-soft]# LL
Total dosage 0
lrwxrwxrwx 1 root root 6 June 20:54 Passwd-soft-passwd

[Email protected] ln-soft]# CD.
[[email protected] tmp]# ln-s ln-soft ln-s-soft//Soft links can be linked to the directory
[Email protected] tmp]# ll-d ln-soft ln-s-soft
Drwxr-xr-x 2 root root 25 June 20:57 Ln-soft
lrwxrwxrwx 1 root root 7 June 21:01 Ln-s-soft-Ln-soft

Link files for Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.