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

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>
            亚洲美女精品一区| 亚洲精品一区二区网址| 亚洲影院一区| 国产精品视频xxx| 性色av一区二区三区红粉影视| 中文国产一区| 国产精品综合久久久| 欧美中文字幕在线| 久久综合九色九九| 最新高清无码专区| 日韩亚洲精品视频| 国产精品普通话对白| 久久久999成人| 蜜臀久久久99精品久久久久久 | 久久久美女艺术照精彩视频福利播放| 国精产品99永久一区一区| 免费观看成人| 欧美激情日韩| 欧美在线观看视频| 久久亚洲不卡| 亚洲视频在线观看免费| 亚洲男女自偷自拍| 亚洲福利国产| av成人手机在线| 国外成人在线视频网站| 欧美激情视频免费观看| 国产精品久久久久av| 麻豆国产精品777777在线| 欧美黄色视屏| 久久免费国产精品| 欧美日本韩国一区二区三区| 欧美在线视频观看| 欧美激情国产高清| 久久深夜福利| 国产精品久久久久毛片软件 | 久久精品国产96久久久香蕉| 免费永久网站黄欧美| 欧美一区二区三区四区在线| 免费一级欧美片在线观看| 午夜欧美理论片| 欧美国产丝袜视频| 久久久久欧美精品| 国产精品久久国产精品99gif| 欧美黄色一区二区| 国产一区在线看| 亚洲婷婷免费| 一本色道久久综合一区| 久久躁日日躁aaaaxxxx| 香蕉久久夜色| 欧美日韩午夜| 亚洲精品女人| 国产欧美在线| 亚洲一区在线观看免费观看电影高清| 亚洲精品乱码久久久久久按摩观| 欧美一二三视频| 亚洲欧美日韩网| 欧美日韩在线高清| 亚洲丰满少妇videoshd| 一区免费在线| 久久久久国产精品麻豆ai换脸| 午夜久久资源| 国产精品免费网站在线观看| 一区二区三区精密机械公司 | 欧美大色视频| 亚洲国内精品在线| 老牛嫩草一区二区三区日本| 久久午夜视频| 黄色精品一区二区| 久久国产视频网站| 久久久久久久网| 国产字幕视频一区二区| 久久精品国产清自在天天线| 久久久久欧美精品| 在线不卡a资源高清| 久久亚洲一区二区| 欧美韩国一区| 一区二区三区鲁丝不卡| 欧美激情一区二区三区在线| 亚洲精品视频在线观看免费| 在线亚洲+欧美+日本专区| 欧美日韩免费观看一区=区三区 | 久久国产精品久久w女人spa| 国产一区二区三区久久| 久久一区二区三区国产精品| 亚洲第一在线| 在线亚洲激情| 国产精品手机视频| 久久久久久久网站| 亚洲欧洲精品一区| 香蕉久久精品日日躁夜夜躁| 合欧美一区二区三区| 欧美福利精品| 亚洲网友自拍| 老色鬼精品视频在线观看播放| 91久久精品久久国产性色也91| 欧美日韩在线亚洲一区蜜芽| 亚洲欧美日韩区| 欧美黄色免费| 欧美一区国产一区| 91久久精品国产91性色tv| 欧美四级剧情无删版影片| 欧美一区二区三区在线播放| 亚洲第一页中文字幕| 午夜日韩电影| 亚洲精品一区二区三区四区高清| 欧美性生交xxxxx久久久| 久久精品国产96久久久香蕉| 亚洲精品久久嫩草网站秘色| 久久精品成人| 亚洲视频久久| 亚洲电影在线播放| 国产精品丝袜白浆摸在线| 免费看精品久久片| 午夜亚洲性色福利视频| 亚洲国产日韩综合一区| 久久久久久久波多野高潮日日 | 91久久午夜| 韩国v欧美v日本v亚洲v| 国产精品久久久久久久久免费| 免费日本视频一区| 久久精品盗摄| 午夜精品久久久久久久久| 日韩视频免费| 91久久久久久久久久久久久| 老司机精品久久| 久久丁香综合五月国产三级网站| 一区二区三区高清视频在线观看| 在线观看日韩www视频免费| 国产欧美69| 国产精品第三页| 欧美日本一道本在线视频| 免费在线观看日韩欧美| 久久精品一区二区三区不卡牛牛| 亚洲综合第一| 亚洲欧美国产毛片在线| 亚洲国产精品久久久久秋霞不卡| 久久精品视频亚洲| 正在播放亚洲| 亚洲精选在线| 日韩视频一区二区三区| 在线观看精品视频| 国产亚洲欧美激情| 欧美视频在线观看一区二区| 欧美日韩国产欧美日美国产精品| 久久久久久网站| 亚洲欧美日本视频在线观看| 99精品久久久| 亚洲高清视频一区| 免费精品视频| 麻豆成人在线播放| 久久精品视频网| 国产精品99久久久久久宅男| 亚洲视频精选| 在线视频日韩精品| 一本一本久久a久久精品综合妖精| 国产欧美日韩麻豆91| 国产一区高清视频| 国产日本亚洲高清| 国产精品美女主播| 国产精品久久网| 欧美三日本三级三级在线播放| 欧美激情小视频| 欧美韩国一区| 欧美日韩亚洲视频| 欧美成人精品福利| 欧美性jizz18性欧美| 欧美视频一区二区| 国产精品久久久久三级| 国产精品一区在线观看你懂的| 国产美女精品免费电影| 国产亚洲日本欧美韩国| 国内一区二区三区| 136国产福利精品导航| 伊人久久综合97精品| 亚洲大片一区二区三区| 国内精品久久久久伊人av| 国产精品国产亚洲精品看不卡15| 欧美体内谢she精2性欧美| 国产精品丝袜久久久久久app| 国产视频一区二区三区在线观看| 国产精品久久久久999| 国产精品日本一区二区| 国模叶桐国产精品一区| 一区二区三区**美女毛片| 欧美一区二区视频在线| 免费一级欧美片在线观看| 亚洲人成免费| 午夜精品久久久久久久久久久| 久久免费黄色| 欧美激情一区二区三级高清视频| 国产精品99免费看 | 亚洲一区二区三区免费视频| 久久av在线看| 亚洲国产日韩欧美在线99| 中日韩视频在线观看| 久久一区二区三区四区| 国产精品国产自产拍高清av| 亚洲大胆av| 久久国产精品久久久| 暖暖成人免费视频|