linux文件属性和类型、系统链接文件、软链接和硬链接

文件属性和类型

[root@wzh ~]# ll -d wzh
d  rwxr-xr-x.  2  root  root  6 Mar 26 06:27 wzh
目录 ,权限   硬链接数 属主 属组 文件大小 创建修改时间文件名
-:普通⽂件
d:⽬录⽂件
rw- --- --- :权限
rwx r-x r-x :权限
r:读 read
w:写 write
x:执⾏权限 execute
-:普通⽂件
d:directory ⽬录⽂件
c:char 字符设备⽂件
b:block 块设备⽂件(⽤来存储数据的设备)
s:socket,安全套接字⽂件
l:link 软链接⽂件(快捷⽅式)
p:pipe 管道⽂件
注意:通过颜⾊或者后缀判断⽂件类型不⼀定准确.

系统链接文件

⼀个⽂件分为两部分:
真实数据
元数据
block:真实数据占⽤的空间:19G
inode:元数据占⽤的空间 :9G

软链接和硬链接

软链接
软链接相当于windows的快捷⽅式,软链接⽂件会将 inode 指向源⽂件的 block
1.那么当我们对⼀个⽂件创建多个软链接时,其实就是多个 inode 指向同⼀个 block 。 2.那么当我们
删除软链接⽂件时,其实只是删除了⼀个 inode 的指向,并不会对源⽂件造成影响。 3.如果我们删除的
是源⽂件,那么该⽂件的所有软链接⽂件都会失效。
2.软链接的应⽤场景 1)软件升级 2)代码发布 3)不⽅便移动的⽬录 4)数据回滚 5)程序读取
硬链接和源文件一样,删除了源文件软链接可以操作
#1. 创建命令不同
硬链接: ln
软链接: ln -s
#2. ⽬录⽆法创建硬链接,可以创建软链接,硬链接不能跨系统的分区,软链接可以
#3. 硬链接⽂件与源⽂件的inode号相同,软链接不同
#4. 软链接如果删除源⽂件,所有软链接⽂件失效,硬链接如果删除源⽂件,其他硬链接⽂件均可以
硬链接:[root@wzh ~]# ll -i /tmp/ys
33605428 -rw-r--r--. 2 root root 0 Mar 26 06:43 /tmp/ys
[root@wzh ~]# ll -i 123
33605428 -rw-r--r--. 2 root root 0 Mar 26 06:43 123
软链接
[root@wzh ~]# ll -i /opt/w
17354516 lrwxrwxrwx. 1 root root 9 Mar 26 06:52 /opt/w -> /root/wyf
[root@wzh ~]# ll -i wyf
total 0
[root@wzh ~]# ll -hi wyf
total 0
[root@wzh ~]# ll -d wyf
drwxr-xr-x. 2 root root 6 Mar 26 06:52 wyf
[root@wzh ~]# ll -di wyf
793418 drwxr-xr-x. 2 root root 6 Mar 26 06:52 wyf

linux文件属性和类型、系统链接文件、软链接和硬链接_第1张图片

[root@wzh ~]#  dd if=/dev/zero of=/opt/disk bs=1K count=1024
1024+0 records in
1024+0 records out
1048576 bytes (1.0 MB) copied, 0.00343602 s, 305 MB/s
[root@wzh ~]#  mkfs.ext4 -i 1024 /opt/disk
mke2fs 1.42.9 (28-Dec-2013)
/opt/disk is not a block special device.
Proceed anyway? (y,n) y

Filesystem too small for a journal
Discarding device blocks: done                            
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
1024 inodes, 1024 blocks
51 blocks (4.98%) reserved for the super user
First data block=1
Maximum filesystem blocks=1048576
1 block group
8192 blocks per group, 8192 fragments per group
1024 inodes per group

Allocating group tables: done                            
Writing inode tables: done                            
Writing superblocks and filesystem accounting information: done

[root@wzh opt]# mkdir data1
[root@wzh opt]# mount -t ext4 -o loop /opt/disk /data1
[root@wzh data1]# touch {1000..10000}
touch: cannot touch ‘9963’: No space left on device
touch: cannot touch ‘9964’: No space left on device
touch: cannot touch ‘9965’: No space left on device
touch: cannot touch ‘9966’: No space left on device
touch: cannot touch ‘9967’: No space left on device
touch: cannot touch ‘9968’: No space left on device
touch: cannot touch ‘9969’: No space left on device
touch: cannot touch ‘9970’: No space left on device
touch: cannot touch ‘9971’: No space left on device
touch: cannot touch ‘9972’: No space left on device
touch: cannot touch ‘9973’: No space left on device
touch: cannot touch ‘9974’: No space left on device
touch: cannot touch ‘9975’: No space left on device
touch: cannot touch ‘9976’: No space left on device
touch: cannot touch ‘9977’: No space left on device
touch: cannot touch ‘9978’: No space left on device
touch: cannot touch ‘9979’: No space left on device
touch: cannot touch ‘9980’: No space left on device
touch: cannot touch ‘9981’: No space left on device
touch: cannot touch ‘9982’: No space left on device
touch: cannot touch ‘9983’: No space left on device
touch: cannot touch ‘9984’: No space left on device
touch: cannot touch ‘9985’: No space left on device
touch: cannot touch ‘9986’: No space left on device
touch: cannot touch ‘9987’: No space left on device
touch: cannot touch ‘9988’: No space left on device
touch: cannot touch ‘9989’: No space left on device
touch: cannot touch ‘9990’: No space left on device
touch: cannot touch ‘9991’: No space left on device
touch: cannot touch ‘9992’: No space left on device
touch: cannot touch ‘9993’: No space left on device
touch: cannot touch ‘9994’: No space left on device
touch: cannot touch ‘9995’: No space left on device
touch: cannot touch ‘9996’: No space left on device
touch: cannot touch ‘9997’: No space left on device
touch: cannot touch ‘9998’: No space left on device
touch: cannot touch ‘9999’: No space left on device
touch: cannot touch ‘10000’: No space left on device
出现这种情况查看磁盘
[root@wzh data1]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        18G  1.5G   17G   8% /
devtmpfs        476M     0  476M   0% /dev
tmpfs           487M     0  487M   0% /dev/shm
tmpfs           487M  7.7M  479M   2% /run
tmpfs           487M     0  487M   0% /sys/fs/cgroup
/dev/sda1      1014M  127M  888M  13% /boot
tmpfs            98M     0   98M   0% /run/user/0
/dev/loop0      891K   40K  780K   5% /data1
发现磁盘没满,再查看inode
[root@wzh data1]# df -i
Filesystem      Inodes  IUsed   IFree IUse% Mounted on
/dev/sda3      9436672 122444 9314228    2% /
devtmpfs        121774    385  121389    1% /dev
tmpfs           124487      1  124486    1% /dev/shm
tmpfs           124487    719  123768    1% /run
tmpfs           124487     16  124471    1% /sys/fs/cgroup
/dev/sda1       524288    326  523962    1% /boot
tmpfs           124487      1  124486    1% /run/user/0
/dev/loop0        1024   1024       0  100% /data1
原来是data1的inode满了
删除没用的空文件
找出占用最多的
[root@wzh data1]# for i in /*; do echo $i; find $i | wc -l; done
/bin
1
/boot
324
/data1
1015
/dev
387
/etc
2379
/home
22
/lib
1
/lib64
1
/media
1
/mnt
1
/oldboy
42
/oldgirl
34
/opt
90004
/proc
33457
/root
9
/run
719
/sbin
1
/srv
1
/sys
48492
/tmp
19
/usr
29579
/var
4381
/wzhh
12
继续寻找opt下的
[root@wzh data1]# for i in /opt/*; do echo $i; find $i | wc -l; done
/opt/data1
90002
/opt/disk
1
删除opt下大小为0的文件
[root@wzh data1]# find /opt/* -name "*" -type f -size 0c | xargs -n 1 rm -f
[root@wzh data1]# ll /opt
total 240
drwxr-xr-x. 2 root root       6 Mar 26 06:20 data1
-rw-r--r--. 1 root root 1048576 Mar 26 06:01 disk
再看下
[root@wzh data1]# df -i
Filesystem      Inodes IUsed   IFree IUse% Mounted on
/dev/sda3      9436672 32443 9404229    1% /
devtmpfs        121774   385  121389    1% /dev
tmpfs           124487     1  124486    1% /dev/shm
tmpfs           124487   719  123768    1% /run
tmpfs           124487    16  124471    1% /sys/fs/cgroup
/dev/sda1       524288   326  523962    1% /boot
tmpfs           124487     1  124486    1% /run/user/0
/dev/loop0        1024  1024       0  100% /data1
发现还是满的,那就删除data1下大小为0的文件
[root@wzh data1]# find /data1/* -name "*" -type f -size 0c | xargs -n 1 rm -f
[root@wzh data1]# df -i
Filesystem      Inodes IUsed   IFree IUse% Mounted on
/dev/sda3      9436672 32443 9404229    1% /
devtmpfs        121774   385  121389    1% /dev
tmpfs           124487     1  124486    1% /dev/shm
tmpfs           124487   719  123768    1% /run
tmpfs           124487    16  124471    1% /sys/fs/cgroup
/dev/sda1       524288   326  523962    1% /boot
tmpfs           124487     1  124486    1% /run/user/0
/dev/loop0        1024    11    1013    2% /data1
这样就好了

你可能感兴趣的:(linux文件属性和类型、系统链接文件、软链接和硬链接)