免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 19325 | 回复: 10
打印 上一主题 下一主题

用ln命令建的连接:hard link 和symbolic link有什么区别?? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-02-25 19:39 |只看该作者 |倒序浏览
比如:
ln f1 f2
ln -s f1 f3
f1和f2好像没有什么区别阿?大小一样,内容一样

论坛徽章:
0
2 [报告]
发表于 2003-02-25 19:52 |只看该作者

用ln命令建的连接:hard link 和symbolic link有什么区别??

小弟认为:
用ln建立的连接,大小和源文件一样,而用ln -s 建立的文件要小得多。但是如果改动任何一个文件,都会影响所有的文件。

论坛徽章:
0
3 [报告]
发表于 2003-02-25 21:43 |只看该作者

用ln命令建的连接:hard link 和symbolic link有什么区别??

原帖由 "tigerlei" 发表:
比如:
ln f1 f2
ln -s f1 f3
f1和f2好像没有什么区别阿?大小一样,内容一样


-s相当于建立快捷方式,删掉不影响源文件
hardlink相当于另一个文件别名入口,删掉任何一个都物理删除了

论坛徽章:
0
4 [报告]
发表于 2003-02-25 22:28 |只看该作者

用ln命令建的连接:hard link 和symbolic link有什么区别??

hardlink 不能跨file system
symbol link 可以跨file system

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
5 [报告]
发表于 2003-02-26 06:02 |只看该作者

用ln命令建的连接:hard link 和symbolic link有什么区别??

链接(link):系统中的链接是一个已经存在的文件的另一个名字,它不复制文件的内容。有两种链接方式,一种是硬链接(hard link),另一种是符号链接(symbolic link),又称软链接。硬链接和原有文件是存储在同一物理地址的两个不同的名字,因此硬链接是相互的;符号链接的内容只是一个所链接文件的文件名,在使用ls –l时,符号链接的第一项的第一位为“l”。

指向一個文件的所有 硬鏈接都刪掉的話文件的內容才會被刪掉
軟鏈接只要刪掉了源鏈接文件,軟鏈接也就失效了

论坛徽章:
0
6 [报告]
发表于 2003-02-26 08:56 |只看该作者

用ln命令建的连接:hard link 和symbolic link有什么区别??

补充公子D:
       软连接之所以文件小,是因为它的内容只是源文件的路径——多的也就几十字节。

论坛徽章:
0
7 [报告]
发表于 2003-07-21 11:01 |只看该作者

用ln命令建的连接:hard link 和symbolic link有什么区别??

但是硬连接的文件大小其实不是另外分配磁盘空间的,他们共享同一块文件区域,所以应该和软连接一样都很省空间的,至于谁更省,我觉得不一定是软连接,有人详细解释一下存储机制吗。

论坛徽章:
0
8 [报告]
发表于 2003-10-21 08:53 |只看该作者

用ln命令建的连接:hard link 和symbolic link有什么区别??

Commands Reference, Volume 3

ln Command

Purpose

Links files.

Syntax

To Link a File to a File

ln [ -f | -n ] [ -s ] SourceFile [ TargetFile ]

To Link a File or Files to a Directory

ln [ -f | -n ] [ -s ] SourceFile ... TargetDirectory

Description

The ln command links the file designated in the SourceFile parameter to the file
designated by the TargetFile parameter or to the same file name in another
directory specified by the TargetDirectory parameter. By default, the ln command
creates hard links. To use the ln command to create symbolic links, designate
the -s flag.

A symbolic link is an indirect pointer to a file; its directory entry contains
the name of the file to which it is linked. Symbolic links may span file systems and may refer to directories.

If you are linking a file to a new name, you can list only one file. If you are
linking to a directory, you can list more than one file.

The TargetFile parameter is optional. If you do not designate a target file, the
ln command creates a new file in your current directory. The new file inherits
the name of the file designated in the SourceFile parameter. See example 5.

    Notes:

      1. You cannot link files across file systems without using the -s flag.
      2. If TargetDirectory is already a symbolic link to a directory, then the
         ln command treats the existing target as a file. This means that a
         command such as ln -fs somepath/lname symdir will not follow the
         existing symbolic link of symdir, instead it will create a new symbolic
         link from somepath/lname to symdir.
Flags

-f Causes the ln command to replace any destination paths that already exist. If
a destination path already exists and the -f flag is not specified, the ln
command writes a diagnostic message to standard error without creating a new
link and continues to link the remaining SourceFiles.

-n Specifies that if the link is an existing file, do not overwrite the contents
of the file. The -f flag overrides this flag. This is the default behaviour.

-s Causes the ln command to create symbolic links. A symbolic link contains the
name of the file to which it is linked. The referenced file is used when an open
operation is performed on the link. A stat call on a symbolic link returns the
linked-to file; an lstat call must be done to obtain information about the link.
The readlink call may be used to read the contents of a symbolic link. Symbolic
links can span file systems and refer to directories.

    Note: Absolute path names must be used when specifying the SourceFile
    parameter for the -s flag. If the absolute path name is not designated,
    unexpected results may occur when the SourceFile and the TargetFile
    parameters are located in different directories. The source file does not
    need to exist before creating the symbolic link.
Exit Status

This command returns the following exit values:

0 All specified files were successfully linked.

>;0 An error occurred.

Examples

  1. To create another link (alias) to a file, enter:

     ln  -f chap1  intro

     This links chap1 to the new name, intro. If intro does not already exist,
     the file name is created. If intro does exist, the file is replaced by a
     link to chap1. Then both the chap1 and intro file names will refer to the
     same file. Any changes made to one also appear in the other. If one file
     name is deleted with the rm command, the file is not completely deleted
     since it remains under the other name.
  2. To link a file to the same name in another directory, enter:

     ln  index  manual

     This links index to the new name, manual/index.

         Note: intro in example 1 is the name of a file; manual in example 2 is
         a directory that already exists.

  3. To link several files to names in another directory, enter:

     ln  chap2  jim/chap3  /home/manual

     This links chap2 to the new name /home/manual/chap2 and jim/chap3 to
     /home/manual/chap3.
  4. To use the ln command with pattern-matching characters, enter:

     ln  manual/* .

     This links all files in the manual directory into the current directory, .
     (dot), giving them the same names they have in the manual directory.

         Note: You must type a space between the asterisk and the period.

  5. To create a symbolic link, enter:

     ln -s /tmp/toc toc
     This creates the symbolic link, toc, in the current directory. The toc file
     points to the /tmp/toc file. If the /tmp/toc file exists, the cat toc
     command lists its contents.

     To achieve identical results without designating the TargetFile parameter,
     enter:

     ln -s /tmp/toc

Files

/usr/bin/ln Contains the ln command.

Related Information

The cp command, mv command, rm command.

The link subroutine, readlink subroutine, stat subroutine, symlink subroutine.

Directory Overview in AIX 5L Version 5.2 System User's Guide: Operating System
and Devices describes the structure and characteristics of directories in the
file system.

Files Overview in AIX 5L Version 5.2 System User's Guide: Operating System and
Devices describes files, file types, and how to name files.

Linking Files and Directories in AIX 5L Version 5.2 System User's Guide:
Operating System and Devices explains the concept of file linking.

Linking for Programmers in AIX 5L Version 5.2 General Programming Concepts:
Writing and Debugging Programs discusses links from a programming viewpoint.

论坛徽章:
0
9 [报告]
发表于 2004-02-13 09:08 |只看该作者

用ln命令建的连接:hard link 和symbolic link有什么区别??

那 link 和 ln 有何区别?
我要装Oracle 到/space下 但是实际只有/home可以供使用
我应该用什么命令?
1,link /home /space
2,ln /home /space
3,ln -s /home /space
大虾赐教

论坛徽章:
0
10 [报告]
发表于 2012-01-19 14:08 |只看该作者
譬如:(a、b2个文件)
硬连接ln:ln a b;
      a b指向同一个文件区域,删除a,b可以代替;删除b,a可以代替;修改a,b会修改;修改b,a会修改
软连接ln:ln -s a  b;
      b是a的快捷方式,相当于window下的快捷方式,在windows下原文件被删除,那么双击快捷方式会怎么样?只能是找不到原文件。
                             删除a原文件,b打不开了;删出b快捷方式,a源文件照样可用

    在硬连接中,因为a b指向同一块区域,大小一样;软连接中,b这是a 的快捷方式,在windows下快捷方式能有多大呢?
不知道有没有说清楚。
     
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP