iT邦幫忙

第 12 屆 iThome 鐵人賽

0
自我挑戰組

30天菜鳥學 Linux 系列 第 38

38天-研究du用法

  • 分享至 

  • xImage
  •  

今天進度研究 du 用法

du 用法 :

root@test:/# du --help
Usage: du [OPTION]... [FILE]...
  or:  du [OPTION]... --files0-from=F
Summarize disk usage of the set of FILEs, recursively for directories.

Mandatory arguments to long options are mandatory for short options too.
  -0, --null            end each output line with NUL, not 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).

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

GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Full documentation at: <https://www.gnu.org/software/coreutils/du>
or available locally via: info '(coreutils) du invocation'

顯示根目錄底下的資料 KB 大小

root@test:/# du -sk /*
0	/bin
198552	/boot
4	/cdrom
0	/demo.txt
0	/dev
6736	/etc
15388	/home
0	/lib
0	/lib32
0	/lib64
0	/libx32
16	/lost+found
4	/media
4	/mnt
4	/opt
du: cannot access '/proc/16046/task/16046/fd/4': No such file or directory
du: cannot access '/proc/16046/task/16046/fdinfo/4': No such file or directory
du: cannot access '/proc/16046/fd/3': No such file or directory
du: cannot access '/proc/16046/fdinfo/3': No such file or directory
0	/proc
21676	/root
1084	/run
0	/sbin
1819298	/snap
4	/srv
2097156	/swap.img
0	/sys
84	/tmp
2874164	/usr
2840124	/var

好閱讀版本 -h :

root@test:/# du -s -h /*
0	/bin
194M	/boot
4.0K	/cdrom
0	/demo.txt
0	/dev
6.6M	/etc
16M	/home
0	/lib
0	/lib32
0	/lib64
0	/libx32
16K	/lost+found
4.0K	/media
4.0K	/mnt
4.0K	/opt
du: cannot access '/proc/16051/task/16051/fd/4': No such file or directory
du: cannot access '/proc/16051/task/16051/fdinfo/4': No such file or directory
du: cannot access '/proc/16051/fd/3': No such file or directory
du: cannot access '/proc/16051/fdinfo/3': No such file or directory
0	/proc
22M	/root
1.1M	/run
0	/sbin
1.8G	/snap
4.0K	/srv
2.1G	/swap.img
0	/sys
84K	/tmp
2.8G	/usr
2.8G	/var

不加 -s 會將遍歷全部子資料夾

root@test:/var/log# du -h /*
166K	/snap/core18/1885/usr/lib/python3/dist-packages/cryptography/hazmat/backends/openssl/__pycache__
389K	/snap/core18/1885/usr/lib/python3/dist-packages/cryptography/hazmat/backends/openssl
417K	/snap/core18/1885/usr/lib/python3/dist-packages/cryptography/hazmat/backends
512	/snap/core18/1885/usr/lib/python3/dist-packages/cryptography/hazmat/bindings/__pycache__
13K	/snap/core18/1885/usr/lib/python3/dist-packages/cryptography/hazmat/bindings/openssl/__pycache__
27K	/snap/core18/1885/usr/lib/python3/dist-packages/cryptography/hazmat/bindings/openssl
972K	/snap/core18/1885/usr/lib/python3/dist-packages/cryptography/hazmat/bindings
30K	/snap/core18/1885/usr/lib/python3/dist-packages/cryptography/hazmat/primitives/__pycache__
48K	/snap/core18/1885/usr/lib/python3/dist-packages/cryptography/hazmat/primitives/asymmetric/__pycache__
89K	/snap/core18/1885/usr/lib/python3/dist-packages/cryptography/hazmat/primitives/asymmetric
28K	/snap/core18/1885/usr/lib/python3/dist-packages/cryptography/hazmat/primitives/ciphers/__pycache__
53K	/snap/core18/1885/usr/lib/python3/dist-packages/cryptography/hazmat/primitives/ciphers
20K	/snap/core18/1885/usr/lib/python3/dist-packages/cryptography/hazmat/primitives/kdf/__pycache__
42K	/snap/core18/1885/usr/lib/python3/dist-packages/cryptography/hazmat/primitives/kdf
6.5K	/snap/core18/1885/usr/lib/python3/dist-packages/cryptography/hazmat/primitives/twofactor/__pycache__
13K	/snap/core18/1885/usr/lib/python3/dist-packages/cryptography/hazmat/primitives/twofactor
254K	/snap/core18/1885/usr/lib/python3/dist-packages/cryptography/hazmat/primitives
1.7M	/snap/core18/1885/usr/lib/python3/dist-packages/cryptography/hazmat
106K	/snap/core18/1885/usr/lib/python3/dist-packages/cryptography/x509/__pycache__
207K	/snap/core18/1885/usr/lib/python3/dist-packages/cryptography/x509
1.9M	/snap/core18/1885/usr/lib/python3/dist-packages/cryptography
6.5K	/snap/core18/1885/usr/lib/python3/dist-packages/cryptography-2.1.4.egg-info
261K	/snap/core18/1885/usr/lib/python3/dist-packages/idna/__pycache__
493K	/snap/core18/1885/usr/lib/python3/dist-packages/idna
12K	/snap/core18/1885/usr/lib/python3/dist-packages/idna-2.6.egg-info
378K	/snap/core18/1885/usr/lib/python3/dist-packages/jinja2/__pycache__
812K	/snap/core18/1885/usr/lib/python3/dist-packages/jinja2
4.0K	/snap/core18/1885/usr/lib/python3/dist-packages/jsonpatch-1.16.egg-info
3.5K	/snap/core18/1885/usr/lib/python3/dist-packages/jsonpointer-1.10.egg-info
57K	/snap/core18/1885/usr/lib/python3/dist-packages/jsonschema/__pycache__
11K	/snap/core18/1885/usr/lib/python3/dist-packages/jsonschema/schemas
64K	/snap/core18/1885/usr/lib/python3/dist-packages/jsonschema/tests/__pycache__
129K	/snap/core18/1885/usr/lib/python3/dist-packages/jsonschema/tests
254K	/snap/core18/1885/usr/lib/python3/dist-packages/jsonschema
7.5K	/snap/core18/1885/usr/lib/python3/dist-packages/jsonschema-2^C


上一篇
37天-Linux 的檔案權限與目錄
下一篇
第39天-學習 od 指令
系列文
30天菜鳥學 Linux 59
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言