du command
The du
command is a Linux utility that estimates the space used by a file or directory and displays the sizes in a human-readable format. Here are some common options you can use with du
:
-
-a
or--all
: show sizes of directories and files, including hidden files -
-b
or--bytes
: display sizes in bytes -
-c
or--total
: display a grand total of all the file sizes -
-h
or--human-readable
: display sizes in a human-readable format (e.g., 1K 234M 2G) -
-s
or--summarize
: display only a total for each argument -
--exclude=PATTERN
: exclude files and directories that match the PATTERN specified -
--exclude-from=FILE
: exclude patterns listed in the specified FILE
Here are some examples of how you can use du
:
To show the sizes of all files and directories in the current directory, including hidden files:
du -a
To display the sizes of all files and directories in the /var
directory in human-readable format:
du -sh /var
To display the sizes of all files and directories in the current directory, excluding files and directories that match the pattern *.tmp
:
du -a --exclude='*.tmp'
df command
The df
command is a Linux utility that displays information about the available and used disk space on a file system. Here are some common options you can use with df
:
-
-a
or--all
: include pseudo, duplicate, and inaccessible file systems -
-B
or--block-size=SIZE
: use SIZE-byte blocks -
-h
or--human-readable
: display sizes in a human-readable format (e.g., 1K 234M 2G) -
-H
or--si
: like-h
, but use powers of 1000 not 1024 -
-i
or--inodes
: display inode information -
-k
or--kilobytes
: display sizes in kilobytes -
-l
or--local
: limit the output to local file systems -
-T
or--print-type
: display the file system type
Here are some examples of how you can use df
:
To display information about all mounted file systems:
df -h
To display information about the file system that contains the current directory, in human-readable format:
Copy code
df -h .
what is the difference between du and df command ?
The du
command is used to estimate the space used by a file or directory, while the df
command is used to display information about the available and used disk space on a file system.
One key difference between these two commands is the level of granularity at which they operate. du
examines individual files and directories and displays the sizes of each, while df
provides an overview of the entire file system or a specific mounted file system.
I hope this helps clarify the difference between these two commands. Let me know if you have any questions.a
Top comments (1)
Nice one!
I find very useful
df -h /
du -sh <path>