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

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 閱讀(379) 評論(0)  編輯 收藏 引用 所屬分類: Linux

導航

隨筆分類

隨筆檔案

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            欧美日韩中文字幕综合视频 | 一区二区三区欧美在线| 久久精品夜夜夜夜久久| 亚洲激情专区| 欧美片第一页| 亚洲美女av在线播放| 亚洲日本一区二区| 免费成人av在线| 亚洲欧美不卡| 日韩午夜av| 欧美一区二区三区喷汁尤物| 国产午夜精品久久久久久免费视| 先锋影音网一区二区| 久久婷婷麻豆| 亚洲欧美另类久久久精品2019| 在线观看精品一区| 免费影视亚洲| 久久精品99国产精品日本| 一区二区三区产品免费精品久久75| 国产欧美一级| 欧美午夜美女看片| 亚洲欧美国产一区二区三区| 亚洲精品影视| 欧美激情导航| 99精品国产高清一区二区| 欧美伊人影院| 欧美大片在线观看| 欧美成人性生活| 亚洲国产精品成人一区二区| 欧美午夜视频一区二区| 午夜精品久久久久久久 | 欧美激情中文字幕一区二区| 久久免费少妇高潮久久精品99| 亚洲丝袜av一区| 国产精品视频网址| 久久在线视频在线| 欧美精品免费播放| 9色porny自拍视频一区二区| 日韩一级精品| 久久久精彩视频| 久久激情中文| 99视频国产精品免费观看| 蜜桃久久精品乱码一区二区| 久久精品一本久久99精品| 久久久精品五月天| 亚洲国产高清自拍| 久久女同互慰一区二区三区| 美女91精品| 亚洲精品乱码| 亚洲男女自偷自拍| 久久理论片午夜琪琪电影网| 久久久久九九九九| 欧美另类久久久品 | 伊甸园精品99久久久久久| 1000部国产精品成人观看| 久久精品国产91精品亚洲| 欧美激情综合网| 国产日韩欧美| 久久精品二区| 亚洲欧美国产毛片在线| 久久永久免费| 91久久久亚洲精品| 久久久久久久久久久成人| 亚洲一区二区三区777| 欧美日韩国产成人精品| 亚洲欧美一区二区三区极速播放| 欧美日韩国产综合新一区| 国产啪精品视频| 牛牛影视久久网| 久久婷婷久久| 亚洲开发第一视频在线播放| 一区二区三区日韩在线观看| 免费看精品久久片| 欧美国产免费| 亚洲高清视频中文字幕| 欧美激情第3页| 欧美日韩精品欧美日韩精品一 | 性刺激综合网| 国产伦精品一区二区三区高清| 亚洲大胆在线| 欧美午夜精品伦理| 99视频精品在线| 在线看日韩欧美| 亚洲欧美日韩一区二区三区在线观看 | 久久久xxx| 99精品国产一区二区青青牛奶 | 国产欧美在线看| 久久香蕉精品| 久久久国产精品一区二区中文| 亚洲一区二区三区四区在线观看 | 黄色成人在线| 亚洲精品日韩精品| 欧美视频在线观看一区二区| 久久大香伊蕉在人线观看热2| 亚洲一区网站| 亚洲欧美日本国产有色| 欧美二区在线播放| 欧美一区二区久久久| 久久久中精品2020中文| 欧美一区二区三区视频在线| 国产精品草草| 午夜久久久久久| 久久婷婷久久| av成人国产| 卡一卡二国产精品| 欧美一区日韩一区| 久久精品夜色噜噜亚洲a∨ | 9l国产精品久久久久麻豆| 亚洲欧美中文字幕| 开元免费观看欧美电视剧网站| 狠狠久久亚洲欧美| 免费在线一区二区| 亚洲国产视频一区二区| 亚洲国产精品久久久久秋霞影院| 免费一级欧美片在线播放| 久久亚洲一区| 亚洲午夜影视影院在线观看| 亚洲国产一区二区三区高清| 欧美日韩亚洲另类| 亚洲香蕉成视频在线观看| 伊人色综合久久天天| 久久精品人人爽| 亚洲欧洲精品一区二区三区不卡 | 欧美精品一级| 欧美激情精品久久久久久免费印度| 国产欧美日韩三区| 久久久亚洲人| 午夜精品在线视频| 亚洲欧美日本国产专区一区| 久久久久.com| 久久精品视频在线| 中文精品视频| 一本色道久久88亚洲综合88| 一区精品在线| 国产伦精品一区二区三区视频孕妇 | 久久久久久久综合| 亚洲天堂网在线观看| 亚洲精品美女在线观看播放| 一区二区成人精品| 欧美一二三区在线观看| 欧美一级专区| 国产偷国产偷亚洲高清97cao| 午夜久久久久| 蜜乳av另类精品一区二区| 欧美大香线蕉线伊人久久国产精品| 亚洲免费在线观看| 在线视频你懂得一区| 欧美韩国一区| 亚洲欧美大片| 亚洲在线成人| 亚洲激情网站| 亚洲一区国产一区| 亚洲永久免费| 日韩天天综合| 久久精品一区四区| 夜夜夜精品看看| 久久一区欧美| 国产主播精品| 欧美国产日韩亚洲一区| 久久久97精品| 亚洲欧美视频在线观看| 欧美国产精品中文字幕| 久久国产精品99精品国产| 先锋影音网一区二区| 欧美日韩一区二区视频在线观看 | 日韩一级二级三级| 老牛国产精品一区的观看方式| 亚洲一本大道在线| 免费黄网站欧美| 亚欧成人在线| 欧美日韩国产成人精品| 亚洲第一精品福利| 久久综合成人精品亚洲另类欧美| 一区二区三区欧美成人| 欧美成人精品激情在线观看| 欧美中文字幕在线视频| 国产精品久久夜| 久久久欧美一区二区| 亚洲性视频网站| 亚洲黄色天堂| 久久激情综合网| 亚洲一级片在线观看| 久久亚洲春色中文字幕| 久久国产精品久久久| 欧美国产日韩一区二区| 亚洲激情视频网站| 亚洲在线观看| 亚洲电影免费观看高清完整版在线观看 | 欧美日韩高清免费| 久热精品视频| av成人免费观看| 国产日韩欧美亚洲| 欧美在线首页| 亚洲国产精品一区二区www在线 | 中国成人在线视频| 亚洲承认在线| 最新国产精品拍自在线播放| 你懂的视频欧美| 野花国产精品入口| 免费国产自线拍一欧美视频|