<返回

鸟哥的linux私房菜:基础学习篇 范例汇总

时间:2022-04-03

----------------------------------------------------------------------------------------------------
[root@study ~]# chown [-R] 帐号名称 文件或目录
[root@study ~]# chown [-R] 帐号名称:群组名称 文件或目录
选项与参数:
-R : 进行递回(recursive)的持续变更,亦即连同次目录下的所有文件都变更

范例:将 initial-setup-ks.cfg 的拥有者改为bin这个帐号:
[root@study ~]# chown bin initial-setup-ks.cfg
[root@study ~]# ls -l
-rw-r--r--. 1 bin  users 1864 May  4 18:01 initial-setup-ks.cfg

范例:将 initial-setup-ks.cfg 的拥有者与群组改回为root:
[root@study ~]# chown root:root initial-setup-ks.cfg
[root@study ~]# ls -l
-rw-r--r--. 1 root root 1864 May  4 18:01 initial-setup-ks.cfg
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
[root@study ~]# pwd [-P]
选项与参数:
-P  :显示出确实的路径,而非使用链接 (link) 路径。

范例:单纯显示出目前的工作目录:
[root@study ~]# pwd
/root   <== 显示出目录啦~

范例:显示出实际的工作目录,而非链接文件本身的目录名而已
[root@study ~]# cd /var/mail   <==注意,/var/mail是一个链接文件
[root@study mail]# pwd
/var/mail         <==列出目前的工作目录
[root@study mail]# pwd -P
/var/spool/mail   <==怎么回事?有没有加 -P 差很多~
[root@study mail]# ls -ld /var/mail
lrwxrwxrwx. 1 root root 10 May  4 17:51 /var/mail -> spool/mail
# 看到这里应该知道为啥了吧?因为 /var/mail 是链接文件,链接到 /var/spool/mail
# 所以,加上 pwd -P 的选项后,会不以链接文件的数据显示,而是显示正确的完整路径啊!
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
[root@study ~]# mkdir [-mp] 目录名称
选项与参数:
-m :设置文件的权限喔!直接设置,不需要看默认权限 (umask) 的脸色~
-p :帮助你直接将所需要的目录(包含上层目录)递回创建起来!

范例:请到/tmp下面尝试创建数个新目录看看:
[root@study ~]# cd /tmp
[root@study tmp]# mkdir test    <==创建一名为 test 的新目录
[root@study tmp]# mkdir test1/test2/test3/test4
mkdir: cannot create directory ‘test1/test2/test3/test4’: No such file or directory
# 话说,系统告诉我们,没可能创建这个目录啊!就是没有目录才要创建的!见鬼嘛?
[root@study tmp]# mkdir -p test1/test2/test3/test4
# 原来是要建 test4 上层没先建 test3 之故!加了这个 -p 的选项,可以自行帮你创建多层目录!

范例:创建权限为rwx--x--x的目录
[root@study tmp]# mkdir -m 711 test2
[root@study tmp]# ls -ld test*
drwxr-xr-x. 2 root   root  6 Jun  4 19:03 test
drwxr-xr-x. 3 root   root 18 Jun  4 19:04 test1
drwx--x--x. 2 root   root  6 Jun  4 19:05 test2
# 仔细看上面的权限部分,如果没有加上 -m 来强制设置属性,系统会使用默认属性。
# 那么你的默认属性为何?这要通过下面介绍的 umask 才能了解喔! ^_^
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
[root@study ~]# rmdir [-p] 目录名称
选项与参数:
-p :连同“上层”“空的”目录也一起删除

范例:将于mkdir范例中创建的目录(/tmp下面)删除掉!
[root@study tmp]# ls -ld test*   <==看看有多少目录存在?
drwxr-xr-x. 2 root   root  6 Jun  4 19:03 test
drwxr-xr-x. 3 root   root 18 Jun  4 19:04 test1
drwx--x--x. 2 root   root  6 Jun  4 19:05 test2
[root@study tmp]# rmdir test   <==可直接删除掉,没问题
[root@study tmp]# rmdir test1  <==因为尚有内容,所以无法删除!
rmdir: failed to remove ‘test1’: Directory not empty
[root@study tmp]# rmdir -p test1/test2/test3/test4
[root@study tmp]# ls -ld test*    <==您看看,下面的输出中test与test1不见了!
drwx--x--x. 2 root   root  6 Jun  4 19:05 test2
# 瞧!利用 -p 这个选项,立刻就可以将 test1/test2/test3/test4 一次删除~
# 不过要注意的是,这个 rmdir 仅能“删除空的目录”喔!
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
范例:先用root的身份列出搜寻的路径为何?
[root@study ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

范例:用dmtsai的身份列出搜寻的路径为何?
[root@study ~]# exit    # 由之前的 su - 离开,变回原本的帐号!或再取得一个终端机皆可!
[dmtsai@study ~]$ echo $PATH
/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/dmtsai/.local/bin:/home/dmtsai/bin
# 记不记得我们前一章说过,目前 /bin 是链接到 /usr/bin 当中的喔!
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
范例一:将主文件夹下的所有文件列出来(含属性与隐藏文件)
[root@study ~]# ls -al ~
total 56
dr-xr-x---.  5 root root 4096 Jun  4 19:49 .
dr-xr-xr-x. 17 root root 4096 May  4 17:56 ..
-rw-------.  1 root root 1816 May  4 17:57 anaconda-ks.cfg
-rw-------.  1 root root 6798 Jun  4 19:53 .bash_history
-rw-r--r--.  1 root root   18 Dec 29  2013 .bash_logout
-rw-r--r--.  1 root root  176 Dec 29  2013 .bash_profile
-rw-rw-rw-.  1 root root  176 Dec 29  2013 .bashrc
-rw-r--r--.  1 root root  176 Jun  3 00:04 .bashrc_test
drwx------.  4 root root   29 May  6 00:14 .cache
drwxr-xr-x.  3 root root   17 May  6 00:14 .config
# 这个时候你会看到以 . 为开头的几个文件,以及目录档 (.) (..) .config 等等,
# 不过,目录档文件名都是以深蓝色显示,有点不容易看清楚就是了。

范例二:承上题,不显示颜色,但在文件名末显示出该文件名代表的类型(type)
[root@study ~]# ls -alF --color=never  ~
total 56
dr-xr-x---.  5 root root 4096 Jun  4 19:49 ./
dr-xr-xr-x. 17 root root 4096 May  4 17:56 ../
-rw-------.  1 root root 1816 May  4 17:57 anaconda-ks.cfg
-rw-------.  1 root root 6798 Jun  4 19:53 .bash_history
-rw-r--r--.  1 root root   18 Dec 29  2013 .bash_logout
-rw-r--r--.  1 root root  176 Dec 29  2013 .bash_profile
-rw-rw-rw-.  1 root root  176 Dec 29  2013 .bashrc
-rw-r--r--.  1 root root  176 Jun  3 00:04 .bashrc_test
drwx------.  4 root root   29 May  6 00:14 .cache/
drwxr-xr-x.  3 root root   17 May  6 00:14 .config/
# 注意看到显示结果的第一行,嘿嘿~知道为何我们会下达类似 ./command
# 之类的指令了吧?因为 ./ 代表的是“目前目录下”的意思啊!至于什么是 FIFO/Socket ?
# 请参考前一章节的介绍啊!另外,那个.bashrc 时间仅写2013,能否知道详细时间?

范例三:完整的呈现文件的修改时间 (modification time)
[root@study ~]# ls -al --full-time  ~
total 56
dr-xr-x---.  5 root root 4096 2015-06-04 19:49:54.520684829 +0800 .
dr-xr-xr-x. 17 root root 4096 2015-05-04 17:56:38.888000000 +0800 ..
-rw-------.  1 root root 1816 2015-05-04 17:57:02.326000000 +0800 anaconda-ks.cfg
-rw-------.  1 root root 6798 2015-06-04 19:53:41.451684829 +0800 .bash_history
-rw-r--r--.  1 root root   18 2013-12-29 10:26:31.000000000 +0800 .bash_logout
-rw-r--r--.  1 root root  176 2013-12-29 10:26:31.000000000 +0800 .bash_profile
-rw-rw-rw-.  1 root root  176 2013-12-29 10:26:31.000000000 +0800 .bashrc
-rw-r--r--.  1 root root  176 2015-06-03 00:04:16.916684829 +0800 .bashrc_test
drwx------.  4 root root   29 2015-05-06 00:14:56.960764950 +0800 .cache
drwxr-xr-x.  3 root root   17 2015-05-06 00:14:56.975764950 +0800 .config
# 请仔细看,上面的“时间”字段变了喔!变成较为完整的格式。
# 一般来说, ls -al 仅列出目前短格式的时间,有时不会列出年份,
# 借由 --full-time 可以查阅到比较正确的完整时间格式啊!
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
范例一:用root身份,将主文件夹下的 .bashrc 复制到 /tmp 下,并更名为 bashrc
[root@study ~]# cp ~/.bashrc /tmp/bashrc
[root@study ~]# cp -i ~/.bashrc /tmp/bashrc
cp: overwrite `/tmp/bashrc‘? n  <==n不覆盖,y为覆盖
# 重复作两次动作,由于 /tmp 下面已经存在 bashrc 了,加上 -i 选项后,
# 则在覆盖前会询问使用者是否确定!可以按下 n 或者 y 来二次确认呢!

范例二:变换目录到/tmp,并将/var/log/wtmp复制到/tmp且观察属性:
[root@study ~]# cd /tmp
[root@study tmp]# cp /var/log/wtmp . <==想要复制到目前的目录,最后的 . 不要忘
[root@study tmp]# ls -l /var/log/wtmp wtmp
-rw-rw-r--. 1 root utmp 28416 Jun 11 18:56 /var/log/wtmp
-rw-r--r--. 1 root root 28416 Jun 11 19:01 wtmp
# 注意上面的特殊字体,在不加任何选项的情况下,文件的某些属性/权限会改变;
# 这是个很重要的特性!要注意喔!还有,连文件创建的时间也不一样了!
# 那如果你想要将文件的所有特性都一起复制过来该怎办?可以加上 -a 喔!如下所示:

[root@study tmp]# cp -a /var/log/wtmp wtmp_2
[root@study tmp]# ls -l /var/log/wtmp wtmp_2
-rw-rw-r--. 1 root utmp 28416 Jun 11 18:56 /var/log/wtmp
-rw-rw-r--. 1 root utmp 28416 Jun 11 18:56 wtmp_2
# 瞭了吧!整个数据特性完全一模一样ㄟ!真是不赖~这就是 -a 的特性!
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
范例三:复制 /etc/ 这个目录下的所有内容到 /tmp 下面
[root@study tmp]# cp /etc/ /tmp
cp: omitting directory `/etc‘   <== 如果是目录则不能直接复制,要加上 -r 的选项
[root@study tmp]# cp -r /etc/ /tmp
# 还是要再次的强调喔! -r 是可以复制目录,但是,文件与目录的权限可能会被改变
# 所以,也可以利用“ cp -a /etc /tmp ”来下达指令喔!尤其是在备份的情况下!

范例四:将范例一复制的 bashrc 创建一个链接文件 (symbolic link)
[root@study tmp]# ls -l bashrc
-rw-r--r--. 1 root root 176 Jun 11 19:01 bashrc  <==先观察一下文件情况
[root@study tmp]# cp -s bashrc bashrc_slink
[root@study tmp]# cp -l bashrc bashrc_hlink
[root@study tmp]# ls -l bashrc*
-rw-r--r--. 2 root root 176 Jun 11 19:01 bashrc         <==与原始文件不太一样了!
-rw-r--r--. 2 root root 176 Jun 11 19:01 bashrc_hlink
lrwxrwxrwx. 1 root root   6 Jun 11 19:06 bashrc_slink -> bashrc
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
范例五:若 ~/.bashrc 比 /tmp/bashrc 新才复制过来
[root@study tmp]# cp -u ~/.bashrc /tmp/bashrc
# 这个 -u 的特性,是在目标文件与来源文件有差异时,才会复制的。
# 所以,比较常被用于“备份”的工作当中喔! ^_^

范例六:将范例四造成的 bashrc_slink 复制成为 bashrc_slink_1 与bashrc_slink_2
[root@study tmp]# cp bashrc_slink bashrc_slink_1
[root@study tmp]# cp -d bashrc_slink bashrc_slink_2
[root@study tmp]# ls -l bashrc bashrc_slink*
-rw-r--r--. 2 root root 176 Jun 11 19:01 bashrc
lrwxrwxrwx. 1 root root   6 Jun 11 19:06 bashrc_slink -> bashrc
-rw-r--r--. 1 root root 176 Jun 11 19:09 bashrc_slink_1            <==与原始文件相同
lrwxrwxrwx. 1 root root   6 Jun 11 19:10 bashrc_slink_2 -> bashrc  <==是链接文件!
# 这个例子也是很有趣喔!原本复制的是链接文件,但是却将链接文件的实际文件复制过来了
# 也就是说,如果没有加上任何选项时,cp复制的是原始文件,而非链接文件的属性!
# 若要复制链接文件的属性,就得要使用 -d 的选项了!如 bashrc_slink_2 所示。

范例七:将主文件夹的 .bashrc 及 .bash_history 复制到 /tmp 下面
[root@study tmp]# cp ~/.bashrc ~/.bash_history /tmp
# 可以将多个数据一次复制到同一个目录去!最后面一定是目录!
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
[root@study ~]# rm [-fir] 文件或目录
选项与参数:
-f  :就是 force 的意思,忽略不存在的文件,不会出现警告讯息;
-i  :互动模式,在删除前会询问使用者是否动作
-r  :递回删除啊!最常用在目录的删除了!这是非常危险的选项!!!

范例一:将刚刚在 cp 的范例中创建的 bashrc 删除掉!
[root@study ~]# cd /tmp
[root@study tmp]# rm -i bashrc
rm: remove regular file `bashrc‘? y
# 如果加上 -i 的选项就会主动询问喔,避免你删除到错误的文件名!

范例二:通过万用字符*的帮忙,将/tmp下面开头为bashrc的文件名通通删除:
[root@study tmp]# rm -i bashrc*
# 注意那个星号,代表的是 0 到无穷多个任意字符喔!很好用的东西!

范例三:将 cp 范例中所创建的 /tmp/etc/ 这个目录删除掉!
[root@study tmp]# rmdir /tmp/etc
rmdir: failed to remove ‘/tmp/etc‘: Directory not empty   <== 删不掉啊!因为这不是空的目录!
[root@study tmp]# rm -r /tmp/etc
rm: descend into directory `/tmp/etc‘? y
rm: remove regular file `/tmp/etc/fstab‘? y
rm: remove regular empty file `/tmp/etc/crypttab‘? ^C  <== 按下 [crtl]+c 中断
.....(中间省略).....
# 因为身份是 root ,默认已经加入了 -i 的选项,所以你要一直按 y 才会删除!
# 如果不想要继续按 y ,可以按下“ [ctrl]-c ”来结束 rm 的工作。
# 这是一种保护的动作,如果确定要删除掉此目录而不要询问,可以这样做:
[root@study tmp]# \rm -r /tmp/etc
# 在指令前加上反斜线,可以忽略掉 alias 的指定选项喔!至于 alias 我们在bash再谈!
# 拜托!这个范例很可怕!你不要删错了!删除 /etc 系统是会挂掉的!

范例四:删除一个带有 - 开头的文件
[root@study tmp]# touch ./-aaa-  <==touch这个指令可以创建空文件!
[root@study tmp]# ls -l
-rw-r--r--. 1 root   root       0 Jun 11 19:22 -aaa-  <==文件大小为0,所以是空文件
[root@study tmp]# rm -aaa-
rm: invalid option -- ‘a‘                    <== 因为 "-" 是选项嘛!所以系统误判了!
Try ‘rm ./-aaa-‘ to remove the file `-aaa-‘. <== 新的 bash 有给建议的
Try ‘rm --help‘ for more information.
[root@study tmp]# rm ./-aaa-
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
[root@study ~]# mv [-fiu] source destination
[root@study ~]# mv [options] source1 source2 source3 .... directory
选项与参数:
-f  :force 强制的意思,如果目标文件已经存在,不会询问而直接覆盖;
-i  :若目标文件 (destination) 已经存在时,就会询问是否覆盖!
-u  :若目标文件已经存在,且 source 比较新,才会更新 (update)

范例一:复制一文件,创建一目录,将文件移动到目录中
[root@study ~]# cd /tmp
[root@study tmp]# cp ~/.bashrc bashrc
[root@study tmp]# mkdir mvtest
[root@study tmp]# mv bashrc mvtest
# 将某个文件移动到某个目录去,就是这样做!

范例二:将刚刚的目录名称更名为 mvtest2
[root@study tmp]# mv mvtest mvtest2 <== 这样就更名了!简单~
# 其实在 Linux 下面还有个有趣的指令,名称为 rename ,
# 该指令专职进行多个文件名的同时更名,并非针对单一文件名变更,与mv不同。请man rename。

范例三:再创建两个文件,再全部移动到 /tmp/mvtest2 当中
[root@study tmp]# cp ~/.bashrc bashrc1
[root@study tmp]# cp ~/.bashrc bashrc2
[root@study tmp]# mv bashrc1 bashrc2 mvtest2
# 注意到这边,如果有多个来源文件或目录,则最后一个目标文件一定是“目录!”
# 意思是说,将所有的数据移动到该目录的意思!
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
[root@study ~]# cat [-AbEnTv]
选项与参数:
-A  :相当于 -vET 的整合选项,可列出一些特殊字符而不是空白而已;
-b  :列出行号,仅针对非空白行做行号显示,空白行不标行号!
-E  :将结尾的断行字符 $ 显示出来;
-n  :打印出行号,连同空白行也会有行号,与 -b 的选项不同;
-T  :将 [tab] 按键以 ^I 显示出来;
-v  :列出一些看不出来的特殊字符

范例一:检阅 /etc/issue 这个文件的内容
[root@study ~]# cat /etc/issue
\S
Kernel \r on an \m

范例二:承上题,如果还要加印行号呢?
[root@study ~]# cat -n /etc/issue
     1  \S
     2  Kernel \r on an \m
     3
# 所以这个文件有三行!看到了吧!可以印出行号呢!这对于大文件要找某个特定的行时,有点用处!
# 如果不想要编排空白行的行号,可以使用“cat -b /etc/issue”,自己测试看看:

范例三:将 /etc/man_db.conf 的内容完整的显示出来(包含特殊字符)
[root@study ~]# cat -A /etc/man_db.conf
# $
....(中间省略)....
MANPATH_MAP^I/bin^I^I^I/usr/share/man$
MANPATH_MAP^I/usr/bin^I^I/usr/share/man$
MANPATH_MAP^I/sbin^I^I^I/usr/share/man$
MANPATH_MAP^I/usr/sbin^I^I/usr/share/man$
.....(下面省略).....
# 上面的结果限于篇幅,鸟哥删除掉很多数据了。另外,输出的结果并不会有特殊字体,
# 鸟哥上面的特殊字体是要让您发现差异点在哪里就是了。基本上,在一般的环境中,
# 使用 [tab] 与空白键的效果差不多,都是一堆空白啊!我们无法知道两者的差别。
# 此时使用 cat -A 就能够发现那些空白的地方是啥鬼东西了![tab]会以 ^I 表示,
# 断行字符则是以 $ 表示,所以你可以发现每一行后面都是 $ 啊!不过断行字符
# 在Windows/Linux则不太相同,Windows的断行字符是 ^M$ 啰。
# 这部分我们会在第九章 vim 软件的介绍时,再次的说明到喔!
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
[root@study ~]# tac /etc/issue

Kernel \r on an \m
\S
# 嘿嘿!与刚刚上面的范例一比较,是由最后一行先显示喔!
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
[root@study ~]# nl [-bnw] 文件
选项与参数:
-b  :指定行号指定的方式,主要有两种:
      -b a :表示不论是否为空行,也同样列出行号(类似 cat -n);
      -b t :如果有空行,空的那一行不要列出行号(默认值);
-n  :列出行号表示的方法,主要有三种:
      -n ln :行号在屏幕的最左方显示;
      -n rn :行号在自己字段的最右方显示,且不加 0 ;
      -n rz :行号在自己字段的最右方显示,且加 0 ;
-w  :行号字段的占用的字符数。

范例一:用 nl 列出 /etc/issue 的内容
[root@study ~]# nl /etc/issue
     1  \S
     2  Kernel \r on an \m

# 注意看,这个文件其实有三行,第三行为空白(没有任何字符),
# 因为他是空白行,所以 nl 不会加上行号喔!如果确定要加上行号,可以这样做:

[root@study ~]# nl -b a /etc/issue
     1  \S
     2  Kernel \r on an \m
     3
# 呵呵!行号加上来啰~那么如果要让行号前面自动补上 0 呢?可这样

[root@study ~]# nl -b a -n rz /etc/issue
000001  \S
000002  Kernel \r on an \m
000003
# 嘿嘿!自动在自己字段的地方补上 0 了~默认字段是六位数,如果想要改成 3 位数?

[root@study ~]# nl -b a -n rz -w 3 /etc/issue
001     \S
002     Kernel \r on an \m
003
# 变成仅有 3 位数啰~
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
[root@study ~]# head [-n number] 文件
选项与参数:
-n  :后面接数字,代表显示几行的意思

[root@study ~]# head /etc/man_db.conf
# 默认的情况中,显示前面十行!若要显示前 20 行,就得要这样:
[root@study ~]# head -n 20 /etc/man_db.conf

范例:如果后面100行的数据都不打印,只打印/etc/man_db.conf的前面几行,该如何是好?
[root@study ~]# head -n -100 /etc/man_db.conf
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
[root@study ~]# tail [-n number] 文件
选项与参数:
-n  :后面接数字,代表显示几行的意思
-f  :表示持续侦测后面所接的文件名,要等到按下[ctrl]-c才会结束tail的侦测

[root@study ~]# tail /etc/man_db.conf
# 默认的情况中,显示最后的十行!若要显示最后的 20 行,就得要这样:
[root@study ~]# tail -n 20 /etc/man_db.conf

范例一:如果不知道/etc/man_db.conf有几行,却只想列出100行以后的数据时?
[root@study ~]# tail -n +100 /etc/man_db.conf

范例二:持续侦测/var/log/messages的内容
[root@study ~]# tail -f /var/log/messages
  <==要等到输入[crtl]-c之后才会离开tail这个指令的侦测!
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
[root@study ~]# od [-t TYPE] 文件
选项或参数:
-t  :后面可以接各种“类型 (TYPE)”的输出,例如:
      a       :利用默认的字符来输出;
      c       :使用 ASCII 字符来输出
      d[size] :利用十进制(decimal)来输出数据,每个整数占用 size Bytes ;
      f[size] :利用浮点数值(floating)来输出数据,每个数占用 size Bytes ;
      o[size] :利用八进位(octal)来输出数据,每个整数占用 size Bytes ;
      x[size] :利用十六进制(hexadecimal)来输出数据,每个整数占用 size Bytes ;

范例一:请将/usr/bin/passwd的内容使用ASCII方式来展现!
[root@study ~]# od -t c /usr/bin/passwd
0000000 177   E   L   F 002 001 001  \0  \0  \0  \0  \0  \0  \0  \0  \0
0000020 003  \0   >  \0 001  \0  \0  \0 364   3  \0  \0  \0  \0  \0  \0
0000040   @  \0  \0  \0  \0  \0  \0  \0   x   e  \0  \0  \0  \0  \0  \0
0000060  \0  \0  \0  \0   @  \0   8  \0  \t  \0   @  \0 035  \0 034  \0
0000100 006  \0  \0  \0 005  \0  \0  \0   @  \0  \0  \0  \0  \0  \0  \0
.....(后面省略)....
# 最左边第一栏是以 8 进位来表示Bytes数。以上面范例来说,第二栏0000020代表开头是
# 第 16 个 byes (2x8) 的内容之意。

范例二:请将/etc/issue这个文件的内容以8进位列出储存值与ASCII的对照表
[root@study ~]# od -t oCc /etc/issue
0000000 134 123 012 113 145 162 156 145 154 040 134 162 040 157 156 040
          \   S  \n   K   e   r   n   e   l       \   r       o   n
0000020 141 156 040 134 155 012 012
          a   n       \   m  \n  \n
0000027
# 如上所示,可以发现每个字符可以对应到的数值为何!要注意的是,该数值是 8 进位喔!
# 例如 S 对应的记录数值为 123 ,转成十进制:1x8^2+2x8+3=83。
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
[root@study ~]# touch [-acdmt] 文件
选项与参数:
-a  :仅修订 access time;
-c  :仅修改文件的时间,若该文件不存在则不创建新文件;
-d  :后面可以接欲修订的日期而不用目前的日期,也可以使用 --date="日期或时间"
-m  :仅修改 mtime ;
-t  :后面可以接欲修订的时间而不用目前的时间,格式为[YYYYMMDDhhmm]

范例一:新建一个空的文件并观察时间
[dmtsai@study ~]# cd /tmp
[dmtsai@study tmp]# touch testtouch
[dmtsai@study tmp]# ls -l testtouch
-rw-rw-r--. 1 dmtsai dmtsai 0 Jun 16 00:45 testtouch
# 注意到,这个文件的大小是 0 呢!在默认的状态下,如果 touch 后面有接文件,
# 则该文件的三个时间 (atime/ctime/mtime) 都会更新为目前的时间。若该文件不存在,
# 则会主动的创建一个新的空的文件喔!例如上面这个例子!

范例二:将 ~/.bashrc 复制成为 bashrc,假设复制完全的属性,检查其日期
[dmtsai@study tmp]# cp -a ~/.bashrc bashrc
[dmtsai@study tmp]# date; ll bashrc; ll --time=atime bashrc; ll --time=ctime bashrc
Tue Jun 16 00:49:24 CST 2015                         <==这是目前的时间
-rw-r--r--. 1 dmtsai dmtsai 231 Mar  6 06:06 bashrc  <==这是 mtime
-rw-r--r--. 1 dmtsai dmtsai 231 Jun 15 23:44 bashrc  <==这是 atime
-rw-r--r--. 1 dmtsai dmtsai 231 Jun 16 00:47 bashrc  <==这是 ctime
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
范例三:修改案例二的 bashrc 文件,将日期调整为两天前
[dmtsai@study tmp]# touch -d "2 days ago" bashrc
[dmtsai@study tmp]# date; ll bashrc; ll --time=atime bashrc; ll --time=ctime bashrc
Tue Jun 16 00:51:52 CST 2015
-rw-r--r--. 1 dmtsai dmtsai 231 Jun 14 00:51 bashrc
-rw-r--r--. 1 dmtsai dmtsai 231 Jun 14 00:51 bashrc
-rw-r--r--. 1 dmtsai dmtsai 231 Jun 16 00:51 bashrc
# 跟上个范例比较看看,本来是 16 日变成 14 日了 (atime/mtime)~不过, ctime 并没有跟着改变喔!

范例四:将上个范例的 bashrc 日期改为 2014/06/15 2:02
[dmtsai@study tmp]# touch -t 201406150202 bashrc
[dmtsai@study tmp]# date; ll bashrc; ll --time=atime bashrc; ll --time=ctime bashrc
Tue Jun 16 00:54:07 CST 2015
-rw-r--r--. 1 dmtsai dmtsai 231 Jun 15  2014 bashrc
-rw-r--r--. 1 dmtsai dmtsai 231 Jun 15  2014 bashrc
-rw-r--r--. 1 dmtsai dmtsai 231 Jun 16 00:54 bashrc
# 注意看看,日期在 atime 与 mtime 都改变了,但是 ctime 则是记录目前的时间!
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
[root@study ~]# chattr [+-=][ASacdistu] 文件或目录名称
选项与参数:
+   :增加某一个特殊参数,其他原本存在参数则不动。
-   :移除某一个特殊参数,其他原本存在参数则不动。
=   :设置一定,且仅有后面接的参数

A  :当设置了 A 这个属性时,若你有存取此文件(或目录)时,他的存取时间 atime 将不会被修改,
     可避免 I/O 较慢的机器过度的存取磁盘。(目前建议使用文件系统挂载参数处理这个项目)
S  :一般文件是非同步写入磁盘的(原理请参考前一章sync的说明),如果加上 S 这个属性时,
     当你进行任何文件的修改,该更动会“同步”写入磁盘中。
a  :当设置 a 之后,这个文件将只能增加数据,而不能删除也不能修改数据,只有root 才能设置这属性
c  :这个属性设置之后,将会自动的将此文件“压缩”,在读取的时候将会自动解压缩,
     但是在储存的时候,将会先进行压缩后再储存(看来对于大文件似乎蛮有用的!)
d  :当 dump 程序被执行的时候,设置 d 属性将可使该文件(或目录)不会被 dump 备份
i  :这个 i 可就很厉害了!他可以让一个文件“不能被删除、改名、设置链接也无法写入或新增数据!”
     对于系统安全性有相当大的助益!只有 root 能设置此属性
s  :当文件设置了 s 属性时,如果这个文件被删除,他将会被完全的移除出这个硬盘空间,
     所以如果误删了,完全无法救回来了喔!
u  :与 s 相反的,当使用 u 来设置文件时,如果该文件被删除了,则数据内容其实还存在磁盘中,
     可以使用来救援该文件喔!
注意1:属性设置常见的是 a 与 i 的设置值,而且很多设置值必须要身为 root 才能设置
注意2:xfs 文件系统仅支持 AadiS 而已

范例:请尝试到/tmp下面创建文件,并加入 i 的参数,尝试删除看看。
[root@study ~]# cd /tmp
[root@study tmp]# touch attrtest     <==创建一个空文件
[root@study tmp]# chattr +i attrtest <==给予 i 的属性
[root@study tmp]# rm attrtest        <==尝试删除看看
rm: remove regular empty file `attrtest‘? y
rm: cannot remove `attrtest‘: Operation not permitted
# 看到了吗?呼呼!连 root 也没有办法将这个文件删除呢!赶紧解除设置!

范例:请将该文件的 i 属性取消!
[root@study tmp]# chattr -i attrtest
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
[root@study ~]# which [-a] command
选项或参数:
-a :将所有由 PATH 目录中可以找到的指令均列出,而不止第一个被找到的指令名称

范例一:搜寻 ifconfig 这个指令的完整文件名
[root@study ~]# which ifconfig
/sbin/ifconfig

范例二:用 which 去找出 which 的文件名为何?
[root@study ~]# which which
alias which=‘alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde‘
        /bin/alias
        /usr/bin/which
# 竟然会有两个 which ,其中一个是 alias 这玩意儿呢!那是啥?
# 那就是所谓的“命令别名”,意思是输入 which 会等于后面接的那串指令啦!
# 更多的数据我们会在 bash 章节中再来谈的!

范例三:请找出 history 这个指令的完整文件名
[root@study ~]# which history
/usr/bin/which: no history in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:
/usr/sbin:/usr/bin:/root/bin)

[root@study ~]# history --help
-bash: history: --: invalid option
history: usage: history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg
# 瞎密?怎么可能没有 history ,我明明就能够用 root 执行 history 的啊!
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
[root@study ~]# whereis [-bmsu] 文件或目录名
选项与参数:
-l    :可以列出 whereis 会去查询的几个主要目录而已
-b    :只找 binary 格式的文件
-m    :只找在说明文档 manual 路径下的文件
-s    :只找 source 来源文件
-u    :搜寻不在上述三个项目当中的其他特殊文件

范例一:请找出 ifconfig 这个文件名
[root@study ~]# whereis ifconfig
ifconfig: /sbin/ifconfig /usr/share/man/man8/ifconfig.8.gz

范例二:只找出跟 passwd 有关的“说明文档”文件名(man page)
[root@study ~]# whereis passwd     # 全部的文件名通通列出来!
passwd: /usr/bin/passwd /etc/passwd /usr/share/man/man1/passwd.1.gz /usr/share/man/man5/passwd.5.gz
[root@study ~]# whereis -m passwd  # 只有在 man 里面的文件名才抓出来!
passwd: /usr/share/man/man1/passwd.1.gz /usr/share/man/man5/passwd.5.gz
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
[root@study ~]# locate [-ir] keyword
选项与参数:
-i  :忽略大小写的差异;
-c  :不输出文件名,仅计算找到的文件数量
-l  :仅输出几行的意思,例如输出五行则是 -l 5
-S  :输出 locate 所使用的数据库文件的相关信息,包括该数据库纪录的文件/目录数量等
-r  :后面可接正则表达式的显示方式

范例一:找出系统中所有与 passwd 相关的文件名,且只列出 5 个
[root@study ~]# locate -l 5 passwd
/etc/passwd
/etc/passwd-
/etc/pam.d/passwd
/etc/security/opasswd
/usr/bin/gpasswd

范例二:列出 locate 查询所使用的数据库文件之文件名与各数据数量
[root@study ~]# locate -S
Database /var/lib/mlocate/mlocate.db:
        8,086 directories     # 总纪录目录数
        109,605 files         # 总纪录文件数
        5,190,295 Bytes in file names
        2,349,150 Bytes used to store database
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
[root@study ~]# find [PATH] [option] [action]
选项与参数:
1. 与时间有关的选项:共有 -atime, -ctime 与 -mtime ,以 -mtime 说明
   -mtime  n :n 为数字,意义为在 n 天之前的“一天之内”被更动过内容的文件;
   -mtime +n :列出在 n 天之前(不含 n 天本身)被更动过内容的文件文件名;
   -mtime -n :列出在 n 天之内(含 n 天本身)被更动过内容的文件文件名。
   -newer file :file 为一个存在的文件,列出比 file 还要新的文件文件名

范例一:将过去系统上面 24 小时内有更动过内容 (mtime) 的文件列出
[root@study ~]# find / -mtime 0
# 那个 0 是重点!0 代表目前的时间,所以,从现在开始到 24 小时前,
# 有变动过内容的文件都会被列出来!那如果是三天前的 24 小时内?
# find / -mtime 3 有变动过的文件都被列出的意思!

范例二:寻找 /etc 下面的文件,如果文件日期比 /etc/passwd 新就列出
[root@study ~]# find /etc -newer /etc/passwd
# -newer 用在分辨两个文件之间的新旧关系是很有用的!
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
选项与参数:
2. 与使用者或群组名称有关的参数:
   -uid n :n 为数字,这个数字是使用者的帐号 ID,亦即 UID ,这个 UID 是记录在
            /etc/passwd 里面与帐号名称对应的数字。这方面我们会在第四篇介绍。
   -gid n :n 为数字,这个数字是群组名称的 ID,亦即 GID,这个 GID 记录在
            /etc/group,相关的介绍我们会第四篇说明~
   -user name :name 为使用者帐号名称喔!例如 dmtsai
   -group name:name 为群组名称喔,例如 users ;
   -nouser    :寻找文件的拥有者不存在 /etc/passwd 的人!
   -nogroup   :寻找文件的拥有群组不存在于 /etc/group 的文件!
                当你自行安装软件时,很可能该软件的属性当中并没有文件拥有者,
                这是可能的!在这个时候,就可以使用 -nouser 与 -nogroup 搜寻。

范例三:搜寻 /home 下面属于 dmtsai 的文件
[root@study ~]# find /home -user dmtsai
# 这个东西也很有用的~当我们要找出任何一个使用者在系统当中的所有文件时,
# 就可以利用这个指令将属于某个使用者的所有文件都找出来喔!

范例四:搜寻系统中不属于任何人的文件
[root@study ~]# find / -nouser
# 通过这个指令,可以轻易的就找出那些不太正常的文件。如果有找到不属于系统任何人的文件时,
# 不要太紧张,那有时候是正常的~尤其是你曾经以源代码自行编译软件时。
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
选项与参数:
3. 与文件权限及名称有关的参数:
   -name filename:搜寻文件名称为 filename 的文件;
   -size [+-]SIZE:搜寻比 SIZE 还要大(+)或小(-)的文件。这个 SIZE 的规格有:
                   c: 代表 Byte, k: 代表 1024Bytes。所以,要找比 50KB
                   还要大的文件,就是“ -size +50k ”
   -type TYPE    :搜寻文件的类型为 TYPE 的,类型主要有:一般正规文件 (f), 设备文件 (b, c),
                   目录 (d), 链接文件 (l), socket (s), 及 FIFO (p) 等属性。
   -perm mode  :搜寻文件权限“刚好等于” mode 的文件,这个 mode 为类似 chmod
                 的属性值,举例来说, -rwsr-xr-x 的属性为 4755 !
   -perm -mode :搜寻文件权限“必须要全部囊括 mode 的权限”的文件,举例来说,
                 我们要搜寻 -rwxr--r-- ,亦即 0744 的文件,使用 -perm -0744,
                 当一个文件的权限为 -rwsr-xr-x ,亦即 4755 时,也会被列出来,
                 因为 -rwsr-xr-x 的属性已经囊括了 -rwxr--r-- 的属性了。
   -perm /mode :搜寻文件权限“包含任一 mode 的权限”的文件,举例来说,我们搜寻
                 -rwxr-xr-x ,亦即 -perm /755 时,但一个文件属性为 -rw-------
                 也会被列出来,因为他有 -rw.... 的属性存在!

范例五:找出文件名为 passwd 这个文件
[root@study ~]# find / -name passwd

范例五-1:找出文件名包含了 passwd 这个关键字的文件
[root@study ~]# find / -name "*passwd*"
# 利用这个 -name 可以搜寻文件名啊!默认是完整文件名,如果想要找关键字,
# 可以使用类似 * 的任意字符来处理

范例六:找出 /run 目录下,文件类型为 Socket 的文件名有哪些?
[root@study ~]# find /run -type s
# 这个 -type 的属性也很有帮助喔!尤其是要找出那些怪异的文件,
# 例如 socket 与 FIFO 文件,可以用 find /run -type p 或 -type s 来找!

范例七:搜寻文件当中含有 SGID 或 SUID 或 SBIT 的属性
[root@study ~]# find / -perm /7000
# 所谓的 7000 就是 ---s--s--t ,那么只要含有 s 或 t 的就列出,所以当然要使用 /7000,
# 使用 -7000 表示要同时含有 ---s--s--t 的所有三个权限。而只需要任意一个,就是 /7000 ~瞭乎?
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
选项与参数:
4. 额外可进行的动作:
   -exec command :command 为其他指令,-exec 后面可再接额外的指令来处理搜寻到的结果。
   -print        :将结果打印到屏幕上,这个动作是默认动作!

范例八:将上个范例找到的文件使用 ls -l 列出来~
[root@study ~]# find /usr/bin /usr/sbin -perm /7000 -exec ls -l {} \;
# 注意到,那个 -exec 后面的 ls -l 就是额外的指令,指令不支持命令别名,
# 所以仅能使用 ls -l 不可以使用 ll 喔!注意注意!

范例九:找出系统中,大于 1MB 的文件
[root@study ~]# find / -size +1M
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
[root@study ~]# dumpe2fs [-bh] 设备文件名
选项与参数:
-b :列出保留为坏轨的部分(一般用不到吧!?)
-h :仅列出 superblock 的数据,不会列出其他的区段内容!

范例:鸟哥的一块 1GB ext4 文件系统内容
[root@study ~]# blkid   <==这个指令可以叫出目前系统有被格式化的设备
/dev/vda1: LABEL="myboot" UUID="ce4dbf1b-2b3d-4973-8234-73768e8fd659" TYPE="xfs"
/dev/vda2: LABEL="myroot" UUID="21ad8b9a-aaad-443c-b732-4e2522e95e23" TYPE="xfs"
/dev/vda3: UUID="12y99K-bv2A-y7RY-jhEW-rIWf-PcH5-SaiApN" TYPE="LVM2_member"
/dev/vda5: UUID="e20d65d9-20d4-472f-9f91-cdcfb30219d6" TYPE="ext4"  <==看到 ext4 了!

[root@study ~]# dumpe2fs /dev/vda5
dumpe2fs 1.42.9 (28-Dec-2013)
Filesystem volume name:   <none>           # 文件系统的名称(不一定会有)
Last mounted on:          <not available>  # 上一次挂载的目录位置
Filesystem UUID:          e20d65d9-20d4-472f-9f91-cdcfb30219d6
Filesystem magic number:  0xEF53           # 上方的 UUID 为 Linux 对设备的定义码
Filesystem revision #:    1 (dynamic)      # 下方的 features 为文件系统的特征数据
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent 64bit
 flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
Filesystem flags:         signed_directory_hash
Default mount options:    user_xattr acl   # 默认在挂载时会主动加上的挂载参数
Filesystem state:         clean            # 这块文件系统的状态为何,clean 是没问题
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              65536            # inode 的总数
Block count:              262144           # block 的总数
Reserved block count:     13107            # 保留的 block 总数
Free blocks:              249189           # 还有多少的 block 可用数量
Free inodes:              65525            # 还有多少的 inode 可用数量
First block:              0
Block size:               4096             # 单个 block 的容量大小
Fragment size:            4096
Group descriptor size:    64
....(中间省略)....
Inode size:               256              # inode 的容量大小!已经是 256 了喔!
....(中间省略)....
Journal inode:            8
Default directory hash:   half_md4
Directory Hash Seed:      3c2568b4-1a7e-44cf-95a2-c8867fb19fbc
Journal backup:           inode blocks
Journal features:         (none)
Journal size:             32M              # Journal 日志式数据的可供纪录总容量
Journal length:           8192
Journal sequence:         0x00000001
Journal start:            0

Group 0: (Blocks 0-32767)                  # 第一块 block group 位置
  Checksum 0x13be, unused inodes 8181
  Primary superblock at 0, Group descriptors at 1-1   # 主要 superblock 的所在喔!
  Reserved GDT blocks at 2-128
  Block bitmap at 129 (+129), Inode bitmap at 145 (+145)
  Inode table at 161-672 (+161)                       # inode table 的所在喔!
  28521 free blocks, 8181 free inodes, 2 directories, 8181 unused inodes
  Free blocks: 142-144, 153-160, 4258-32767           # 下面两行说明剩余的容量有多少
  Free inodes: 12-8192
Group 1: (Blocks 32768-65535) [INODE_UNINIT]          # 后续为更多其他的 block group 喔!
....(下面省略)....
# 由于数据量非常的庞大,因此鸟哥将一些信息省略输出了!上表与你的屏幕会有点差异。
# 前半部在秀出 supberblock 的内容,包括标头名称(Label)以及inode/block的相关信息
# 后面则是每个 block group 的个别信息了!您可以看到各区段数据所在的号码!
# 也就是说,基本上所有的数据还是与 block 的号码有关就是了!很重要!
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
[root@study ~]# xfs_info 挂载点|设备文件名

范例一:找出系统 /boot 这个挂载点下面的文件系统的 superblock 纪录
[root@study ~]# df -T /boot
Filesystem     Type 1K-blocks   Used Available Use% Mounted on
/dev/vda2      xfs    1038336 133704    904632  13% /boot
# 没错!可以看得出来是 xfs 文件系统的!来观察一下内容吧!

[root@study ~]# xfs_info /dev/vda2
1  meta-data=/dev/vda2         isize=256    agcount=4, agsize=65536 blks
2           =                  sectsz=512   attr=2, projid32bit=1
3           =                  crc=0        finobt=0
4  data     =                  bsize=4096   blocks=262144, imaxpct=25
5           =                  sunit=0      swidth=0 blks
6  naming   =version 2         bsize=4096   ascii-ci=0 ftype=0
7  log      =internal          bsize=4096   blocks=2560, version=2
8           =                  sectsz=512   sunit=0 blks, lazy-count=1
9  realtime =none              extsz=4096   blocks=0, rtextents=0
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
[root@study ~]# df [-ahikHTm] [目录或文件名]
选项与参数:
-a  :列出所有的文件系统,包括系统特有的 /proc 等文件系统;
-k  :以 KBytes 的容量显示各文件系统;
-m  :以 MBytes 的容量显示各文件系统;
-h  :以人们较易阅读的 GBytes, MBytes, KBytes 等格式自行显示;
-H  :以 M=1000K 取代 M=1024K 的进位方式;
-T  :连同该 partition 的 filesystem 名称 (例如 xfs) 也列出;
-i  :不用磁盘容量,而以 inode 的数量来显示

范例一:将系统内所有的 filesystem 列出来!
[root@study ~]# df
Filesystem              1K-blocks    Used Available Use% Mounted on
/dev/mapper/centos-root  10475520 3409408   7066112  33% /
devtmpfs                   627700       0    627700   0% /dev
tmpfs                      637568      80    637488   1% /dev/shm
tmpfs                      637568   24684    612884   4% /run
tmpfs                      637568       0    637568   0% /sys/fs/cgroup
/dev/mapper/centos-home   5232640   67720   5164920   2% /home
/dev/vda2                 1038336  133704    904632  13% /boot
# 在 Linux 下面如果 df 没有加任何选项,那么默认会将系统内所有的
# (不含特殊内存内的文件系统与 swap) 都以 1 KBytes 的容量来列出来!
# 至于那个 /dev/shm 是与内存有关的挂载,先不要理他!
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
范例二:将容量结果以易读的容量格式显示出来
[root@study ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   10G  3.3G  6.8G  33% /
devtmpfs                 613M     0  613M   0% /dev
tmpfs                    623M   80K  623M   1% /dev/shm
tmpfs                    623M   25M  599M   4% /run
tmpfs                    623M     0  623M   0% /sys/fs/cgroup
/dev/mapper/centos-home  5.0G   67M  5.0G   2% /home
/dev/vda2               1014M  131M  884M  13% /boot
# 不同于范例一,这里会以 G/M 等容量格式显示出来,比较容易看啦!

范例三:将系统内的所有特殊文件格式及名称都列出来
[root@study ~]# df -aT
Filesystem              Type        1K-blocks    Used Available Use% Mounted on
rootfs                  rootfs       10475520 3409368   7066152  33% /
proc                    proc                0       0         0    - /proc
sysfs                   sysfs               0       0         0    - /sys
devtmpfs                devtmpfs       627700       0    627700   0% /dev
securityfs              securityfs          0       0         0    - /sys/kernel/security
tmpfs                   tmpfs          637568      80    637488   1% /dev/shm
devpts                  devpts              0       0         0    - /dev/pts
tmpfs                   tmpfs          637568   24684    612884   4% /run
tmpfs                   tmpfs          637568       0    637568   0% /sys/fs/cgroup
.....(中间省略).....
/dev/mapper/centos-root xfs          10475520 3409368   7066152  33% /
selinuxfs               selinuxfs           0       0         0    - /sys/fs/selinux
.....(中间省略).....
/dev/mapper/centos-home xfs           5232640   67720   5164920   2% /home
/dev/vda2               xfs           1038336  133704    904632  13% /boot
binfmt_misc             binfmt_misc         0       0         0    - /proc/sys/fs/binfmt_misc
# 系统里面其实还有很多特殊的文件系统存在的。那些比较特殊的文件系统几乎
# 都是在内存当中,例如 /proc 这个挂载点。因此,这些特殊的文件系统
# 都不会占据磁盘空间喔! ^_^

范例四:将 /etc 下面的可用的磁盘容量以易读的容量格式显示
[root@study ~]# df -h /etc
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   10G  3.3G  6.8G  33% /
# 这个范例比较有趣一点啦,在 df 后面加上目录或者是文件时, df
# 会自动的分析该目录或文件所在的 partition ,并将该 partition 的容量显示出来,
# 所以,您就可以知道某个目录下面还有多少容量可以使用了! ^_^

范例五:将目前各个 partition 当中可用的 inode 数量列出
[root@study ~]# df -ih
Filesystem              Inodes IUsed IFree IUse% Mounted on
/dev/mapper/centos-root    10M  108K  9.9M    2% /
devtmpfs                  154K   397  153K    1% /dev
tmpfs                     156K     5  156K    1% /dev/shm
tmpfs                     156K   497  156K    1% /run
tmpfs  &

相关文章
最新文章
热门推荐
网友评论