Cách kiểm tra dung lượng ổ cứng trên Linux bằng lệnh ‘df’

Lệnh ‘df’ là gì? Lệnh ‘df’ trong Linux nghĩa là 'disk filesystem'. Nó được sử dụng để hiển thị tóm tắt đầy đủ về việc sử dụng không gian đĩa cứng còn sẵn và được sử dụng của hệ thống tập tin trên hệ thống Linux.

Cách kiểm tra dung lượng ổ cứng trên Linux bằng lệnh ‘df’ 1

Kiểm tra dung lượng ổ đĩa

Lệnh ‘df’ hiển thị thông tin về tên thiết bị, tổng số khối, tổng dung lượng, đĩa, dung lượng đĩa đã sử dụng, dung lượng đĩa sẵn có và các mount point trên hệ thống tệp.

# df

Filesystem        1K-blocks Used Available Use% Mounted on

/dev/sda3          18292484 13836896 3519704  80% /

tmpfs                508072 112 507960   1% /dev/shm

/dev/sda1            194241 123105 60896  67% /boot

/home/ssh/key.img      9911 93 9306   1% /tmp/ssh-mount

Hiển thị thông tin của tất cả dung lượng đĩa đã sử dụng

Giống như trên, nhưng df -a sẽ hiển thị thông tin của các hệ thống tập tin cùng với tất cả mức sử dụng dung lượng ổ cứng của hệ thống tập tin.

# df -a

Filesystem        1K-blocks Used Available Use% Mounted on

/dev/sda3          18292484 13836896 3519704  80% /

proc                      0 0 0 - /proc

sysfs                     0 0 0 - /sys

devpts                    0 0 0 - /dev/pts

tmpfs                508072 112 507960   1% /dev/shm

/dev/sda1            194241 123105 60896  67% /boot

none                      0 0 0 - /proc/sys/fs/binfmt_misc

/home/ssh/key.img      9911 93 9306   1% /tmp/ssh-mount

Hiển thị mức sử dụng dung lượng ổ cứng theo định dạng dễ đọc

Các lệnh trên hiển thị thông tin dung lượng ổ cứng mặc định theo byte không dễ đọc. Bởi chúng ta có thói quen đọc kích thước theo megabyte, gigabyte,... vì nó rất dễ hiểu và dễ nhớ.

Lệnh df cung cấp tùy chọn hiển thị dung lượng sử dụng ở định dạng. Có thể đọc được bằng cách sử dụng ‘-h’.

# df -ha

Filesystem         Size Used Avail Use% Mounted on

/dev/sda3           18G 14G 3.4G 80% /

proc                  0 0 0 - /proc

sysfs                 0 0 0 - /sys

devpts                0 0 0 - /dev/pts

tmpfs              497M 112K 497M 1% /dev/shm

/dev/sda1          190M 121M 60M 67% /boot

none                  0 0 0 - /proc/sys/fs/binfmt_misc

/home/ssh/key.img  9.7M 93K 9.1M 1% /tmp/ssh-mount

Hiển thị thông tin dung lượng của /home file system

Để check dung lượng ổ của thư mục /home file system, ta sử dụng câu lệnh dưới đây:

# df -hT /home/

Filesystem     Type Size Used Avail Use% Mounted on

/dev/sda3      ext4 18G 14G  3.4G 80% /

Hiển thị thông tin dung lượng của File system theo dạng Bytes

Để hiển thị thông tin của tất cả file system theo dạng khối 1024-byte, ta sử dụng tùy chọn '-k'.

#  df -k

Filesystem        1K-blocks Used Available Use% Mounted on

/dev/sda3          18292484 13836896 3519704  80% /

tmpfs                508072 112 507960   1% /dev/shm

/dev/sda1            194241 123105 60896  67% /boot

/home/ssh/key.img      9911 93 9306   1% /tmp/ssh-mount

Hiển thị thông tin dung lượng của File system theo Megabytes

# df -m

Filesystem        1M-blocks Used Available Use% Mounted on

/dev/sda3             17864 13513 3438 80% /

tmpfs                   497 1 497 1% /dev/shm

/dev/sda1               190 121 60 67% /boot

/home/ssh/key.img        10 1 10 1% /tmp/ssh-mount

Hiển thị thông tin Inodes của file system

Sử dụng option '-i' sẽ hiển thị thông tin về số lượng inodes đã sử dụng và tỷ lệ phần trăm của chúng cho từng file system.

# df -i

Filesystem         Inodes IUsed IFree IUse% Mounted on

/dev/sda3         1171456 219378 952078   19% /

tmpfs              127018 11 127007    1% /dev/shm

/dev/sda1           51200 62 51138   1% /boot

/home/ssh/key.img    2560 12 2548 1% /tmp/ssh-mount

Hiển thị các loại file system

Nếu bạn để ý những câu lệnh output ở phía trên, bạn sẽ nhìn thấy rằng không có liệt kê loại file system (ext4, xfs, ext3,...). Để kiểm tra loại file system đang sử dụng, ta có thể sử dụng tùy chọn 'T'.

# df -Th

Filesystem        Type Size Used Avail Use% Mounted on

/dev/sda3         ext4 18G 14G 3.4G  80% /

tmpfs             tmpfs 497M 112K 497M   1% /dev/shm

/dev/sda1         ext4 190M 121M   60M 67% /boot

/home/ssh/key.img ext2   9.7M 93K 9.1M 1% /tmp/ssh-mount

Hiển thị thông tin dựa trên loại file system

Nếu bạn muốn hiển thị một số loại file hệ thống ta sử dụng '-t' và thêm tên của loại file bạn muốn. Ví dụ:

# df -t ext4

Filesystem     1K-blocks Used Available Use% Mounted on

/dev/sda3       18292484 13826712   3529888 80% /

/dev/sda1         194241 123105   60896 67% /boot

Hiển thị thông tin của lệnh df

Sử dụng lệnh '-help' sẽ liệt kê danh sách những tùy chọn có thể áp dụng với lệnh df.

# 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 dummy file systems

  -B, --block-size=SIZE  use SIZE-byte blocks

      --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)

  -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 may be (or may be an integer optionally followed by) one of following:

KB 1000, K 1024, MB 1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y.




Report df bugs to bug-coreutils@gnu.org

GNU coreutils home page: <http://www.gnu.org/software/coreutils/>

General help using GNU software: <http://www.gnu.org/gethelp/>

For complete documentation, run: info coreutils 'df invocation'

Chúc bạn thành công với bài hướng dẫn cách kiểm tra dung lượng ổ cứng trên Linux bằng lệnh ‘df’ mà chúng tôi đã giới thiệu trên đây.

Mọi người cùng tìm kiếm: check dung lượng ổ cứng linux, check dung luong o cung ubuntu, check dung luong folder linux, 1k-blocks, cách kiểm tra dung lượng ổ cứng