zoukankan      html  css  js  c++  java
  • linux文件系统与链接

    Linux的文件属性图1

                                     图1   linux的文件属性      

    ls -lhi

       -l 长格式

       -h 人性化

       -i inodo   

       -d 看目录自己的信息

    inode

        源自于文件系统

        分区

        平面设计图

    格式化

        施工

    文件系统    

        windows

            NTFS

            FAT32(淘汰)

                允许的单个文件大小不超过4G

        Linux 

            ext4

            xft

    inode包含文件的元信息,具体来说有以下内容

        *文件的字节数

        *文件拥有者的User ID

        *文件的Group ID

        *文件的读、写、执行权限

        *

    文件的时间戳,共有三个,ctime指inode上一次变动的时间,mtime指文件上一次变动的时间,atime指文件上一次打开的时间

        *链接数,即有多少个文件名指向inode

        *文件数据block的位置

    [root@localhost ~]# ls -lhd /etc/

    drwxr-xr-x. 75 root root 8.0K Oct 21 10:49 /etc/

    [root@localhost ~]# du -sh /etc/

    31M/etc/

        df -ih 

    Linux系统文件类型

    ls -l /tmp/test //看第一个字符

    格式          说明

      -    普通文件(文本文件,二进制文件,压缩文件,图片文件)

      d    目录文件(深蓝色)

      b    设备文件(块设备)存储设备硬盘 /dev/sda,/dev/sda1

      c    设备文件(字符设备),终端/dev/tty1,/dev/zero

      s    套接字文件,进程间通信

      p    管道文件

      l    链接文件(浅蓝色)

      

    //示例  

    [root@localhost ~]# ls -ld /etc/hosts /tmp /bin/ls /dev/sda /dev/tty1 /etc/grub2.cfg /dev/log /run/systemd/initctl/fifo 

    -rwxr-xr-x. 1 root root 117608 Aug 20 14:25 /bin/ls

    srw-rw-rw-  1 root root      0 Oct 21 08:40 /dev/log

    brw-rw----  1 root disk   8, 0 Oct 21 08:41 /dev/sda

    crw--w----  1 root tty    4, 1 Oct 21 08:41 /dev/tty1

    lrwxrwxrwx. 1 root root     22 Oct 18 18:41 /etc/grub2.cfg -> ../boot/grub2/grub.cfg

    -rw-r--r--. 1 root root    158 Jun  7  2013 /etc/hosts

    prw-------  1 root root      0 Oct 21 08:40 /run/systemd/initctl/fifo

    drwxrwxrwt. 7 root root    211 Oct 21 12:00 /tmp

    查看文件类型命令file

    [root@localhost ~]# file /etc/hosts

    /etc/hosts: ASCII text

    [root@localhost ~]# file /tmp/

    /tmp/: sticky directory

    [root@localhost ~]# file /bin/ls

    /bin/ls: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=aaf05615b6c91d3cbb076af81aeff531c5d7dfd9, stripped

    [root@localhost ~]# file /dev/sda

    /dev/sda: block special

    [root@localhost ~]# file /dev/log

    /dev/log: socket

    [root@localhost ~]# file /dev/tty1

    /dev/tty1: character special

    [root@localhost ~]# file /etc/grub2.cfg 

    /etc/grub2.cfg: symbolic link to `../boot/grub2/grub.cfg'

    [root@localhost ~]# file /run/systemd/initctl/fifo 

    /run/systemd/initctl/fifo: fifo (named pipe)

    注:

    通过文件后缀跟颜色判断文件类型不一定准确

    文件扩展名不代表任何含义,仅为了好识别

    Linux系统链接文件

    软链接 

    Linux里的软链接文件类似于Windows系统中的“快捷方式”里面具体存放的是源文件的路劲,并指向源文件实体,因此通过访问这个

    “快捷方式”可迅速访问到源文件。软链接文件类型是l。

    我们只需要执行命令“ln -s 源文件 软链接文件”完成软链接创建

    注意:软链接和源文件是不同类型的文件,所以inode也不同

    软链接实际应用示例 图2

                           图2       软链接现实生活应用图(例) 

    //文件软链接示例

    [root@localhost ~]# ln -s 1.txt 1.txt.bak

    [root@localhost ~]# ls -l 1.txt*

    -rw-r--r-- 1 root root 26 Oct 21 15:42 1.txt

    lrwxrwxrwx 1 root root  5 Oct 21 15:45 1.txt.bak -> 1.txt

    //目录软链接演示

    [root@localhost ~]# ln -s /etc/ etc.link

    [root@localhost ~]# ls -lid /etc/ etc.link

    16777281 drwxr-xr-x. 75 root root 8192 Oct 21 10:49 /etc/

    33594255 lrwxrwxrwx   1 root root    5 Oct 21 15:51 etc.link -> /etc/

    生产软链接的作用

    1、软件升级

    2、企业代码发布

    3、不方便目录移动

    注意:

    软链接要使用绝对路径

    软链接既可以对文件也可以对目录

    硬链接

    Linux文件系统中,多个文件名指向同一个索引节点(Inode)是正常且允许的(文件的多个有效的入口),这种

    情况的文件称为硬链接。通过执行“ln 源文件 硬链接文件”给文件设置硬链接,来防止重要文件被误删。

    注意:目录不能创建硬链接,硬链接文件可以用rm命令删除

    硬链接与备份的区别  图三

                          图3               硬链接与备份的区别

    //文件硬链接演示

    ln 1.txt 1.txt.bak

    [root@localhost ~]# ls -lid 1.txt*

    33594220 -rw-r--r-- 2 root root 26 Oct 21 15:42 1.txt

    33594256 lrwxrwxrwx 1 root root  5 Oct 21 16:27 1.txt.bak -> 1.txt

    33594220 -rw-r--r-- 2 root root 26 Oct 21 15:42 1.txt.hard

    Linux软链接与硬链接的区别

    1、1n命令不能创建硬链接,ln-s命令创建软链接

    2、目录不能创建硬链接,并且硬链接不能跨越分区系统

    3、目录软链接特别常用,并且软链接支持跨越分区系统

    4、硬链接文件与源文件的inode相同,软链接文件与源文件inode不同

    5、删除软链接文件,对源文件及硬链接文件无任何影响

    6、删除文件的硬链接文件,对源文件及链接文件无任何影响

    7、删除链接文件的源文件,对源文件无影响,会导致软链接失效

    8、删除源文件及其硬链接文件,整个文件会被真正的删除

  • 相关阅读:
    hdu5441Travel【并查集】
    笔试题 brotherword【tire || hash】
    20150917
    字典树模板
    三维凸包模板
    HUST1341A Simple Task【模拟】
    hust1350Trie【字典树+dfs || 字典树 + LCA】
    kmp笔试题。。
    poj3461Oulipo【kmp】
    【转帖】如何看外文文献
  • 原文地址:https://www.cnblogs.com/xmtxh/p/11722178.html
Copyright © 2011-2022 走看看