The method of viewing file and directory size by Linux
This article introduces you to Linux view file and directory size method, the content is very detailed, interested friends can refer to reference, hope to be helpful to everyone.
After using df command in Linux system, you can view the relevant situation of directory, but df has no effect on file, you can use du to view the relevant properties of file.
application scenarios
1. Perform file operations and encounter No space left on device. You can understand the overall layout by looking at the disk file size. 2. Check the file size before moving and transferring files to determine whether there is enough space available.
df command usage
df -T
df -T View mount directory
df -T Display Diagram
df -h
df -h View mount directory
df -h display
The parameter-h indicates output using "Human-readable", displaying output in human-readable formats such as GB, MB, etc. Unlike-T (T upper case), the file system type is not displayed, and the mount directory size is more readable.
Therefore, it is better to use df -Th in combination to view the size of the mount directory, as shown in the figure.
df -Th display
du command usage
du Common parameters
-h: Display in a human-readable manner (GB, MB)
-a: Displays the disk space occupied by directories, and also displays the disk space occupied by directories and files under them.
-s: Displays the disk space occupied by directories, not their subdirectories and files
-c: Display the disk space occupied by several directories or files, and also count their sum
Apparent-size: Displays the size of the directory or file itself
-l: Counts the size of disk space occupied by hard links
-L: Counts the amount of disk space occupied by the file to which the symbolic link points
cd location directory
du -sh View the total capacity of the current directory. The capacity occupied by each sub-item is not listed separately.
du -sh * View the capacity of files and subdirectories in the current directory (capacity occupied by each subitem).
du -sh * |sort -n Statistics the size of files and subdirectories in the current directory, and sorts them by-n (size).
About Linux view file and directory size method to share here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.