zoukankan      html  css  js  c++  java
  • linux文件管理之链接文件

    文件链接


    ====================================================================================
    软链接 或 符号链接
    硬链接

    软链接相当于windows中的快捷方式,硬链接相当于一个灾备系统,数据存放在两处,与复制不同的是两处之间存在同步机制,一处数据的改变会实时同步到另一处,另外,一处数据如果被删除了,不会影响到另一处的数据。

    ln [-s -v] SRC DEST
    硬链接:
    1、只能对文件创建,不能应用于目录;
    2、不能跨文件系统;
    3、创建硬链接会增加文件被链接的次数;

    符号链接:
    1、可应用于目录;
    2、可以跨文件系统;
    3、不会增加被链接文件的链接次数;


    一、符号链接 symbolic link
    [root@localhost ~]# echo 111 > /file1
    [root@localhost ~]# ln -s /file1 /home/file11
    [root@localhost ~]# ll /home/file11
    lrwxrwxrwx 1 root root 6 Dec 20 17:58 /home/file11 -> /file1

    [root@localhost ~]# ll -i /file1 /home/file11
    4599081 -rw-r--r-- 1 root root 4 Dec 20 17:57 /file1
    135 lrwxrwxrwx 1 root root 6 Dec 20 17:58 /home/file11 -> /file1

    [root@localhost ~]# cat /file1
    111
    [root@localhost ~]# cat /home/file11
    111

    [root@localhost ~]# rm -rf /file1
    [root@localhost ~]# ll /home/file11
    lrwxrwxrwx 1 root root 6 Dec 20 17:58 /home/file11 -> /file1


    二、硬链接
    [root@localhost ~]# echo 222 > /file2
    [root@localhost ~]# ln /file2 /file2-h1
    [root@localhost ~]# ln /file2 /home/file2-h2
    ln: failed to create hard link ‘/home/file2-h2’ => ‘/file2’: Invalid cross-device link
    [root@localhost ~]# ln /file2 /etc/file2-h3

    [root@localhost ~]# echo 222 > /file2
    [root@localhost ~]# ln /file2 /file2-h1
    [root@localhost ~]# ln /file2 /home/file2-h2
    ln: failed to create hard link ‘/home/file2-h2’ => ‘/file2’: Invalid cross-device link
    [root@localhost ~]# ln /file2 /etc/file2-h3

    [root@localhost ~]# ll -i /file2 /file2-h1 /etc/file2-h3
    4599081 -rw-r--r-- 3 root root 4 Dec 20 18:03 /etc/file2-h3
    4599081 -rw-r--r-- 3 root root 4 Dec 20 18:03 /file2
    4599081 -rw-r--r-- 3 root root 4 Dec 20 18:03 /file2-h1

    把一些重要文件做多个链接



    注:硬链接
    1. 不能跨文件系统(分区)
    2. 不支持目录做硬链接
    [root@localhost home]# ln /home/ /mnt
    ln: “/home/”: 不允许将硬链接指向目录



    警告:删除目录软链时:


    # mkdir /home/it1000
    # touch /home/it1000/file{1..10}
    # ln -s /home/it1000/ /var/

    rm -rf /var/it1000/ 删除目录下的文件
    rm -rf /var/it1000 仅删除链接文件本身

    [root@localhost ~]# ln -s /etc /home/
    [root@localhost ~]# rm -rf /home/etc/
    ====================================================================================




  • 相关阅读:
    Oracle中的带参数的视图--我们致力于打造人力资源软件
    (免费)在线演示人力资源管理系统--源自偕行软件
    打造国内第一个支持在线演示的人力资源管理系统--源自偕行软件
    Silverlight C1.Silverlight.FlexGrid 表格动态列
    SILVERLIGHT 多维表头、复杂表头 MULTIPLE HEADER
    weixin JS 接口调用代码
    盒布局
    焦点不在input或textarea中,屏蔽回格按钮
    CSS3多栏布局
    AJAX
  • 原文地址:https://www.cnblogs.com/anttech/p/10612341.html
Copyright © 2011-2022 走看看