青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

GLORY | 學習·記錄

coding for life

硬鏈接和軟連接

文章轉自http://www.ugrad.cs.ubc.ca/~cs219/CourseNotes/Unix/commands-links.html
Hard links and Soft links

Links

As was mentioned in the section on file system structure, every file has a data structure (record) known as an i-node that stores information about the file, and the filename is simply used as a reference to that data structure. A link is simply a way to refer to the contents of a file. There are two types of links:

  • Hard links: a hard link is a pointer to the file's i-node. For example, suppose that we have a file a-file.txt that contains the string "The file a-file.txt":
    % cat a-file.txt
    The file a-file.txt
    %

    Now we use the ln command to create a link to a-file.txt called b-file.txt:

    % ls
    ./ ../ a-file.txt
    % ln a-file.txt b-file.txt
    % ls
    ./ ../ a-file.txt b-file.txt

    Hard Links

    The two names a-file.txt and b-file.txt now refer to the same data:

    % cat b-file.txt
    The file a-file.txt
    %

    If we modify the contents of file b-file.txt, then we also modify the contents of file a-file.txt:

    % vi b-file.txt
    ...
    % cat b-file.txt
    The file a-file.txt has been modified.
    % cat a-file.txt
    The file a-file.txt has been modified.
    %

    and vice versa:

    % vi a-file.txt
    ...
    % cat a-file.txt
    The file a-file.txt has been modified again!
    % cat b-file.txt
    The file a-file.txt has been modified again!
    %
  • Soft links (symbolic links): a soft link, also called symbolic link, is a file that contains the name of another file. We can then access the contents of the other file through that name. That is, a symbolic link is like a pointer to the pointer to the file's contents. For instance, supposed that in the previous example, we had used the -s option of the ln to create a soft link:
    % ln -s a-file.txt b-file.txt
    On disk, the file system would look like the following picture:

    Soft Links

But what are the differences between the two types of links, in practice? Let us look at an example that highlights these differences. The directory currently looks like this (let us assume that a-file.txt b-file.txt are both hard links to the same file):

% ls
./ ../ a-file.txt b-file.txt

Let us first add another symbolic link using the -s option:

% ln -s a-file.txt Symbolicb-file.txt
% ls -F
./ ../ a-file.txt b-file.txt Symbolicb-file.txt@

A symbolic link, that ls -F displays with a @ symbol, has been added to the directory. Let us examine the contents of the file:

% cat Symbolicb-file.txt 
The file a-file.txt has been modified again!

If we change the file Symbolicb-file.txt, then the file a-file.txt is also modified.

% vi Symbolicb-file.txt
...
% cat Symbolicb-file.txt
The file a-file.txt has been modified a third time!
% cat a-file.txt
The file a-file.txt has been modified a third time!
% cat b-file.txt
The file a-file.txt has been modified a third time!
%

If we remove the file a-file.txt, we can no longer access the data through the symbolic link Symbolicb-file.txt:

% ls -F
./ ../ a-file.txt b-file.txt Symbolicb-file.txt@
% rm a-file.txt
rm: remove `a-file.txt'? y
% ls -F
./ ../ b-file.txt Symbolicb-file.txt@
% cat Symbolicb-file.txt
cat: Symbolicb-file.txt: No such file or directory

The link Symbolicb-file.txt contains the name a-file.txt, and there no longer is a file with that name. On the other hand, b-file.txt has its own pointer to the contents of the file we called a-file.txt, and hence we can still use it to access the data.

% cat b-file.txt
The file a-file.txt has been modified a third time!

Although it may seem like symbolic links are not particularly useful, hard links have their drawbacks. The most significant drawback is that hard links cannot be created to link a file from one file system to another file on another file system. A Unix file structure hierarchy can consist of several different file systems (possibly on several physical disks). Each file system maintains its own information regarding the internal structure of the system and the individual files on the system. Hard links only know this system-specific information, which make hard links unable to span file systems. Soft links, on the other hand, know the name of the file, which is more general, and are able to span file systems.

For a concrete analogy, suppose that our friend Joel User is a student at both UBC and SFU. Both universities assign him a student number. If he tries to use his UBC student number at SFU, he will not meet with any success. He will also fail if he tries to use his SFU student number at UBC. But if he uses his legal name, Joel User, he will probably be successful. The student numbers are system-specific (like hard links), while his legal name spans both of the systems (like soft links).

Here is an example that demonstrates a situation where a hard link cannot be used and a symbolic link is needed. Suppose that we try to create a hard link from the current working directory to the C header stdio.h.

% ln /usr/include/stdio.h stdio.h
ln: creating hard link `stdio.h' to `/usr/include/stdio.h': Invalid cross-device link
%

The ln command fails because stdio.h is stored on a different file system. If we want to create a link to it, we will have to use a symbolic link:

% ln -s /usr/include/stdio.h stdio.h
% ls -l
lrwxrwxrwx 1 a1a1 guest 20 Apr 20 11:58 stdio.h -> /usr/include/stdio.h
% ls
./ ../ stdio.h@
%

Now we can view the file stdio.h just as if it was located in the working directory. For example:

% cat stdio.h 
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */

/* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T */
/* The copyright notice above does not evidence any */
/* actual or intended publication of such source code. */

/*
* User-visible pieces of the ANSI C standard I/O package.
*/

#ifndef _STDIO_H
#define _STDIO_H
...
%

The entire output of the cat command was not included to save space.

Note that the long listing (ls -l) of a soft link does not accurately reflect its associated permissions. To view the permissions of the file or directory that the symbolic link references, the -L options of the ls command can be used. For example:

% ln -s /usr/include/stdio.h stdio.h

% ls -l stdio.h
lrwxrwxrwx 1 a1a1 undergrad 20 May 10 15:13 stdio.h -> /usr/include/stdio.h

% ls -l /usr/include/stdio.h
-rw-r--r-- 1 root bin 11066 Jan 5 2000 /usr/include/stdio.h

% ls -lL stdio.h
-rw-r--r-- 1 root bin 11066 Jan 5 2000 stdio.h

posted on 2010-12-22 16:12 meglory 閱讀(383) 評論(0)  編輯 收藏 引用 所屬分類: Linux


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


導航

隨筆分類

隨筆檔案

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            久久免费午夜影院| 欧美刺激午夜性久久久久久久| 亚洲国产精品va| 精品69视频一区二区三区| 国产在线不卡| 亚洲国产精品成人| 亚洲精品在线看| 一区二区三区国产精品| 亚洲一区免费视频| 久久久久国产一区二区三区四区| 另类欧美日韩国产在线| 亚洲欧洲在线视频| 亚洲区一区二区三区| 亚洲特黄一级片| 欧美影院午夜播放| 免费在线观看精品| 欧美日韩一区在线观看| 国产日产精品一区二区三区四区的观看方式| 国产精品麻豆成人av电影艾秋| 国产日韩欧美日韩| 亚洲黄色精品| 校园春色国产精品| 欧美国产日韩一区| 亚洲私人黄色宅男| 免费久久99精品国产| 国产精品久久久久毛片软件| 在线看不卡av| 香蕉乱码成人久久天堂爱免费| 久久天天躁夜夜躁狠狠躁2022| 91久久精品国产91久久性色| 欧美一级欧美一级在线播放| 欧美高清在线视频| 国产亚洲a∨片在线观看| 亚洲精品网址在线观看| 久久九九热re6这里有精品| 亚洲精品网站在线播放gif| 久久爱www久久做| 欧美日韩一区二区在线观看视频 | 亚洲国产精品一区二区三区| 亚洲一卡久久| 欧美电影免费网站| 亚洲欧美视频一区| 久久高清免费观看| 一区二区三区精品久久久| 亚洲午夜精品福利| 欧美v亚洲v综合ⅴ国产v| 亚洲男同1069视频| 欧美日韩国产一区| 亚洲日本中文字幕区| 久久久精品视频成人| av不卡在线观看| 欧美激情性爽国产精品17p| 国内外成人在线| 欧美自拍偷拍| 亚洲一区二区免费在线| 欧美日韩精品欧美日韩精品一| 在线日本高清免费不卡| 久久亚洲综合色| 欧美在线中文字幕| 国产亚洲精品久久久久动| 午夜亚洲性色福利视频| 日韩视频在线你懂得| 欧美日韩精品久久久| 亚洲美女色禁图| 亚洲精品国产精品国自产观看| 免费观看一级特黄欧美大片| 亚洲激情av| 亚洲欧洲日产国码二区| 欧美精品久久久久久久免费观看 | 女女同性精品视频| 久久久精品网| 亚洲国语精品自产拍在线观看| 男女精品视频| 免费欧美高清视频| 日韩视频一区二区三区在线播放免费观看| 欧美91视频| 欧美国产一区二区在线观看 | 久久久久国产精品午夜一区| 久久激情网站| 亚洲欧洲一区二区天堂久久 | 巨乳诱惑日韩免费av| 激情小说另类小说亚洲欧美| 欧美高清影院| 欧美日韩在线观看一区二区三区| 亚洲在线中文字幕| 香蕉久久夜色精品国产| 亚洲高清视频的网址| 亚洲激情影视| 国产免费观看久久黄| 免费一区二区三区| 欧美日韩精品一区二区在线播放| 香港久久久电影| 另类人畜视频在线| 久久精品99无色码中文字幕| 亚洲一区国产视频| 国产一区三区三区| 亚洲国产精品精华液网站| 欧美日韩在线播放三区| 久久成人精品无人区| 欧美波霸影院| 久久aⅴ乱码一区二区三区| 久久一区二区三区四区| 一区二区三区欧美成人| 欧美一区二区在线免费播放| 99re6这里只有精品| 欧美亚洲一区二区三区| 夜色激情一区二区| 久久久久一区二区| 亚洲综合欧美| 欧美大片免费久久精品三p | 伊人影院久久| 在线一区二区三区四区五区| 亚洲东热激情| 午夜一区不卡| 亚洲一区二三| 欧美久久婷婷综合色| 久久九九99视频| 国产精品麻豆成人av电影艾秋| 亚洲高清三级视频| 国产在线播放一区二区三区| 亚洲色图综合久久| 99re亚洲国产精品| 蜜乳av另类精品一区二区| 久久精品亚洲一区二区| 国产精品国产三级国产普通话蜜臀| 亚洲福利视频专区| 在线观看欧美一区| 欧美综合第一页| 久久精品99| 国产三级欧美三级日产三级99| 在线亚洲精品| 亚洲午夜伦理| 国产精品爱久久久久久久| 亚洲精品国产精品国产自| 亚洲精品一区中文| 免费日韩av片| 亚洲国产欧美国产综合一区| 亚洲大胆视频| 免费精品视频| 亚洲人成网在线播放| 亚洲精品精选| 欧美日韩另类一区| 亚洲午夜国产成人av电影男同| 亚洲综合视频一区| 国产精品久久久久久久久久直播 | 99pao成人国产永久免费视频| 可以免费看不卡的av网站| 欧美va天堂| 亚洲精选国产| 欧美日韩亚洲不卡| 在线亚洲免费视频| 欧美专区中文字幕| 狠狠色丁香婷综合久久| 久久久久久精| 欧美激情精品久久久久久免费印度 | 久久婷婷国产麻豆91天堂| 国产私拍一区| 久久综合狠狠综合久久综合88 | 亚洲国产精品综合| 日韩亚洲精品视频| 欧美午夜在线视频| 欧美亚洲在线观看| 欧美成人免费网站| 中文日韩电影网站| 国产欧美日韩一区二区三区在线| 性欧美大战久久久久久久免费观看| 久久―日本道色综合久久| 亚洲精品乱码| 国产欧美精品一区二区三区介绍| 久久gogo国模啪啪人体图| 亚洲第一在线视频| 亚洲欧美一级二级三级| 在线观看视频亚洲| 欧美午夜精品理论片a级大开眼界| 亚洲欧美综合国产精品一区| 亚洲第一福利社区| 欧美在线免费| 中文国产成人精品| 在线观看欧美精品| 国产伦精品一区二区三区免费迷 | 亚洲电影专区| 国产精品推荐精品| 免费黄网站欧美| 欧美在线999| 一区二区三区四区在线| 欧美成人一区二区三区| 亚洲欧美国产精品桃花| 亚洲电影av在线| 国产伦精品一区二区三区视频孕妇| 麻豆亚洲精品| 欧美亚洲一区二区在线| 野花国产精品入口| 亚洲夫妻自拍| 免费观看日韩av| 欧美中文字幕久久| 亚洲一二三级电影| 亚洲精品男同| 亚洲欧洲综合| 亚洲国产老妈| 亚洲国产另类久久久精品极度|