4.5 文件系统管理
4.5.1 df - report file system disk space usage
-h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G)
-H, --si likewise, but use powers of 1000 not 1024
-i, --inodes list inode information instead of block usage
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/rhel-root 10229760 4194692 6035068 42% /
/dev/mapper/rhel-home 2037760 33032 2004728 2% /home
/dev/sda1 508588 121208 387380 24% /boot
[root@localhost ~]# df -h #以可读的方式显示,即GB
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 9.8G 4.1G 5.8G 42% /
/dev/mapper/rhel-home 2.0G 33M 2.0G 2% /home
/dev/sda1 497M 119M 379M 24% /boot
[root@localhost ~]# df -H #以1000换算
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 11G 4.3G 6.2G 42% /
/dev/mapper/rhel-home 2.1G 34M 2.1G 2% /home
/dev/sda1 521M 125M 397M 24% /boot
[root@localhost ~]# df -i #显示inode使用情况
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/mapper/rhel-root 10240000 152278 10087722 2% /
/dev/mapper/rhel-home 2048000 31 2047969 1% /home
/dev/sda1 512000 328 511672 1% /boot
[root@localhost ~]# df -h /dev/sda1 #查看某一特定文件系统
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 497M 119M 379M 24% /boot
4.5.2 du - estimate file space usage
[root@localhost tmp]# du #查看当前目录容量
[root@localhost tmp]# du --inode #查看当前目录的inode使用情况
[root@localhost tmp]# du -s #显示当前目录的总量
[root@localhost tmp]# du -s /etc/ #显示/etc目录的总量
本章同步视频:https://edu.51cto.com/sd/e48744.5.3 ln - make links between files
ln [OPTION]... [-T] TARGET LINK_NAME
-s :如果不加任何参数就进行连结,那就是hard link,至于 -s 就是symbolic link
-f :如果 目标档 存在时,就主动的将目标档直接移除后再建立!
[root@localhost tmp]# ls #查看当前文件
dir mbr mbr.l passwd root test
[root@localhost tmp]# ln mbr mbr.l #建立硬链接
[root@localhost tmp]# ll -i mbr* #查看源文件和硬链接
7562 -rw-r--r--. 2 root root 512 Mar 18 21:57 mbr
7562 -rw-r--r--. 2 root root 512 Mar 18 21:57 mbr.l
[root@localhost tmp]# rm -f mbr #删除源文件
-rw-r--r--. 1 root root 512 Mar 18 21:57 mbr.l
lrwxrwxrwx. 1 root root 3 Mar 20 12:23 mbr.s -> mbr
[root@localhost tmp]# cat mbr.l #硬链接仍可打开
[root@localhost tmp]# ln dir dir.l
ln: ‘dir’: hard link not allowed for directory
[root@localhost tmp]# ln -s mbr mbr.s
[root@localhost tmp]# ll -i mbr*
7562 -rw-r--r--. 2 root root 512 Mar 18 21:57 mbr
7562 -rw-r--r--. 2 root root 512 Mar 18 21:57 mbr.l
7595 lrwxrwxrwx. 1 root root 3 Mar 20 12:23 mbr.s -> mbr
l 当来源档被删除之后,symbolic link 就会失效。
[root@localhost tmp]# rm -f mbr #删除源文件
-rw-r--r--. 1 root root 512 Mar 18 21:57 mbr.l
lrwxrwxrwx. 1 root root 3 Mar 20 12:23 mbr.s -> mbr
[root@localhost tmp]# cat mbr.s #软连接无法打开
cat: mbr.s: No such file or directory
l Symbolic Link 与 Windows 的快捷方式可以给他划上等号。
[root@localhost tmp]# touch hard
-rw-r--r--. 1 root root 0 Mar 20 12:42 hard
[root@localhost tmp]# ln -s hard hard.s
-rw-r--r--. 1 root root 0 Mar 20 12:42 hard
[root@localhost tmp]# ln hard hard.l
[root@localhost tmp]# ll hard*
-rw-r--r--. 2 root root 0 Mar 20 12:42 hard
-rw-r--r--. 2 root root 0 Mar 20 12:42 hard.l
lrwxrwxrwx. 1 root root 4 Mar 20 12:42 hard.s -> hard
#建立一个硬链接,源文件和硬链接的链接数+1,软链接的链接数不增加。
[root@localhost tmp]# mkdir dir
[root@localhost tmp]# ll -d dir
drwxr-xr-x. 2 root root 6 Mar 20 12:36 dir
[root@localhost tmp]# ll -a dir
drwxr-xr-x. 2 root root 6 Mar 20 12:36 .
drwxrwxrwt. 9 root root 4096 Mar 20 12:36 ..
[root@localhost tmp]# mkdir dir/dir1
[root@localhost tmp]# ll -d dir
drwxr-xr-x. 3 root root 17 Mar 20 12:38 dir
[root@localhost tmp]# touch dir/aaa
[root@localhost tmp]# ll -d dir/
drwxr-xr-x. 3 root root 27 Mar 20 12:39 dir/
[root@localhost tmp]# mkdir dir/dir1/dir2
[root@localhost tmp]# ll -d dir/
drwxr-xr-x. 3 root root 27 Mar 20 12:39 dir/
#创建一个“孙”目录,“爷”目录的链接数不会增加,但父目录的链接数会+1。
本章同步视频:https://edu.51cto.com/sd/e4874