文件系统常用工具实战篇

本文涉及的产品
云数据库 Tair(兼容Redis),内存型 2GB
Redis 开源版,标准版 2GB
推荐场景:
搭建游戏排行榜
简介: 文章详细介绍了Linux系统中用于查看和分析文件系统空间使用情况的命令工具df和du,以及用于转换和复制文件的dd命令的使用案例。

作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。

  本篇博客主要介绍df,du,dd三个命令的使用案例。

一.已挂载文件系统空间占用等信息的查看工具-df

1>.查看df命令的帮助信息

[root@yinzhengjie.com ~]# df --help
Usage: df [OPTION]... [FILE]...
Show information about the file system on which each FILE resides,
or all file systems by default.

Mandatory arguments to long options are mandatory for short options too.
  -a, --all             include pseudo, duplicate, inaccessible file systems
  -B, --block-size=SIZE  scale sizes by SIZE before printing them; e.g.,
                           '-BM' prints sizes in units of 1,048,576 bytes;
                           see SIZE format below
      --direct          show statistics for a file instead of mount point
      --total           produce a grand total
  -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
  -k                    like --block-size=1K
  -l, --local           limit listing to local file systems
      --no-sync         do not invoke sync before getting usage info (default)
      --output[=FIELD_LIST]  use the output format defined by FIELD_LIST,
                               or print all fields if FIELD_LIST is omitted.
  -P, --portability     use the POSIX output format
      --sync            invoke sync before getting usage info
  -t, --type=TYPE       limit listing to file systems of type TYPE
  -T, --print-type      print file system type
  -x, --exclude-type=TYPE   limit listing to file systems not of type TYPE
  -v                    (ignored)
      --help     display this help and exit
      --version  output version information and exit

Display values are in units of the first available SIZE from --block-size,
and the DF_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environment variables.
Otherwise, units default to 1024 bytes (or 512 if POSIXLY_CORRECT is set).

SIZE is an integer and optional unit (example: 10M is 10*1024*1024).  Units
are K, M, G, T, P, E, Z, Y (powers of 1024) or KB, MB, ... (powers of 1000).

FIELD_LIST is a comma-separated list of columns to be included.  Valid
field names are: 'source', 'fstype', 'itotal', 'iused', 'iavail', 'ipcent',
'size', 'used', 'avail', 'pcent', 'file' and 'target' (see info page).

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
For complete documentation, run: info coreutils 'df invocation'
[root@yinzhengjie.com ~]#

[root@yinzhengjie.com ~]# df --help

2>.df命令默认以字节形式显示

[root@yinzhengjie.com ~]# df
Filesystem                      1K-blocks    Used  Available Use% Mounted on
/dev/mapper/centos-root         524032000 3589332  520442668   1% /
devtmpfs                          2001028       0    2001028   0% /dev
tmpfs                             2013192       0    2013192   0% /dev/shm
tmpfs                             2013192   11936    2001256   1% /run
tmpfs                             2013192       0    2013192   0% /sys/fs/cgroup
/dev/sdb5                       103080888   61468   97760156   1% /mnt/sdb5
/dev/sdc2                       209612800   33008  209579792   1% /home
/dev/sda2                         1038336  135368     902968  14% /boot
/dev/mapper/centos-yinzhengjie 1621224000  458632 1620765368   1% /yinzhengjie
/dev/loop0                         999320    2572     927936   1% /mnt/ext4
tmpfs                              402640       0     402640   0% /run/user/0
[root@yinzhengjie.com ~]#

[root@yinzhengjie.com ~]# df

3>.以1000为单位显示磁盘使用空间

[root@yinzhengjie.com ~]# df -H
Filesystem                      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root         537G  3.7G  533G   1% /
devtmpfs                        2.1G     0  2.1G   0% /dev
tmpfs                           2.1G     0  2.1G   0% /dev/shm
tmpfs                           2.1G   13M  2.1G   1% /run
tmpfs                           2.1G     0  2.1G   0% /sys/fs/cgroup
/dev/sdb5                       106G   63M  101G   1% /mnt/sdb5
/dev/sdc2                       215G   34M  215G   1% /home
/dev/sda2                       1.1G  139M  925M  14% /boot
/dev/mapper/centos-yinzhengjie  1.7T  470M  1.7T   1% /yinzhengjie
/dev/loop0                      1.1G  2.7M  951M   1% /mnt/ext4
tmpfs                           413M     0  413M   0% /run/user/0
[root@yinzhengjie.com ~]#

[root@yinzhengjie.com ~]# df -H

4>.人性化可读方式显示(以1024为单位显示)

[root@yinzhengjie.com ~]# df -h
Filesystem                      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root         500G  3.5G  497G   1% /
devtmpfs                        2.0G     0  2.0G   0% /dev
tmpfs                           2.0G     0  2.0G   0% /dev/shm
tmpfs                           2.0G   12M  2.0G   1% /run
tmpfs                           2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/sdb5                        99G   61M   94G   1% /mnt/sdb5
/dev/sdc2                       200G   33M  200G   1% /home
/dev/sda2                      1014M  133M  882M  14% /boot
/dev/mapper/centos-yinzhengjie  1.6T  448M  1.6T   1% /yinzhengjie
/dev/loop0                      976M  2.6M  907M   1% /mnt/ext4
tmpfs                           394M     0  394M   0% /run/user/0
[root@yinzhengjie.com ~]#

[root@yinzhengjie.com ~]# df -h

5>.显示文件系统类型

[root@yinzhengjie.com ~]# df -T
Filesystem                     Type      1K-blocks    Used  Available Use% Mounted on
/dev/mapper/centos-root        xfs       524032000 3589100  520442900   1% /
devtmpfs                       devtmpfs    2001028       0    2001028   0% /dev
tmpfs                          tmpfs       2013192       0    2013192   0% /dev/shm
tmpfs                          tmpfs       2013192   11936    2001256   1% /run
tmpfs                          tmpfs       2013192       0    2013192   0% /sys/fs/cgroup
/dev/sdb5                      ext4      103080888   61468   97760156   1% /mnt/sdb5
/dev/sdc2                      xfs       209612800   33008  209579792   1% /home
/dev/sda2                      xfs         1038336  135368     902968  14% /boot
/dev/mapper/centos-yinzhengjie xfs      1621224000  458632 1620765368   1% /yinzhengjie
/dev/loop0                     ext4         999320    2572     927936   1% /mnt/ext4
tmpfs                          tmpfs        402640       0     402640   0% /run/user/0
[root@yinzhengjie.com ~]#

[root@yinzhengjie.com ~]# df -T

6>.显示inode信息

[root@yinzhengjie.com ~]# df -i
Filesystem                        Inodes  IUsed     IFree IUse% Mounted on
/dev/mapper/centos-root        262144000 114414 262029586    1% /
devtmpfs                          500257    466    499791    1% /dev
tmpfs                             503298      1    503297    1% /dev/shm
tmpfs                             503298   1379    501919    1% /run
tmpfs                             503298     16    503282    1% /sys/fs/cgroup
/dev/sdb5                        6553600     12   6553588    1% /mnt/sdb5
/dev/sdc2                      104857600      8 104857592    1% /home
/dev/sda2                         524288    326    523962    1% /boot
/dev/mapper/centos-yinzhengjie 162201600   1800 162199800    1% /yinzhengjie
/dev/loop0                         65536     13     65523    1% /mnt/ext4
tmpfs                             503298      1    503297    1% /run/user/0
[root@yinzhengjie.com ~]#

[root@yinzhengjie.com ~]# df -i

7>.以Posix兼容的格式输出

[root@yinzhengjie.com ~]# df -P            #在CentOS 6.x及之前的版本该命令需要使用"-P"参数,以防止第一列名称过长而导致一行内容分两行的形式显示,CentOS 7.x的df命令貌似默认就有"-P"功能。
Filesystem                     1024-blocks    Used  Available Capacity Mounted on
/dev/mapper/centos-root          524032000 3589132  520442868       1% /
devtmpfs                           2001028       0    2001028       0% /dev
tmpfs                              2013192       0    2013192       0% /dev/shm
tmpfs                              2013192   12008    2001184       1% /run
tmpfs                              2013192       0    2013192       0% /sys/fs/cgroup
/dev/sdb5                        103080888   61468   97760156       1% /mnt/sdb5
/dev/sdc2                        209612800   33008  209579792       1% /home
/dev/sda2                          1038336  135368     902968      14% /boot
/dev/mapper/centos-yinzhengjie  1621224000 1398664 1619825336       1% /yinzhengjie
/dev/loop0                          999320    2572     927936       1% /mnt/ext4
tmpfs                               402640       0     402640       0% /run/user/0
/dev/loop1                          939512  939512          0     100% /mnt/cdrom
/dev/loop2                          939512  939512          0     100% /mnt/centos
[root@yinzhengjie.com ~]#

[root@yinzhengjie.com ~]# df -P            #在CentOS 6.x及之前的版本该命令需要使用"-P"参数,以防止第一列名称过长而导致一行内容分两行的形式显示,CentOS 7.x的df命令貌似默认就有"-P"功能。

二.查看某目录总体空间占用状态工具-du

1>.查看du命令的帮助信息

[root@yinzhengjie.com ~]# du --help
Usage: du [OPTION]... [FILE]...
  or:  du [OPTION]... --files0-from=F
Summarize disk usage of each FILE, recursively for directories.

Mandatory arguments to long options are mandatory for short options too.
  -0, --null            end each output line with 0 byte rather than newline
  -a, --all             write counts for all files, not just directories
      --apparent-size   print apparent sizes, rather than disk usage; although
                          the apparent size is usually smaller, it may be
                          larger due to holes in ('sparse') files, internal
                          fragmentation, indirect blocks, and the like
  -B, --block-size=SIZE  scale sizes by SIZE before printing them; e.g.,
                           '-BM' prints sizes in units of 1,048,576 bytes;
                           see SIZE format below
  -b, --bytes           equivalent to '--apparent-size --block-size=1'
  -c, --total           produce a grand total
  -D, --dereference-args  dereference only symlinks that are listed on the
                          command line
  -d, --max-depth=N     print the total for a directory (or file, with --all)
                          only if it is N or fewer levels below the command
                          line argument;  --max-depth=0 is the same as
                          --summarize
      --files0-from=F   summarize disk usage of the
                          NUL-terminated file names specified in file F;
                          if F is -, then read names from standard input
  -H                    equivalent to --dereference-args (-D)
  -h, --human-readable  print sizes in human readable format (e.g., 1K 234M 2G)
      --inodes          list inode usage information instead of block usage
  -k                    like --block-size=1K
  -L, --dereference     dereference all symbolic links
  -l, --count-links     count sizes many times if hard linked
  -m                    like --block-size=1M
  -P, --no-dereference  don't follow any symbolic links (this is the default)
  -S, --separate-dirs   for directories do not include size of subdirectories
      --si              like -h, but use powers of 1000 not 1024
  -s, --summarize       display only a total for each argument
  -t, --threshold=SIZE  exclude entries smaller than SIZE if positive,
                          or entries greater than SIZE if negative
      --time            show time of the last modification of any file in the
                          directory, or any of its subdirectories
      --time=WORD       show time as WORD instead of modification time:
                          atime, access, use, ctime or status
      --time-style=STYLE  show times using STYLE, which can be:
                            full-iso, long-iso, iso, or +FORMAT;
                            FORMAT is interpreted like in 'date'
  -X, --exclude-from=FILE  exclude files that match any pattern in FILE
      --exclude=PATTERN    exclude files that match PATTERN
  -x, --one-file-system    skip directories on different file systems
      --help     display this help and exit
      --version  output version information and exit

Display values are in units of the first available SIZE from --block-size,
and the DU_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environment variables.
Otherwise, units default to 1024 bytes (or 512 if POSIXLY_CORRECT is set).

SIZE is an integer and optional unit (example: 10M is 10*1024*1024).  Units
are K, M, G, T, P, E, Z, Y (powers of 1024) or KB, MB, ... (powers of 1000).

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
For complete documentation, run: info coreutils 'du invocation'
[root@yinzhengjie.com ~]#

[root@yinzhengjie.com ~]# du --help

2>.默认查看当前目录下的所有目录(包括隐藏目录)总体空间占用状态

[root@yinzhengjie.com ~]# ll -aR
.:
total 52
dr-xr-x---.  4 root root   199 May 28 18:53 .
dr-xr-xr-x. 18 root root   243 Jan 20 04:20 ..
-rw-------.  1 root root 11187 May 28 18:06 .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-r--r--.  1 root root   271 May 16 14:19 .bashrc
-rw-r--r--.  1 root root   100 Dec 29  2013 .cshrc
-rw-------   1 root root  1499 May 18 11:25 .mysql_history
drwxr-----   3 root root    19 May 15 20:09 .pki
-rw-------   1 root root    87 May 15 23:56 .rediscli_history
-rw-r--r--.  1 root root   129 Dec 29  2013 .tcshrc
drwxr-xr-x   2 root root    45 May 28 18:53 test
-rw-------   1 root root  9491 May 28 17:46 .viminfo

./.pki:
total 0
drwxr-----  3 root root  19 May 15 20:09 .
dr-xr-x---. 4 root root 199 May 28 18:53 ..
drwxr-----  2 root root   6 May 15 20:09 nssdb

./.pki/nssdb:
total 0
drwxr----- 2 root root  6 May 15 20:09 .
drwxr----- 3 root root 19 May 15 20:09 ..

./test:
total 8
drwxr-xr-x  2 root root  45 May 28 18:53 .
dr-xr-x---. 4 root root 199 May 28 18:53 ..
-rw-r--r--  1 root root  64 May  7 03:10 dpt
-rw-r--r--  1 root root 408 May 16 14:19 random_encryption.sh
[root@yinzhengjie.com ~]#

[root@yinzhengjie.com ~]# ll -aR

[root@yinzhengjie.com ~]# du
8    ./test
0    ./.pki/nssdb
0    ./.pki
60    .
[root@yinzhengjie.com ~]#

[root@yinzhengjie.com ~]# du

3>.指定查看路径下所有目录总体空间占用状态

[root@yinzhengjie.com ~]# du /etc/  
72    /etc/grub.d
0    /etc/terminfo
12    /etc/skel
0    /etc/alternatives
0    /etc/chkconfig.d
8    /etc/libnl
40    /etc/rc.d/init.d
0    /etc/rc.d/rc0.d
0    /etc/rc.d/rc1.d
0    /etc/rc.d/rc2.d
0    /etc/rc.d/rc3.d
0    /etc/rc.d/rc4.d
0    /etc/rc.d/rc5.d
0    /etc/rc.d/rc6.d
44    /etc/rc.d
100    /etc/pam.d
4    /etc/depmod.d
0    /etc/dracut.conf.d
12    /etc/default
12    /etc/prelink.conf.d
12    /etc/modprobe.d
4    /etc/rsyslog.d
0    /etc/binfmt.d
0    /etc/modules-load.d
4    /etc/systemd/system/multi-user.target.wants
0    /etc/systemd/system/getty.target.wants
0    /etc/systemd/system/default.target.wants
0    /etc/systemd/system/system-update.target.wants
0    /etc/systemd/system/sysinit.target.wants
0    /etc/systemd/system/basic.target.wants
0    /etc/systemd/system/local-fs.target.wants
0    /etc/systemd/system/sockets.target.wants
4    /etc/systemd/system/redis-sentinel.service.d
4    /etc/systemd/system/redis.service.d
16    /etc/systemd/system
0    /etc/systemd/user
40    /etc/systemd
92    /etc/dbus-1/system.d
0    /etc/dbus-1/session.d
100    /etc/dbus-1
0    /etc/sysctl.d
0    /etc/tmpfiles.d
0    /etc/udev/rules.d
7764    /etc/udev
4    /etc/lvm/archive
4    /etc/lvm/backup
0    /etc/lvm/cache
28    /etc/lvm/profile
136    /etc/lvm
0    /etc/NetworkManager/dispatcher.d/no-wait.d
0    /etc/NetworkManager/dispatcher.d/pre-down.d
0    /etc/NetworkManager/dispatcher.d/pre-up.d
8    /etc/NetworkManager/dispatcher.d
0    /etc/NetworkManager/conf.d
0    /etc/NetworkManager/dnsmasq-shared.d
0    /etc/NetworkManager/dnsmasq.d
0    /etc/NetworkManager/system-connections
12    /etc/NetworkManager
72    /etc/profile.d
8    /etc/polkit-1/rules.d
0    /etc/polkit-1/localauthority/10-vendor.d
0    /etc/polkit-1/localauthority/20-org.d
0    /etc/polkit-1/localauthority/30-site.d
0    /etc/polkit-1/localauthority/50-local.d
0    /etc/polkit-1/localauthority/90-mandatory.d
0    /etc/polkit-1/localauthority
0    /etc/polkit-1/localauthority.conf.d
8    /etc/polkit-1
0    /etc/ppp/peers
28    /etc/ppp
8    /etc/ntp
0    /etc/X11/applnk
0    /etc/X11/fontpath.d
4    /etc/X11/xorg.conf.d
4    /etc/X11
20    /etc/bash_completion.d
0    /etc/opt
156    /etc/pki/ca-trust/extracted/java
256    /etc/pki/ca-trust/extracted/openssl
388    /etc/pki/ca-trust/extracted/pem
804    /etc/pki/ca-trust/extracted
0    /etc/pki/ca-trust/source/anchors
0    /etc/pki/ca-trust/source/blacklist
4    /etc/pki/ca-trust/source
816    /etc/pki/ca-trust
0    /etc/pki/java
12    /etc/pki/tls/certs
24    /etc/pki/tls/misc
0    /etc/pki/tls/private
48    /etc/pki/tls
16    /etc/pki/rpm-gpg
4    /etc/pki/nss-legacy
124    /etc/pki/nssdb
0    /etc/pki/CA/certs
0    /etc/pki/CA/crl
0    /etc/pki/CA/newcerts
0    /etc/pki/CA/private
0    /etc/pki/CA
0    /etc/pki/rsyslog
1008    /etc/pki
0    /etc/pm/config.d
0    /etc/pm/power.d
0    /etc/pm/sleep.d
0    /etc/pm
8    /etc/sysconfig/cbq
0    /etc/sysconfig/console
0    /etc/sysconfig/modules
256    /etc/sysconfig/network-scripts
352    /etc/sysconfig
0    /etc/xdg/autostart
0    /etc/xdg/systemd
0    /etc/xdg
0    /etc/xinetd.d
8    /etc/ld.so.conf.d
4    /etc/dhcp/dhclient-exit-hooks.d
0    /etc/dhcp/dhclient.d
4    /etc/dhcp
0    /etc/popt.d
0    /etc/statetab.d
0    /etc/pkcs11/modules
0    /etc/pkcs11
0    /etc/ssl
12    /etc/rpm
44    /etc/yum.repos.d
8    /etc/yum/vars
4    /etc/yum/protected.d
8    /etc/yum/pluginconf.d
0    /etc/yum/fssnap.d
24    /etc/yum
4    /etc/wpa_supplicant
4    /etc/cron.hourly
0    /etc/krb5.conf.d
0    /etc/gcrypt
0    /etc/cron.weekly
0    /etc/gss/mech.d
0    /etc/gss
0    /etc/security/console.apps
0    /etc/security/console.perms.d
8    /etc/security/limits.d
0    /etc/security/namespace.d
68    /etc/security
4    /etc/sasl2
0    /etc/groff/site-font
8    /etc/groff/site-tmac
8    /etc/groff
4    /etc/python
36    /etc/iproute2
12    /etc/my.cnf.d
64    /etc/openldap/certs
68    /etc/openldap
8    /etc/cron.daily
4    /etc/rwtab.d
24    /etc/logrotate.d
4    /etc/cron.d
0    /etc/cron.monthly
604    /etc/ssh
0    /etc/selinux/tmp
0    /etc/selinux/targeted/modules/active/modules
4    /etc/selinux/targeted/modules/active
4    /etc/selinux/targeted/modules
1848    /etc/selinux/targeted/contexts/files
28    /etc/selinux/targeted/contexts/users
1944    /etc/selinux/targeted/contexts
0    /etc/selinux/targeted/logins
3844    /etc/selinux/targeted/policy
32    /etc/selinux/targeted/active/modules/100/abrt
20    /etc/selinux/targeted/active/modules/100/accountsd
20    /etc/selinux/targeted/active/modules/100/acct
20    /etc/selinux/targeted/active/modules/100/afs
20    /etc/selinux/targeted/active/modules/100/aiccu
20    /etc/selinux/targeted/active/modules/100/aide
20    /etc/selinux/targeted/active/modules/100/ajaxterm
20    /etc/selinux/targeted/active/modules/100/alsa
20    /etc/selinux/targeted/active/modules/100/amanda
20    /etc/selinux/targeted/active/modules/100/amtu
28    /etc/selinux/targeted/active/modules/100/anaconda
24    /etc/selinux/targeted/active/modules/100/antivirus
48    /etc/selinux/targeted/active/modules/100/apache
20    /etc/selinux/targeted/active/modules/100/apcupsd
28    /etc/selinux/targeted/active/modules/100/apm
20    /etc/selinux/targeted/active/modules/100/application
20    /etc/selinux/targeted/active/modules/100/arpwatch
20    /etc/selinux/targeted/active/modules/100/asterisk
28    /etc/selinux/targeted/active/modules/100/auditadm
20    /etc/selinux/targeted/active/modules/100/authconfig
32    /etc/selinux/targeted/active/modules/100/authlogin
20    /etc/selinux/targeted/active/modules/100/automount
20    /etc/selinux/targeted/active/modules/100/avahi
20    /etc/selinux/targeted/active/modules/100/awstats
28    /etc/selinux/targeted/active/modules/100/bacula
120    /etc/selinux/targeted/active/modules/100/base
20    /etc/selinux/targeted/active/modules/100/bcfg2
28    /etc/selinux/targeted/active/modules/100/bind
20    /etc/selinux/targeted/active/modules/100/bitlbee
20    /etc/selinux/targeted/active/modules/100/blkmapd
20    /etc/selinux/targeted/active/modules/100/blueman
28    /etc/selinux/targeted/active/modules/100/bluetooth
28    /etc/selinux/targeted/active/modules/100/boinc
28    /etc/selinux/targeted/active/modules/100/bootloader
20    /etc/selinux/targeted/active/modules/100/brctl
20    /etc/selinux/targeted/active/modules/100/brltty
20    /etc/selinux/targeted/active/modules/100/bugzilla
20    /etc/selinux/targeted/active/modules/100/bumblebee
20    /etc/selinux/targeted/active/modules/100/cachefilesd
20    /etc/selinux/targeted/active/modules/100/calamaris
20    /etc/selinux/targeted/active/modules/100/callweaver
20    /etc/selinux/targeted/active/modules/100/canna
20    /etc/selinux/targeted/active/modules/100/ccs
20    /etc/selinux/targeted/active/modules/100/cdrecord
20    /etc/selinux/targeted/active/modules/100/certmaster
28    /etc/selinux/targeted/active/modules/100/certmonger
20    /etc/selinux/targeted/active/modules/100/certwatch
20    /etc/selinux/targeted/active/modules/100/cfengine
20    /etc/selinux/targeted/active/modules/100/cgdcbxd
20    /etc/selinux/targeted/active/modules/100/cgroup
28    /etc/selinux/targeted/active/modules/100/chrome
20    /etc/selinux/targeted/active/modules/100/chronyd
28    /etc/selinux/targeted/active/modules/100/cinder
20    /etc/selinux/targeted/active/modules/100/cipe
20    /etc/selinux/targeted/active/modules/100/clock
20    /etc/selinux/targeted/active/modules/100/clogd
28    /etc/selinux/targeted/active/modules/100/cloudform
20    /etc/selinux/targeted/active/modules/100/cmirrord
20    /etc/selinux/targeted/active/modules/100/cobbler
20    /etc/selinux/targeted/active/modules/100/cockpit
20    /etc/selinux/targeted/active/modules/100/collectd
20    /etc/selinux/targeted/active/modules/100/colord
20    /etc/selinux/targeted/active/modules/100/comsat
28    /etc/selinux/targeted/active/modules/100/condor
20    /etc/selinux/targeted/active/modules/100/conman
28    /etc/selinux/targeted/active/modules/100/consolekit
28    /etc/selinux/targeted/active/modules/100/container
20    /etc/selinux/targeted/active/modules/100/couchdb
20    /etc/selinux/targeted/active/modules/100/courier
20    /etc/selinux/targeted/active/modules/100/cpucontrol
20    /etc/selinux/targeted/active/modules/100/cpufreqselector
20    /etc/selinux/targeted/active/modules/100/cpuplug
36    /etc/selinux/targeted/active/modules/100/cron
20    /etc/selinux/targeted/active/modules/100/ctdb
32    /etc/selinux/targeted/active/modules/100/cups
20    /etc/selinux/targeted/active/modules/100/cvs
20    /etc/selinux/targeted/active/modules/100/cyphesis
20    /etc/selinux/targeted/active/modules/100/cyrus
20    /etc/selinux/targeted/active/modules/100/daemontools
24    /etc/selinux/targeted/active/modules/100/dbadm
20    /etc/selinux/targeted/active/modules/100/dbskk
28    /etc/selinux/targeted/active/modules/100/dbus
20    /etc/selinux/targeted/active/modules/100/dcc
20    /etc/selinux/targeted/active/modules/100/ddclient
20    /etc/selinux/targeted/active/modules/100/denyhosts
32    /etc/selinux/targeted/active/modules/100/devicekit
20    /etc/selinux/targeted/active/modules/100/dhcp
20    /etc/selinux/targeted/active/modules/100/dictd
28    /etc/selinux/targeted/active/modules/100/dirsrv
28    /etc/selinux/targeted/active/modules/100/dirsrv-admin
20    /etc/selinux/targeted/active/modules/100/dmesg
20    /etc/selinux/targeted/active/modules/100/dmidecode
20    /etc/selinux/targeted/active/modules/100/dnsmasq
20    /etc/selinux/targeted/active/modules/100/dnssec
28    /etc/selinux/targeted/active/modules/100/dovecot
20    /etc/selinux/targeted/active/modules/100/drbd
20    /etc/selinux/targeted/active/modules/100/dspam
20    /etc/selinux/targeted/active/modules/100/entropyd
24    /etc/selinux/targeted/active/modules/100/exim
20    /etc/selinux/targeted/active/modules/100/fail2ban
20    /etc/selinux/targeted/active/modules/100/fcoe
20    /etc/selinux/targeted/active/modules/100/fetchmail
20    /etc/selinux/targeted/active/modules/100/finger
20    /etc/selinux/targeted/active/modules/100/firewalld
20    /etc/selinux/targeted/active/modules/100/firewallgui
20    /etc/selinux/targeted/active/modules/100/firstboot
20    /etc/selinux/targeted/active/modules/100/fprintd
20    /etc/selinux/targeted/active/modules/100/freeipmi
20    /etc/selinux/targeted/active/modules/100/freqset
28    /etc/selinux/targeted/active/modules/100/fstools
28    /etc/selinux/targeted/active/modules/100/ftp
28    /etc/selinux/targeted/active/modules/100/games
20    /etc/selinux/targeted/active/modules/100/gdomap
20    /etc/selinux/targeted/active/modules/100/geoclue
20    /etc/selinux/targeted/active/modules/100/getty
20    /etc/selinux/targeted/active/modules/100/git
20    /etc/selinux/targeted/active/modules/100/gitosis
20    /etc/selinux/targeted/active/modules/100/glance
28    /etc/selinux/targeted/active/modules/100/glusterd
20    /etc/selinux/targeted/active/modules/100/gnome
28    /etc/selinux/targeted/active/modules/100/gpg
20    /etc/selinux/targeted/active/modules/100/gpm
20    /etc/selinux/targeted/active/modules/100/gpsd
20    /etc/selinux/targeted/active/modules/100/gssproxy
28    /etc/selinux/targeted/active/modules/100/guest
20    /etc/selinux/targeted/active/modules/100/hddtemp
20    /etc/selinux/targeted/active/modules/100/hostname
20    /etc/selinux/targeted/active/modules/100/hsqldb
20    /etc/selinux/targeted/active/modules/100/hwloc
20    /etc/selinux/targeted/active/modules/100/hypervkvp
20    /etc/selinux/targeted/active/modules/100/icecast
28    /etc/selinux/targeted/active/modules/100/inetd
56    /etc/selinux/targeted/active/modules/100/init
20    /etc/selinux/targeted/active/modules/100/inn
20    /etc/selinux/targeted/active/modules/100/iodine
20    /etc/selinux/targeted/active/modules/100/iotop
20    /etc/selinux/targeted/active/modules/100/ipa
20    /etc/selinux/targeted/active/modules/100/ipmievd
28    /etc/selinux/targeted/active/modules/100/ipsec
24    /etc/selinux/targeted/active/modules/100/iptables
20    /etc/selinux/targeted/active/modules/100/irc
20    /etc/selinux/targeted/active/modules/100/irqbalance
20    /etc/selinux/targeted/active/modules/100/iscsi
20    /etc/selinux/targeted/active/modules/100/isns
20    /etc/selinux/targeted/active/modules/100/jabber
16    /etc/selinux/targeted/active/modules/100/jetty
20    /etc/selinux/targeted/active/modules/100/jockey
20    /etc/selinux/targeted/active/modules/100/journalctl
28    /etc/selinux/targeted/active/modules/100/kdump
20    /etc/selinux/targeted/active/modules/100/kdumpgui
20    /etc/selinux/targeted/active/modules/100/keepalived
28    /etc/selinux/targeted/active/modules/100/kerberos
16    /etc/selinux/targeted/active/modules/100/keyboardd
24    /etc/selinux/targeted/active/modules/100/keystone
20    /etc/selinux/targeted/active/modules/100/kismet
20    /etc/selinux/targeted/active/modules/100/kmscon
20    /etc/selinux/targeted/active/modules/100/ksmtuned
20    /etc/selinux/targeted/active/modules/100/ktalk
20    /etc/selinux/targeted/active/modules/100/l2tp
20    /etc/selinux/targeted/active/modules/100/ldap
28    /etc/selinux/targeted/active/modules/100/libraries
28    /etc/selinux/targeted/active/modules/100/likewise
20    /etc/selinux/targeted/active/modules/100/linuxptp
20    /etc/selinux/targeted/active/modules/100/lircd
20    /etc/selinux/targeted/active/modules/100/livecd
20    /etc/selinux/targeted/active/modules/100/lldpad
20    /etc/selinux/targeted/active/modules/100/loadkeys
28    /etc/selinux/targeted/active/modules/100/locallogin
20    /etc/selinux/targeted/active/modules/100/lockdev
20    /etc/selinux/targeted/active/modules/100/logadm
28    /etc/selinux/targeted/active/modules/100/logging
28    /etc/selinux/targeted/active/modules/100/logrotate
20    /etc/selinux/targeted/active/modules/100/logwatch
20    /etc/selinux/targeted/active/modules/100/lpd
20    /etc/selinux/targeted/active/modules/100/lsm
20    /etc/selinux/targeted/active/modules/100/lttng-tools
28    /etc/selinux/targeted/active/modules/100/lvm
20    /etc/selinux/targeted/active/modules/100/mailman
20    /etc/selinux/targeted/active/modules/100/mailscanner
20    /etc/selinux/targeted/active/modules/100/man2html
20    /etc/selinux/targeted/active/modules/100/mandb
20    /etc/selinux/targeted/active/modules/100/mcelog
20    /etc/selinux/targeted/active/modules/100/mediawiki
20    /etc/selinux/targeted/active/modules/100/memcached
20    /etc/selinux/targeted/active/modules/100/milter
20    /etc/selinux/targeted/active/modules/100/minidlna
20    /etc/selinux/targeted/active/modules/100/minissdpd
20    /etc/selinux/targeted/active/modules/100/mip6d
20    /etc/selinux/targeted/active/modules/100/mirrormanager
20    /etc/selinux/targeted/active/modules/100/miscfiles
20    /etc/selinux/targeted/active/modules/100/mock
20    /etc/selinux/targeted/active/modules/100/modemmanager
28    /etc/selinux/targeted/active/modules/100/modutils
20    /etc/selinux/targeted/active/modules/100/mojomojo
20    /etc/selinux/targeted/active/modules/100/mon_statd
20    /etc/selinux/targeted/active/modules/100/mongodb
20    /etc/selinux/targeted/active/modules/100/motion
28    /etc/selinux/targeted/active/modules/100/mount
36    /etc/selinux/targeted/active/modules/100/mozilla
20    /etc/selinux/targeted/active/modules/100/mpd
20    /etc/selinux/targeted/active/modules/100/mplayer
20    /etc/selinux/targeted/active/modules/100/mrtg
28    /etc/selinux/targeted/active/modules/100/mta
32    /etc/selinux/targeted/active/modules/100/munin
28    /etc/selinux/targeted/active/modules/100/mysql
20    /etc/selinux/targeted/active/modules/100/mythtv
36    /etc/selinux/targeted/active/modules/100/nagios
20    /etc/selinux/targeted/active/modules/100/namespace
20    /etc/selinux/targeted/active/modules/100/ncftool
20    /etc/selinux/targeted/active/modules/100/netlabel
20    /etc/selinux/targeted/active/modules/100/netutils
28    /etc/selinux/targeted/active/modules/100/networkmanager
20    /etc/selinux/targeted/active/modules/100/ninfod
20    /etc/selinux/targeted/active/modules/100/nis
20    /etc/selinux/targeted/active/modules/100/nova
20    /etc/selinux/targeted/active/modules/100/nscd
20    /etc/selinux/targeted/active/modules/100/nsd
20    /etc/selinux/targeted/active/modules/100/nslcd
20    /etc/selinux/targeted/active/modules/100/ntop
20    /etc/selinux/targeted/active/modules/100/ntp
20    /etc/selinux/targeted/active/modules/100/numad
20    /etc/selinux/targeted/active/modules/100/nut
20    /etc/selinux/targeted/active/modules/100/nx
20    /etc/selinux/targeted/active/modules/100/obex
20    /etc/selinux/targeted/active/modules/100/oddjob
20    /etc/selinux/targeted/active/modules/100/openct
20    /etc/selinux/targeted/active/modules/100/opendnssec
20    /etc/selinux/targeted/active/modules/100/openhpid
32    /etc/selinux/targeted/active/modules/100/openshift
16    /etc/selinux/targeted/active/modules/100/openshift-origin
20    /etc/selinux/targeted/active/modules/100/opensm
28    /etc/selinux/targeted/active/modules/100/openvpn
20    /etc/selinux/targeted/active/modules/100/openvswitch
20    /etc/selinux/targeted/active/modules/100/openwsman
20    /etc/selinux/targeted/active/modules/100/oracleasm
20    /etc/selinux/targeted/active/modules/100/osad
20    /etc/selinux/targeted/active/modules/100/pads
20    /etc/selinux/targeted/active/modules/100/passenger
20    /etc/selinux/targeted/active/modules/100/pcmcia
28    /etc/selinux/targeted/active/modules/100/pcp
20    /etc/selinux/targeted/active/modules/100/pcscd
36    /etc/selinux/targeted/active/modules/100/pegasus
8    /etc/selinux/targeted/active/modules/100/permissivedomains
20    /etc/selinux/targeted/active/modules/100/pesign
20    /etc/selinux/targeted/active/modules/100/pingd
28    /etc/selinux/targeted/active/modules/100/piranha
20    /etc/selinux/targeted/active/modules/100/pkcs
28    /etc/selinux/targeted/active/modules/100/pki
20    /etc/selinux/targeted/active/modules/100/plymouthd
20    /etc/selinux/targeted/active/modules/100/podsleuth
28    /etc/selinux/targeted/active/modules/100/policykit
20    /etc/selinux/targeted/active/modules/100/polipo
20    /etc/selinux/targeted/active/modules/100/portmap
20    /etc/selinux/targeted/active/modules/100/portreserve
32    /etc/selinux/targeted/active/modules/100/postfix
28    /etc/selinux/targeted/active/modules/100/postgresql
20    /etc/selinux/targeted/active/modules/100/postgrey
28    /etc/selinux/targeted/active/modules/100/ppp
28    /etc/selinux/targeted/active/modules/100/prelink
28    /etc/selinux/targeted/active/modules/100/prelude
20    /etc/selinux/targeted/active/modules/100/privoxy
20    /etc/selinux/targeted/active/modules/100/procmail
20    /etc/selinux/targeted/active/modules/100/prosody
20    /etc/selinux/targeted/active/modules/100/psad
20    /etc/selinux/targeted/active/modules/100/ptchown
20    /etc/selinux/targeted/active/modules/100/publicfile
28    /etc/selinux/targeted/active/modules/100/pulseaudio
28    /etc/selinux/targeted/active/modules/100/puppet
20    /etc/selinux/targeted/active/modules/100/pwauth
20    /etc/selinux/targeted/active/modules/100/qmail
20    /etc/selinux/targeted/active/modules/100/qpid
28    /etc/selinux/targeted/active/modules/100/quantum
20    /etc/selinux/targeted/active/modules/100/quota
20    /etc/selinux/targeted/active/modules/100/rabbitmq
20    /etc/selinux/targeted/active/modules/100/radius
20    /etc/selinux/targeted/active/modules/100/radvd
20    /etc/selinux/targeted/active/modules/100/raid
20    /etc/selinux/targeted/active/modules/100/rasdaemon
20    /etc/selinux/targeted/active/modules/100/rdisc
20    /etc/selinux/targeted/active/modules/100/readahead
32    /etc/selinux/targeted/active/modules/100/realmd
20    /etc/selinux/targeted/active/modules/100/redis
20    /etc/selinux/targeted/active/modules/100/remotelogin
36    /etc/selinux/targeted/active/modules/100/rhcs
28    /etc/selinux/targeted/active/modules/100/rhev
20    /etc/selinux/targeted/active/modules/100/rhgb
20    /etc/selinux/targeted/active/modules/100/rhnsd
20    /etc/selinux/targeted/active/modules/100/rhsmcertd
28    /etc/selinux/targeted/active/modules/100/ricci
16    /etc/selinux/targeted/active/modules/100/rkhunter
24    /etc/selinux/targeted/active/modules/100/rlogin
20    /etc/selinux/targeted/active/modules/100/rngd
20    /etc/selinux/targeted/active/modules/100/roundup
28    /etc/selinux/targeted/active/modules/100/rpc
20    /etc/selinux/targeted/active/modules/100/rpcbind
36    /etc/selinux/targeted/active/modules/100/rpm
20    /etc/selinux/targeted/active/modules/100/rshd
20    /etc/selinux/targeted/active/modules/100/rssh
20    /etc/selinux/targeted/active/modules/100/rsync
20    /etc/selinux/targeted/active/modules/100/rtas
20    /etc/selinux/targeted/active/modules/100/rtkit
20    /etc/selinux/targeted/active/modules/100/rwho
44    /etc/selinux/targeted/active/modules/100/samba
20    /etc/selinux/targeted/active/modules/100/sambagui
28    /etc/selinux/targeted/active/modules/100/sandboxX
20    /etc/selinux/targeted/active/modules/100/sanlock
20    /etc/selinux/targeted/active/modules/100/sasl
20    /etc/selinux/targeted/active/modules/100/sbd
20    /etc/selinux/targeted/active/modules/100/sblim
20    /etc/selinux/targeted/active/modules/100/screen
28    /etc/selinux/targeted/active/modules/100/secadm
20    /etc/selinux/targeted/active/modules/100/sectoolm
36    /etc/selinux/targeted/active/modules/100/selinuxutil
28    /etc/selinux/targeted/active/modules/100/sendmail
20    /etc/selinux/targeted/active/modules/100/sensord
20    /etc/selinux/targeted/active/modules/100/setrans
20    /etc/selinux/targeted/active/modules/100/setroubleshoot
20    /etc/selinux/targeted/active/modules/100/seunshare
28    /etc/selinux/targeted/active/modules/100/sge
20    /etc/selinux/targeted/active/modules/100/shorewall
20    /etc/selinux/targeted/active/modules/100/slocate
20    /etc/selinux/targeted/active/modules/100/slpd
20    /etc/selinux/targeted/active/modules/100/smartmon
20    /etc/selinux/targeted/active/modules/100/smokeping
20    /etc/selinux/targeted/active/modules/100/smoltclient
20    /etc/selinux/targeted/active/modules/100/smsd
20    /etc/selinux/targeted/active/modules/100/snapper
20    /etc/selinux/targeted/active/modules/100/snmp
20    /etc/selinux/targeted/active/modules/100/snort
28    /etc/selinux/targeted/active/modules/100/sosreport
20    /etc/selinux/targeted/active/modules/100/soundserver
28    /etc/selinux/targeted/active/modules/100/spamassassin
20    /etc/selinux/targeted/active/modules/100/speech-dispatcher
28    /etc/selinux/targeted/active/modules/100/squid
36    /etc/selinux/targeted/active/modules/100/ssh
24    /etc/selinux/targeted/active/modules/100/sssd
68    /etc/selinux/targeted/active/modules/100/staff
20    /etc/selinux/targeted/active/modules/100/stapserver
20    /etc/selinux/targeted/active/modules/100/stunnel
20    /etc/selinux/targeted/active/modules/100/su
20    /etc/selinux/targeted/active/modules/100/sudo
20    /etc/selinux/targeted/active/modules/100/svnserve
20    /etc/selinux/targeted/active/modules/100/swift
92    /etc/selinux/targeted/active/modules/100/sysadm
20    /etc/selinux/targeted/active/modules/100/sysadm_secadm
28    /etc/selinux/targeted/active/modules/100/sysnetwork
20    /etc/selinux/targeted/active/modules/100/sysstat
36    /etc/selinux/targeted/active/modules/100/systemd
20    /etc/selinux/targeted/active/modules/100/tangd
20    /etc/selinux/targeted/active/modules/100/targetd
20    /etc/selinux/targeted/active/modules/100/tcpd
20    /etc/selinux/targeted/active/modules/100/tcsd
24    /etc/selinux/targeted/active/modules/100/telepathy
20    /etc/selinux/targeted/active/modules/100/telnet
20    /etc/selinux/targeted/active/modules/100/tftp
20    /etc/selinux/targeted/active/modules/100/tgtd
20    /etc/selinux/targeted/active/modules/100/thin
20    /etc/selinux/targeted/active/modules/100/thumb
20    /etc/selinux/targeted/active/modules/100/tlp
20    /etc/selinux/targeted/active/modules/100/tor
20    /etc/selinux/targeted/active/modules/100/tmpreaper
20    /etc/selinux/targeted/active/modules/100/tomcat
20    /etc/selinux/targeted/active/modules/100/tuned
20    /etc/selinux/targeted/active/modules/100/tvtime
36    /etc/selinux/targeted/active/modules/100/udev
20    /etc/selinux/targeted/active/modules/100/ulogd
20    /etc/selinux/targeted/active/modules/100/uml
20    /etc/selinux/targeted/active/modules/100/unconfined
36    /etc/selinux/targeted/active/modules/100/unconfineduser
16    /etc/selinux/targeted/active/modules/100/unlabelednet
60    /etc/selinux/targeted/active/modules/100/unprivuser
20    /etc/selinux/targeted/active/modules/100/updfstab
20    /etc/selinux/targeted/active/modules/100/usbmodules
20    /etc/selinux/targeted/active/modules/100/usbmuxd
28    /etc/selinux/targeted/active/modules/100/userdomain
20    /etc/selinux/targeted/active/modules/100/userhelper
32    /etc/selinux/targeted/active/modules/100/usermanage
20    /etc/selinux/targeted/active/modules/100/usernetctl
20    /etc/selinux/targeted/active/modules/100/uucp
20    /etc/selinux/targeted/active/modules/100/uuidd
20    /etc/selinux/targeted/active/modules/100/varnishd
20    /etc/selinux/targeted/active/modules/100/vdagent
20    /etc/selinux/targeted/active/modules/100/vhostmd
56    /etc/selinux/targeted/active/modules/100/virt
20    /etc/selinux/targeted/active/modules/100/vlock
28    /etc/selinux/targeted/active/modules/100/vmtools
28    /etc/selinux/targeted/active/modules/100/vmware
20    /etc/selinux/targeted/active/modules/100/vnstatd
20    /etc/selinux/targeted/active/modules/100/vpn
20    /etc/selinux/targeted/active/modules/100/w3c
28    /etc/selinux/targeted/active/modules/100/watchdog
20    /etc/selinux/targeted/active/modules/100/wdmd
24    /etc/selinux/targeted/active/modules/100/webadm
20    /etc/selinux/targeted/active/modules/100/webalizer
20    /etc/selinux/targeted/active/modules/100/wine
20    /etc/selinux/targeted/active/modules/100/wireshark
28    /etc/selinux/targeted/active/modules/100/xen
40    /etc/selinux/targeted/active/modules/100/xguest
56    /etc/selinux/targeted/active/modules/100/xserver
28    /etc/selinux/targeted/active/modules/100/zabbix
20    /etc/selinux/targeted/active/modules/100/zarafa
20    /etc/selinux/targeted/active/modules/100/zebra
20    /etc/selinux/targeted/active/modules/100/zoneminder
20    /etc/selinux/targeted/active/modules/100/zosremote
9376    /etc/selinux/targeted/active/modules/100
0    /etc/selinux/targeted/active/modules/disabled
40    /etc/selinux/targeted/active/modules/200/container
40    /etc/selinux/targeted/active/modules/200
9416    /etc/selinux/targeted/active/modules
17532    /etc/selinux/targeted/active
23340    /etc/selinux/targeted
0    /etc/selinux/final
23348    /etc/selinux
4    /etc/plymouth
0    /etc/gnupg
0    /etc/tuned/recommend.d
16    /etc/tuned
0    /etc/firewalld/helpers
0    /etc/firewalld/icmptypes
0    /etc/firewalld/ipsets
0    /etc/firewalld/services
8    /etc/firewalld/zones
16    /etc/firewalld
8    /etc/audisp/plugins.d
12    /etc/audisp
4    /etc/audit/rules.d
16    /etc/audit
148    /etc/postfix
4    /etc/kernel/postinst.d
4    /etc/kernel
0    /etc/sudoers.d
4    /etc/containerd
8    /etc/docker
35492    /etc/
[root@yinzhengjie.com ~]#

[root@yinzhengjie.com ~]# du /etc/

4>:.指定查看目录的深度

[root@yinzhengjie.com ~]# du /etc/  --max-depth=1
72    /etc/grub.d
0    /etc/terminfo
12    /etc/skel
0    /etc/alternatives
0    /etc/chkconfig.d
8    /etc/libnl
44    /etc/rc.d
100    /etc/pam.d
4    /etc/depmod.d
0    /etc/dracut.conf.d
12    /etc/default
12    /etc/prelink.conf.d
12    /etc/modprobe.d
4    /etc/rsyslog.d
0    /etc/binfmt.d
0    /etc/modules-load.d
40    /etc/systemd
100    /etc/dbus-1
0    /etc/sysctl.d
0    /etc/tmpfiles.d
7764    /etc/udev
136    /etc/lvm
12    /etc/NetworkManager
72    /etc/profile.d
8    /etc/polkit-1
28    /etc/ppp
8    /etc/ntp
4    /etc/X11
20    /etc/bash_completion.d
0    /etc/opt
1008    /etc/pki
0    /etc/pm
352    /etc/sysconfig
0    /etc/xdg
0    /etc/xinetd.d
8    /etc/ld.so.conf.d
4    /etc/dhcp
0    /etc/popt.d
0    /etc/statetab.d
0    /etc/pkcs11
0    /etc/ssl
12    /etc/rpm
44    /etc/yum.repos.d
24    /etc/yum
4    /etc/wpa_supplicant
4    /etc/cron.hourly
0    /etc/krb5.conf.d
0    /etc/gcrypt
0    /etc/cron.weekly
0    /etc/gss
68    /etc/security
4    /etc/sasl2
8    /etc/groff
4    /etc/python
36    /etc/iproute2
12    /etc/my.cnf.d
68    /etc/openldap
8    /etc/cron.daily
4    /etc/rwtab.d
24    /etc/logrotate.d
4    /etc/cron.d
0    /etc/cron.monthly
604    /etc/ssh
23348    /etc/selinux
4    /etc/plymouth
0    /etc/gnupg
16    /etc/tuned
16    /etc/firewalld
12    /etc/audisp
16    /etc/audit
148    /etc/postfix
4    /etc/kernel
0    /etc/sudoers.d
4    /etc/containerd
8    /etc/docker
35492    /etc/
[root@yinzhengjie.com ~]#

[root@yinzhengjie.com ~]# du /etc/ --max-depth=1

5>.以人性化的形式显示

[root@yinzhengjie.com ~]# du -sh /* 
0    /bin
100M    /boot
0    /dev
35M    /etc
16K    /home
0    /lib
0    /lib64
0    /media
1.8G    /mnt
16K    /opt
du: cannot access ‘/proc/6403/task/6403/fd/4’: No such file or directory
du: cannot access ‘/proc/6403/task/6403/fdinfo/4’: No such file or directory
du: cannot access ‘/proc/6403/fd/4’: No such file or directory
du: cannot access ‘/proc/6403/fdinfo/4’: No such file or directory
0    /proc
60K    /root
12M    /run
0    /sbin
0    /srv
0    /sys
0    /tmp
1.6G    /usr
1.8G    /var
1.4G    /yinzhengjie
[root@yinzhengjie.com ~]#

[root@yinzhengjie.com ~]# du -sh /*

三.转换和复制文件(convert and copy a file)工具-dd

1>.查看dd命令的帮助信息

[root@yinzhengjie.com ~]# dd --help
Usage: dd [OPERAND]...
  or:  dd OPTION
Copy a file, converting and formatting according to the operands.

  bs=BYTES        read and write up to BYTES bytes at a time
  cbs=BYTES       convert BYTES bytes at a time
  conv=CONVS      convert the file as per the comma separated symbol list
  count=N         copy only N input blocks
  ibs=BYTES       read up to BYTES bytes at a time (default: 512)
  if=FILE         read from FILE instead of stdin
  iflag=FLAGS     read as per the comma separated symbol list
  obs=BYTES       write BYTES bytes at a time (default: 512)
  of=FILE         write to FILE instead of stdout
  oflag=FLAGS     write as per the comma separated symbol list
  seek=N          skip N obs-sized blocks at start of output
  skip=N          skip N ibs-sized blocks at start of input
  status=LEVEL    The LEVEL of information to print to stderr;
                  'none' suppresses everything but error messages,
                  'noxfer' suppresses the final transfer statistics,
                  'progress' shows periodic transfer statistics

N and BYTES may be followed by the following multiplicative suffixes:
c =1, w =2, b =512, kB =1000, K =1024, MB =1000*1000, M =1024*1024, xM =M
GB =1000*1000*1000, G =1024*1024*1024, and so on for T, P, E, Z, Y.

Each CONV symbol may be:

  ascii     from EBCDIC to ASCII
  ebcdic    from ASCII to EBCDIC
  ibm       from ASCII to alternate EBCDIC
  block     pad newline-terminated records with spaces to cbs-size
  unblock   replace trailing spaces in cbs-size records with newline
  lcase     change upper case to lower case
  ucase     change lower case to upper case
  sparse    try to seek rather than write the output for NUL input blocks
  swab      swap every pair of input bytes
  sync      pad every input block with NULs to ibs-size; when used
            with block or unblock, pad with spaces rather than NULs
  excl      fail if the output file already exists
  nocreat   do not create the output file
  notrunc   do not truncate the output file
  noerror   continue after read errors
  fdatasync  physically write output file data before finishing
  fsync     likewise, but also write metadata

Each FLAG symbol may be:

  append    append mode (makes sense only for output; conv=notrunc suggested)
  direct    use direct I/O for data
  directory  fail unless a directory
  dsync     use synchronized I/O for data
  sync      likewise, but also for metadata
  fullblock  accumulate full blocks of input (iflag only)
  nonblock  use non-blocking I/O
  noatime   do not update access time
  nocache   discard cached data
  noctty    do not assign controlling terminal from file
  nofollow  do not follow symlinks
  count_bytes  treat 'count=N' as a byte count (iflag only)
  skip_bytes  treat 'skip=N' as a byte count (iflag only)
  seek_bytes  treat 'seek=N' as a byte count (oflag only)

Sending a USR1 signal to a running 'dd' process makes it
print I/O statistics to standard error and then resume copying.

  $ dd if=/dev/zero of=/dev/null& pid=$!
  $ kill -USR1 $pid; sleep 1; kill $pid
  18335302+0 records in
  18335302+0 records out
  9387674624 bytes (9.4 GB) copied, 34.6279 seconds, 271 MB/s

Options are:

      --help     display this help and exit
      --version  output version information and exit

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
For complete documentation, run: info coreutils 'dd invocation'
[root@yinzhengjie.com ~]#

[root@yinzhengjie.com ~]# dd --help            #更多信息请参考"man dd"的帮助手册

  dd命令常用选项介绍:
    if:
      指定源文件,即从所命名文件读取而不是从标准输入

    of:
      指定目标文件,即写到所命名的文件而不是到标准输出。

    bs:
      指定块大小(既是是ibs也是obs)

    ibs:
      一次读size个byte

    obs:
      一次写size个byte

    cbs:
      一次转化size个byte

    skip:
      从开头忽略blocks个ibs大小的块

    seek:
      从开头忽略blocks个obs大小的块

    count:
      只拷贝n个记录

    conv:
      用指定的参数转换文件,常见的转换参数如下所示:
        ascii:
          转换EBCDIC 为ASCII
        ebcdic:
          转换ASCII 为EBCDIC
        lcase:
          把大写字符转换为小写字符
        ucase:
          把小写字符转换为大写字符
        nocreat:
          不创建输出文件
        noerror:
          出错时不停止
        notrunc:
          不截断输出文件
        sync:
          把每个输入块填充到ibs个字节,不足部分用空(NUL)字符补齐
        Fdatasync:
          写完成前,物理写入输出文件

2>.使用dd命令备份MBR

[root@yinzhengjie.com ~]# dd if=/dev/sda of=/tmp/mbr.bak bs=512 count=1
1+0 records in
1+0 records out
512 bytes (512 B) copied, 0.000135145 s, 3.8 MB/s
[root@yinzhengjie.com ~]# 
[root@yinzhengjie.com ~]# ll /tmp/mbr.bak 
-rw-r--r-- 1 root root 512 May 28 19:26 /tmp/mbr.bak
[root@yinzhengjie.com ~]#

[root@yinzhengjie.com ~]# dd if=/dev/sda of=/tmp/mbr.bak bs=512 count=1

[root@yinzhengjie.com ~]# hexdump -C /tmp/mbr.bak 
00000000  eb 63 90 00 00 00 00 00  00 00 00 00 00 00 00 00  |.c..............|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000050  00 00 00 00 00 00 00 00  00 00 00 80 00 08 00 00  |................|
00000060  00 00 00 00 ff fa 90 90  f6 c2 80 74 05 f6 c2 70  |...........t...p|
00000070  74 02 b2 80 ea 79 7c 00  00 31 c0 8e d8 8e d0 bc  |t....y|..1......|
00000080  00 20 fb a0 64 7c 3c ff  74 02 88 c2 52 be 05 7c  |. ..d|<.t...R..||
00000090  b4 41 bb aa 55 cd 13 5a  52 72 3d 81 fb 55 aa 75  |.A..U..ZRr=..U.u|
000000a0  37 83 e1 01 74 32 31 c0  89 44 04 40 88 44 ff 89  |7...t21..D.@.D..|
000000b0  44 02 c7 04 10 00 66 8b  1e 5c 7c 66 89 5c 08 66  |D.....f..|f..f|
000000c0  8b 1e 60 7c 66 89 5c 0c  c7 44 06 00 70 b4 42 cd  |..`|f...D..p.B.|
000000d0  13 72 05 bb 00 70 eb 76  b4 08 cd 13 73 0d 5a 84  |.r...p.v....s.Z.|
000000e0  d2 0f 83 de 00 be 85 7d  e9 82 00 66 0f b6 c6 88  |.......}...f....|
000000f0  64 ff 40 66 89 44 04 0f  b6 d1 c1 e2 02 88 e8 88  |d.@f.D..........|
00000100  f4 40 89 44 08 0f b6 c2  c0 e8 02 66 89 04 66 a1  |.@.D.......f..f.|
00000110  60 7c 66 09 c0 75 4e 66  a1 5c 7c 66 31 d2 66 f7  |`|f..uNf.|f1.f.|
00000120  34 88 d1 31 d2 66 f7 74  04 3b 44 08 7d 37 fe c1  |4..1.f.t.;D.}7..|
00000130  88 c5 30 c0 c1 e8 02 08  c1 88 d0 5a 88 c6 bb 00  |..0........Z....|
00000140  70 8e c3 31 db b8 01 02  cd 13 72 1e 8c c3 60 1e  |p..1......r...`.|
00000150  b9 00 01 8e db 31 f6 bf  00 80 8e c6 fc f3 a5 1f  |.....1..........|
00000160  61 ff 26 5a 7c be 80 7d  eb 03 be 8f 7d e8 34 00  |a.&Z|..}....}.4.|
00000170  be 94 7d e8 2e 00 cd 18  eb fe 47 52 55 42 20 00  |..}.......GRUB .|
00000180  47 65 6f 6d 00 48 61 72  64 20 44 69 73 6b 00 52  |Geom.Hard Disk.R|
00000190  65 61 64 00 20 45 72 72  6f 72 0d 0a 00 bb 01 00  |ead. Error......|
000001a0  b4 0e cd 10 ac 3c 00 75  f4 c3 00 00 00 00 00 00  |.....<.u........|
000001b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001c0  01 00 ee fe ff ff 01 00  00 00 ff ff ff ff 00 00  |................|
000001d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|
00000200
[root@yinzhengjie.com ~]#

[root@yinzhengjie.com ~]# hexdump -C /tmp/mbr.bak

3>.破坏MBR中的bootloader

[root@yinzhengjie.com ~]# hexdump -C /dev/sda -n 512
00000000  eb 63 90 00 00 00 00 00  00 00 00 00 00 00 00 00  |.c..............|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000050  00 00 00 00 00 00 00 00  00 00 00 80 00 08 00 00  |................|
00000060  00 00 00 00 ff fa 90 90  f6 c2 80 74 05 f6 c2 70  |...........t...p|
00000070  74 02 b2 80 ea 79 7c 00  00 31 c0 8e d8 8e d0 bc  |t....y|..1......|
00000080  00 20 fb a0 64 7c 3c ff  74 02 88 c2 52 be 05 7c  |. ..d|<.t...R..||
00000090  b4 41 bb aa 55 cd 13 5a  52 72 3d 81 fb 55 aa 75  |.A..U..ZRr=..U.u|
000000a0  37 83 e1 01 74 32 31 c0  89 44 04 40 88 44 ff 89  |7...t21..D.@.D..|
000000b0  44 02 c7 04 10 00 66 8b  1e 5c 7c 66 89 5c 08 66  |D.....f..|f..f|
000000c0  8b 1e 60 7c 66 89 5c 0c  c7 44 06 00 70 b4 42 cd  |..`|f...D..p.B.|
000000d0  13 72 05 bb 00 70 eb 76  b4 08 cd 13 73 0d 5a 84  |.r...p.v....s.Z.|
000000e0  d2 0f 83 de 00 be 85 7d  e9 82 00 66 0f b6 c6 88  |.......}...f....|
000000f0  64 ff 40 66 89 44 04 0f  b6 d1 c1 e2 02 88 e8 88  |d.@f.D..........|
00000100  f4 40 89 44 08 0f b6 c2  c0 e8 02 66 89 04 66 a1  |.@.D.......f..f.|
00000110  60 7c 66 09 c0 75 4e 66  a1 5c 7c 66 31 d2 66 f7  |`|f..uNf.|f1.f.|
00000120  34 88 d1 31 d2 66 f7 74  04 3b 44 08 7d 37 fe c1  |4..1.f.t.;D.}7..|
00000130  88 c5 30 c0 c1 e8 02 08  c1 88 d0 5a 88 c6 bb 00  |..0........Z....|
00000140  70 8e c3 31 db b8 01 02  cd 13 72 1e 8c c3 60 1e  |p..1......r...`.|
00000150  b9 00 01 8e db 31 f6 bf  00 80 8e c6 fc f3 a5 1f  |.....1..........|
00000160  61 ff 26 5a 7c be 80 7d  eb 03 be 8f 7d e8 34 00  |a.&Z|..}....}.4.|
00000170  be 94 7d e8 2e 00 cd 18  eb fe 47 52 55 42 20 00  |..}.......GRUB .|
00000180  47 65 6f 6d 00 48 61 72  64 20 44 69 73 6b 00 52  |Geom.Hard Disk.R|
00000190  65 61 64 00 20 45 72 72  6f 72 0d 0a 00 bb 01 00  |ead. Error......|
000001a0  b4 0e cd 10 ac 3c 00 75  f4 c3 00 00 00 00 00 00  |.....<.u........|
000001b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001c0  01 00 ee fe ff ff 01 00  00 00 ff ff ff ff 00 00  |................|
000001d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|
00000200
[root@yinzhengjie.com ~]#

[root@yinzhengjie.com ~]# hexdump -C /dev/sda -n 512

[root@yinzhengjie.com ~]# dd if=/dev/zero of=/dev/sda bs=64 count=1 seek=446
1+0 records in
1+0 records out
64 bytes (64 B) copied, 0.000603372 s, 106 kB/s
[root@yinzhengjie.com ~]#

[root@yinzhengjie.com ~]# dd if=/dev/zero of=/dev/sda bs=64 count=1 seek=446

[root@yinzhengjie.com ~]# hexdump -C /dev/sda -n 512 -v
00000000  eb 63 90 00 00 00 00 00  00 00 00 00 00 00 00 00  |.c..............|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000030  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000040  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000050  00 00 00 00 00 00 00 00  00 00 00 80 00 08 00 00  |................|
00000060  00 00 00 00 ff fa 90 90  f6 c2 80 74 05 f6 c2 70  |...........t...p|
00000070  74 02 b2 80 ea 79 7c 00  00 31 c0 8e d8 8e d0 bc  |t....y|..1......|
00000080  00 20 fb a0 64 7c 3c ff  74 02 88 c2 52 be 05 7c  |. ..d|<.t...R..||
00000090  b4 41 bb aa 55 cd 13 5a  52 72 3d 81 fb 55 aa 75  |.A..U..ZRr=..U.u|
000000a0  37 83 e1 01 74 32 31 c0  89 44 04 40 88 44 ff 89  |7...t21..D.@.D..|
000000b0  44 02 c7 04 10 00 66 8b  1e 5c 7c 66 89 5c 08 66  |D.....f..|f..f|
000000c0  8b 1e 60 7c 66 89 5c 0c  c7 44 06 00 70 b4 42 cd  |..`|f...D..p.B.|
000000d0  13 72 05 bb 00 70 eb 76  b4 08 cd 13 73 0d 5a 84  |.r...p.v....s.Z.|
000000e0  d2 0f 83 de 00 be 85 7d  e9 82 00 66 0f b6 c6 88  |.......}...f....|
000000f0  64 ff 40 66 89 44 04 0f  b6 d1 c1 e2 02 88 e8 88  |d.@f.D..........|
00000100  f4 40 89 44 08 0f b6 c2  c0 e8 02 66 89 04 66 a1  |.@.D.......f..f.|
00000110  60 7c 66 09 c0 75 4e 66  a1 5c 7c 66 31 d2 66 f7  |`|f..uNf.|f1.f.|
00000120  34 88 d1 31 d2 66 f7 74  04 3b 44 08 7d 37 fe c1  |4..1.f.t.;D.}7..|
00000130  88 c5 30 c0 c1 e8 02 08  c1 88 d0 5a 88 c6 bb 00  |..0........Z....|
00000140  70 8e c3 31 db b8 01 02  cd 13 72 1e 8c c3 60 1e  |p..1......r...`.|
00000150  b9 00 01 8e db 31 f6 bf  00 80 8e c6 fc f3 a5 1f  |.....1..........|
00000160  61 ff 26 5a 7c be 80 7d  eb 03 be 8f 7d e8 34 00  |a.&Z|..}....}.4.|
00000170  be 94 7d e8 2e 00 cd 18  eb fe 47 52 55 42 20 00  |..}.......GRUB .|
00000180  47 65 6f 6d 00 48 61 72  64 20 44 69 73 6b 00 52  |Geom.Hard Disk.R|
00000190  65 61 64 00 20 45 72 72  6f 72 0d 0a 00 bb 01 00  |ead. Error......|
000001a0  b4 0e cd 10 ac 3c 00 75  f4 c3 00 00 00 00 00 00  |.....<.u........|
000001b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001c0  01 00 ee fe ff ff 01 00  00 00 ff ff ff ff 00 00  |................|
000001d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|
00000200
[root@yinzhengjie.com ~]#

[root@yinzhengjie.com ~]# hexdump -C /dev/sda -n 512 -v

4>.将小写字母转换为大写

[root@yinzhengjie.com ~]# cat /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Mon Jan 20 04:18:36 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root             /                       xfs     defaults                0 0
UUID=1865a93f-6113-4097-89dc-8c4ea5fdf68c     /boot                   xfs     defaults                0 0

#Add by yinzhengjie
/dev/mapper/centos-yinzhengjie                /yinzhengjie            xfs     defaults,noatime,nodiratime     0 0
UUID=075b12f8-0a1f-4aef-a393-3f8fb6240e43     /mnt/sdb5         ext4     defaults,noexec            0 0
/boot                          /mnt/boot         none    bind                0 0
/yinzhengjie/data/ext4file            /mnt/ext4        ext4    loop                0 0
#/dev/sr0                    /mnt/cdrom        iso9660    defaults            0 0

#Add by yinzhengjie for mount "/home".
UUID=2307c9c5-f7b1-4a2b-b9e9-46d89a9c7c81     /home             xfs    defaults            0 0
[root@yinzhengjie.com ~]#

[root@yinzhengjie.com ~]# cat /etc/fstab

[root@yinzhengjie.com ~]# dd if=/etc/fstab of=/tmp/fstab.bak conv=ucase            #将"/etc/fstab"文件的字符转换为大写并写入到"/tmp/fstab.bak"文件中
1+1 records in
1+1 records out
868 bytes (868 B) copied, 0.000140742 s, 6.2 MB/s
[root@yinzhengjie.com ~]# 
[root@yinzhengjie.com ~]# cat /tmp/fstab.bak 

#
# /ETC/FSTAB
# CREATED BY ANACONDA ON MON JAN 20 04:18:36 2020
#
# ACCESSIBLE FILESYSTEMS, BY REFERENCE, ARE MAINTAINED UNDER '/DEV/DISK'
# SEE MAN PAGES FSTAB(5), FINDFS(8), MOUNT(8) AND/OR BLKID(8) FOR MORE INFO
#
/DEV/MAPPER/CENTOS-ROOT             /                       XFS     DEFAULTS                0 0
UUID=1865A93F-6113-4097-89DC-8C4EA5FDF68C     /BOOT                   XFS     DEFAULTS                0 0

#ADD BY YINZHENGJIE
/DEV/MAPPER/CENTOS-YINZHENGJIE                /YINZHENGJIE            XFS     DEFAULTS,NOATIME,NODIRATIME     0 0
UUID=075B12F8-0A1F-4AEF-A393-3F8FB6240E43     /MNT/SDB5         EXT4     DEFAULTS,NOEXEC            0 0
/BOOT                          /MNT/BOOT         NONE    BIND                0 0
/YINZHENGJIE/DATA/EXT4FILE            /MNT/EXT4        EXT4    LOOP                0 0
#/DEV/SR0                    /MNT/CDROM        ISO9660    DEFAULTS            0 0

#ADD BY YINZHENGJIE FOR MOUNT "/HOME".
UUID=2307C9C5-F7B1-4A2B-B9E9-46D89A9C7C81     /HOME             XFS    DEFAULTS            0 0
[root@yinzhengjie.com ~]#

[root@yinzhengjie.com ~]# dd if=/etc/fstab of=/tmp/fstab.bak conv=ucase            #将"/etc/fstab"文件的字符转换为大写并写入到"/tmp/fstab.bak"文件中

5>.不截断输出文件(标准输出指定的是普通文件默认会被截断,但设备并不会截断哟)

[root@yinzhengjie.com ~]# cat f1.txt
ABCEDFGHIJKLMN
[root@yinzhengjie.com ~]# 
[root@yinzhengjie.com ~]# cat f2.txt
12345
[root@yinzhengjie.com ~]# 
[root@yinzhengjie.com ~]# dd if=f2.txt of=f1.txt bs=1 count=3 skip=2 seek=5
3+0 records in
3+0 records out
3 bytes (3 B) copied, 0.000268328 s, 11.2 kB/s
[root@yinzhengjie.com ~]# 
[root@yinzhengjie.com ~]# cat f2.txt
12345
[root@yinzhengjie.com ~]# 
[root@yinzhengjie.com ~]# cat f1.txt          #很明显,f1.txt文件内容被截断啦~
ABCED345[root@yinzhengjie.com ~]#

[root@yinzhengjie.com ~]# dd if=f2.txt of=f1.txt bs=1 count=3 skip=2 seek=5

[root@yinzhengjie.com ~]# cat f1.txt-bak 
ABCEDFGHIJKLMN
[root@yinzhengjie.com ~]# 
[root@yinzhengjie.com ~]# cat f2.txt-bak 
12345
[root@yinzhengjie.com ~]# 
[root@yinzhengjie.com ~]# dd if=f2.txt-bak of=f1.txt-bak bs=1 count=3 skip=2 seek=5 conv=notrunc      #添加不被截断参数
3+0 records in
3+0 records out
3 bytes (3 B) copied, 0.000123465 s, 24.3 kB/s
[root@yinzhengjie.com ~]# 
[root@yinzhengjie.com ~]# cat f2.txt-bak 
12345
[root@yinzhengjie.com ~]# 
[root@yinzhengjie.com ~]# cat f1.txt-bak           #很明显,目标文件并未被截断
ABCED345IJKLMN
[root@yinzhengjie.com ~]# 
[root@yinzhengjie.com ~]#

[root@yinzhengjie.com ~]# dd if=f2.txt-bak of=f1.txt-bak bs=1 count=3 skip=2 seek=5 conv=notrunc      #添加不被截断参数

6>.使用dd命令用于备份和恢复

  备份操作:
    将本地的/dev/sdx整盘备份到/dev/sdy:
      dd if=/dev/sdx of=/dev/sdy
    将/dev/sdx全盘数据备份到指定路径的image文件:
      dd if=/dev/sdx of=/path/to/image
    备份/dev/sdx全盘数据,并利用gzip压缩,保存到指定路径
      dd if=/dev/sdx | gzip >/path/to/image.gz
  
  恢复操作:
    将备份文件恢复到指定盘
      dd if=/path/to/image of=/dev/sdx
    将压缩的备份文件恢复到指定盘:
      gzip -dc /path/to/image.gz | dd of=/dev/sdx


  温馨提示:
    当硬盘较长时间(比如1,2年)放置不使用后,磁盘上会产生消磁点。当磁头读到这些区域时会遇到困难,并可能导致I/O错误。当这种情况影响到硬盘的第一个扇区时,可能导致硬盘报废。
    下边的命令有可能使这些数据起死回生,且这个过程是安全高效的.
      dd if=/dev/sda of=/dev/sda

7>.拷贝内存资料到硬盘

  将内存里的数据拷贝到root目录下的mem.bin文件:
    dd if=/dev/mem of=/root/mem.bin bs=1024

8>.从光盘拷贝iso镜像

  拷贝光盘数据到root文件夹下,并保存为cd.iso文件:
    dd if=/dev/cdrom of=/root/cd.iso

9>.销毁磁盘数据

  利用随机的数据填充硬盘,在某些必要的场合可以用来销毁数据,执行此操作以后,/dev/sda1将无法挂载,创建和拷贝操作无法执行:
    dd if=/dev/urandom of=/dev/sda1

10>.得到最恰当的block size

  存储相同大小文件,通过比较dd指令输出中命令的执行时间,即可确定系统最佳的block size大小。通常使用默认4K即可。

[root@yinzhengjie.com ~]# dd if=/dev/zero of=/root/1Gb.file bs=1024 count=1000000
1000000+0 records in
1000000+0 records out
1024000000 bytes (1.0 GB) copied, 8.54313 s, 120 MB/s
[root@yinzhengjie.com ~]#

[root@yinzhengjie.com ~]# dd if=/dev/zero of=/root/1Gb.file bs=1024 count=1000000

[root@yinzhengjie.com ~]# rm -rf /root/1Gb.file 
[root@yinzhengjie.com ~]# 
[root@yinzhengjie.com ~]# dd if=/dev/zero of=/root/1Gb.file bs=2048 count=500000
500000+0 records in
500000+0 records out
1024000000 bytes (1.0 GB) copied, 1.30068 s, 787 MB/s
[root@yinzhengjie.com ~]#

[root@yinzhengjie.com ~]# dd if=/dev/zero of=/root/1Gb.file bs=2048 count=500000

[root@yinzhengjie.com ~]# rm -rf /root/1Gb.file 
[root@yinzhengjie.com ~]# 
[root@yinzhengjie.com ~]# dd if=/dev/zero of=/root/1Gb.file bs=4096 count=250000
250000+0 records in
250000+0 records out
1024000000 bytes (1.0 GB) copied, 0.880223 s, 1.2 GB/s
[root@yinzhengjie.com ~]#

[root@yinzhengjie.com ~]# dd if=/dev/zero of=/root/1Gb.file bs=4096 count=250000        #速度最佳

11>.测试硬盘写速度

[root@yinzhengjie.com ~]# dd if=/dev/zero of=/root/10Gb.file bs=1024 count=10000000        #写一个10G的测试文件,观察写入磁盘写入速度的大小。
10000000+0 records in
10000000+0 records out
10240000000 bytes (10 GB) copied, 87.2831 s, 117 MB/s
[root@yinzhengjie.com ~]#

[root@yinzhengjie.com ~]# dd if=/dev/zero of=/root/10Gb.file bs=1024 count=10000000        #写一个10G的测试文件,观察写入磁盘写入速度的大小。

12>.测试硬盘读速度

[root@yinzhengjie.com ~]# dd if=/root/10Gb.file bs=64k | dd of=/dev/null              #将上一步生成的10G文件读取,观察读取速度的大小
156250+0 records in
156250+0 records out
10240000000 bytes (10 GB) copied, 38.9709 s, 263 MB/s
20000000+0 records in
20000000+0 records out
10240000000 bytes (10 GB) copied, 38.9712 s, 263 MB/s
[root@yinzhengjie.com ~]#

[root@yinzhengjie.com ~]# dd if=/root/10Gb.file bs=64k | dd of=/dev/null              #将上一步生成的10G文件读取,观察读取速度的大小

13>.博主推荐阅读

  Linux测试硬盘读性能的常用工具-hdparm和dd俩搭档:
    https://www.cnblogs.com/yinzhengjie/p/9935478.html
相关实践学习
基于Redis实现在线游戏积分排行榜
本场景将介绍如何基于Redis数据库实现在线游戏中的游戏玩家积分排行榜功能。
云数据库 Redis 版使用教程
云数据库Redis版是兼容Redis协议标准的、提供持久化的内存数据库服务,基于高可靠双机热备架构及可无缝扩展的集群架构,满足高读写性能场景及容量需弹性变配的业务需求。 产品详情:https://www.aliyun.com/product/kvstore &nbsp; &nbsp; ------------------------------------------------------------------------- 阿里云数据库体验:数据库上云实战 开发者云会免费提供一台带自建MySQL的源数据库&nbsp;ECS 实例和一台目标数据库&nbsp;RDS实例。跟着指引,您可以一步步实现将ECS自建数据库迁移到目标数据库RDS。 点击下方链接,领取免费ECS&amp;RDS资源,30分钟完成数据库上云实战!https://developer.aliyun.com/adc/scenario/51eefbd1894e42f6bb9acacadd3f9121?spm=a2c6h.13788135.J_3257954370.9.4ba85f24utseFl
目录
相关文章
|
6月前
|
存储 监控 安全
《Linux 简易速速上手小册》第6章: 磁盘管理与文件系统(2024 最新版)
《Linux 简易速速上手小册》第6章: 磁盘管理与文件系统(2024 最新版)
65 1
|
6月前
|
存储 安全 前端开发
《Linux 简易速速上手小册》第3章: 文件系统与权限(2024 最新版)
《Linux 简易速速上手小册》第3章: 文件系统与权限(2024 最新版)
75 1
|
存储 缓存 负载均衡
需要搭建一个高性能的文件系统?我推荐你试试它.....(上)
需要搭建一个高性能的文件系统?我推荐你试试它.....(上)
需要搭建一个高性能的文件系统?我推荐你试试它.....(上)
|
6月前
|
Ubuntu Linux 开发工具
【专栏】在Linux上,exa是一个现代化的文件管理系统替代工具,提供直观的文件信息展示。
【4月更文挑战第28天】在Linux上,exa是一个现代化的文件管理系统替代工具,提供直观的文件信息展示。要安装exa,可以在基于Debian的系统(如Ubuntu)上运行`sudo apt install exa`,基于RedHat(如CentOS)的系统运行`sudo yum install exa`,或从源代码编译安装。使用exa的基本命令是`exa`,它列出当前目录的文件和目录。通过选项如`-F`(显示文件类型)、`-h`(人类可读大小)、`-l`(详细信息)和`-s`(排序)可以定制输出。exa还能与其他命令(如grep)结合使用,提升效率。
97 0
|
6月前
|
运维 Ubuntu Linux
【Linux操作系统】探秘Linux奥秘:日志管理的解密与实战
【Linux操作系统】探秘Linux奥秘:日志管理的解密与实战
81 0
|
6月前
|
存储 Ubuntu Linux
【Linux操作系统】探秘Linux奥秘:文件系统的管理与使用
【Linux操作系统】探秘Linux奥秘:文件系统的管理与使用
64 0
|
Linux
嵌入式Linux QT开发之如何实现获取磁盘空间大小的应用逻辑
嵌入式Linux QT开发之如何实现获取磁盘空间大小的应用逻辑
241 0
|
Ubuntu Linux Go
嵌入式Linux系列第19篇:如何高效的阅读Linux源码
嵌入式Linux系列第19篇:如何高效的阅读Linux源码
|
缓存 Linux 测试技术
二十五、Linux性能优化实战学习笔记Linux 磁盘I/O是怎么工作的?(下)
使用率、饱和度、IOPS、吞吐量以及响应时间等。这五个指标,是衡量磁盘性能的基本指标。
264 1
|
存储 缓存 算法
十五、Linux性能优化实战学习笔记 - Linux内存是怎么工作的
内存管理也是操作系统最核心的功能之一。内存主要用来存储系统和应用程序的指令、数据、缓存等
302 1