Today, I will explain how to check the file size of the directory under the Linux system for you in detail, so as to help you better manage and use your digital devices.
1. Basic command: ls
When we want to see the size of a file in a certain directory, the most direct command is ls. You can use ls -l to view the details of the file, where the fifth column is the file size. If you want to get a more intuitive idea of the file size, you can use ls -lh, so that the file size will be displayed in k, m, g, etc., which is easier to read.
2. Check the total size of the directory: du
If you want to know the total size of the entire directory and its subdirectories, then the du command will be your best handy. With du -sh path to directory, you can quickly get the total size of the directory. Among them, "-s" indicates the summary output, and "-h" indicates that it is displayed in units such as k, m, and g.
3. Sort and view and find files of a specific size.
If you want to sort the files in a directory by size, you can use the ls -lsh command, where "-s" means to sort by size and "-r" can be sorted in reverse order. Also, if you want to find files in a directory that are larger than a certain size, you can use the find command, such as find path to directory -type f -size +1g, to find files larger than 1g.
4. Advanced tools: NCDU
In addition to the basic command-line tools, there are many advanced tools under Linux that can help us better view and manage file sizes, among which I recommend NCDU the most. It is a text-based disk usage analysis tool that provides a simple command-line operation to visualize the size of individual directories and files, making it ideal for detailed analysis and management of disk space.
Through the above four steps, I believe you have a deep understanding of how to view directory file size under Linux. Whether it is basic LS and DU commands, or advanced FIND and NCDU tools, it can help us to be more comfortable when managing digital devices. Remember, mastering these commands will not only improve your productivity, but also make your digital life more organized and convenient.