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

GLORY | 學(xué)習(xí)·記錄

coding for life

硬鏈接和軟連接

文章轉(zhuǎn)自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 閱讀(384) 評論(0)  編輯 收藏 引用 所屬分類: Linux


只有注冊用戶登錄后才能發(fā)表評論。
網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


導(dǎo)航

隨筆分類

隨筆檔案

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            国产精品视频久久久| 国产精品日韩精品欧美在线| 国产一区二区三区在线播放免费观看| 日韩视频中午一区| 欧美成人亚洲成人| 久久综合国产精品| 亚洲电影成人| 亚洲第一福利社区| 欧美aⅴ99久久黑人专区| 亚洲国产欧美一区| 亚洲福利在线看| 欧美日韩无遮挡| 亚洲欧美日韩另类| 欧美一进一出视频| 亚洲国产日韩在线| 亚洲国产精品日韩| 欧美日韩一区二区三区免费看| 亚洲一区二区三区免费在线观看| 亚洲午夜一区| 一区二区在线看| 亚洲国产高清aⅴ视频| 欧美精品激情在线| 欧美专区中文字幕| 欧美大片在线看| 性欧美8khd高清极品| 久久五月天婷婷| 亚洲调教视频在线观看| 欧美专区在线观看| 一本久久青青| 午夜精品成人在线视频| 亚洲国产成人精品久久久国产成人一区| 亚洲国产清纯| 国产日韩专区| 亚洲精品视频一区二区三区| 国产区亚洲区欧美区| 亚洲国产精品国自产拍av秋霞| 国产精品麻豆成人av电影艾秋| 免费不卡在线观看| 欧美性猛交xxxx乱大交退制版 | 欧美99久久| 亚洲欧美日韩综合aⅴ视频| 另类尿喷潮videofree| 亚洲一区二区三区免费观看| 美日韩丰满少妇在线观看| 性色av一区二区三区在线观看| 欧美~级网站不卡| 久久精品99国产精品日本| 欧美日韩一区二区三区四区五区| 久久影视精品| 国产精品人人爽人人做我的可爱| 亚洲黄网站黄| 亚洲国产成人精品久久| 久久成人国产精品| 亚洲欧美精品suv| 欧美男人的天堂| 欧美激情aⅴ一区二区三区| 国产欧美一区二区三区另类精品| 亚洲伦理在线观看| 亚洲精品黄色| 快射av在线播放一区| 久久阴道视频| 国产亚洲精品aa| 亚洲欧美欧美一区二区三区| 亚洲一区二区动漫| 欧美日韩亚洲综合| 日韩亚洲欧美成人一区| 日韩视频免费在线| 欧美电影免费观看高清完整版| 免费毛片一区二区三区久久久| 国产日韩欧美黄色| 欧美一区1区三区3区公司| 欧美亚洲在线| 国产亚洲a∨片在线观看| 亚洲综合视频一区| 欧美在线影院在线视频| 国产美女精品视频免费观看| 亚洲欧美日韩国产综合精品二区| 午夜精品久久久久久99热软件| 国产精品蜜臀在线观看| 亚洲一区免费视频| 久久久www| 伊人夜夜躁av伊人久久| 久久夜色精品国产噜噜av| 欧美顶级大胆免费视频| 亚洲精品国久久99热| 欧美日韩视频不卡| 正在播放日韩| 久久久噜噜噜久久中文字免| 国产在线视频欧美| 免费看的黄色欧美网站| 亚洲精品视频在线播放| 亚洲欧美日韩久久精品 | 久久色在线观看| 亚洲高清一区二区三区| 一本一本久久a久久精品综合妖精| 欧美日韩国产123| 在线亚洲一区二区| 久久综合九色99| 亚洲精品资源| 国产精品乱子乱xxxx| 久久精品国产亚洲aⅴ| 亚洲高清影视| 性色一区二区三区| 亚洲激情视频在线播放| 欧美日韩精品不卡| 欧美在线国产| 日韩视频在线免费| 久久先锋影音av| 在线亚洲欧美| 极品av少妇一区二区| 欧美日韩一区二区三区视频| 久久成人国产精品| 日韩午夜av电影| 蜜桃av久久久亚洲精品| 亚洲素人在线| 伊大人香蕉综合8在线视| 欧美精品1区2区| 欧美在线日韩| 99re成人精品视频| 免费观看成人www动漫视频| 亚洲午夜电影| 亚洲日韩视频| 精品福利电影| 国产女主播视频一区二区| 欧美黄色影院| 久久婷婷成人综合色| 亚洲欧美综合一区| 日韩视频免费| 亚洲高清资源综合久久精品| 久久国产免费| 亚洲欧美日本另类| 99国产精品国产精品久久| 在线观看日韩www视频免费| 国产精品视频999| 欧美精品一区二区精品网| 久久在线精品| 久久精品一区蜜桃臀影院 | 免费观看成人| 久久影视三级福利片| 欧美专区在线播放| 午夜精品久久久久影视| 亚洲视频精品| 一区二区三区国产| 一区二区毛片| 一本色道久久精品| 一区二区日本视频| 亚洲免费观看| 日韩亚洲不卡在线| 日韩视频―中文字幕| 99天天综合性| 这里只有视频精品| 亚洲一级片在线观看| 亚洲五月婷婷| 亚洲尤物精选| 性色av一区二区三区在线观看 | 在线观看亚洲精品视频| 国语精品中文字幕| 激情视频一区| 亚洲电影在线免费观看| 亚洲国产你懂的| 亚洲精选一区二区| 亚洲天堂av在线免费| 亚洲综合视频网| 久久av资源网站| 老色鬼久久亚洲一区二区| 欧美国产日韩一区| 亚洲精品乱码久久久久久蜜桃麻豆| 亚洲七七久久综合桃花剧情介绍| 亚洲精品精选| 亚洲一区二区欧美| 久久成人国产| 欧美紧缚bdsm在线视频| 国产精品久久午夜| 国产一区二区三区四区| 91久久综合| 亚洲免费视频一区二区| 久久成人在线| 亚洲国产婷婷香蕉久久久久久99| 夜夜嗨av一区二区三区网站四季av| 亚洲伊人观看| 可以看av的网站久久看| 欧美日韩dvd在线观看| 国产精品夜夜夜一区二区三区尤| 国产亚洲欧美日韩在线一区| 亚洲福利视频网| 亚洲女人天堂av| 久久免费视频在线观看| 亚洲激情社区| 欧美一区二区三区视频在线| 欧美激情在线观看| 国产精品一区视频| 日韩午夜电影av| 久久免费国产精品1| 日韩视频免费在线| 久久久中精品2020中文| 国产精品久久激情| 亚洲精品小视频| 老司机亚洲精品| 亚洲影视在线| 欧美日韩1234|