

Here are some advantages to use du command to check file size in Linux. If you want du to check the sizes of all files and subdirectories within “mydir”, you can use the “-sh” option: It can be used to find out not only the size of a given file, but also the size of a directory.įor example, to check the size of the file “myfile.txt”, you would type: Enter the command du /home/howtouselinuxĤ096 /home/howtouselinux/.mozilla/pluginsĤ.0K /home/howtouselinux/.mozilla/pluginsĤ.0K /home/howtouselinux/.mozilla/extensionsĭu is a command line utility for estimating file space usage. To find out the disk usage summary of a /home/howtouselinux directory tree and each of its subdirectories. This is the most efficient way to get the size of a directory in du -sh /home/howtouselinux This will give you a total size for the directory, rather than listing the size of each individual file and subdirectory within it. If you need to get the size of a directory in Linux, use du -sh command. It can be used to check the disk usage of files and directories on Linux system. The Linux du (Disk Usage) is a standard Unix/Linux command. Can we use du command to check the size of a directory in Linux? The answer is yes. Now we know that we can use du command to get the size of file. If you need to get the size for all the files under the current directory, you can use this command.
#FILE DETAILS LINUX CODE#
In bash, we can use the following code to get the file size only.įilesize=$(du -h /etc/passwd | awk '') From the command output in our example, we can see that the size of file test is 4.0K. Here ~ means the home directory in Linux.
#FILE DETAILS LINUX FULL#
Or we can use du command followed by the full path of the file. This is one of my favorite option for du command.įor example, if we need to check the size of file test under our home directory, we can use following commands. It offers many helpful options individually or in the correct combinations.ĭu -h option will print file size in human readable format (e.g., 1K 234M 2G). The du command summarizes disk usage of each file and recursively for each directory. Here’s an example from Redhat that highlights why we can use du command: This means we can see file size in Bytes, Kilobytes, Megabytes, Gigabytes, etc.

The size will be displayed in Human Readable Format. The file size will be listed on the first column. Change into the directory where the file is located. The most efficient way to check file size in Linux is using du command.

The following Linux commands can be used to check file size. If you want to check your disk size, you can check this article. I will use text files as examples in this article. A file doesn’t include only text files, images, and compiled programs but also includes partitions, hardware device drivers, and directories. I will also cover why the file size is different between the ls command and the du command in some cases.
#FILE DETAILS LINUX HOW TO#
In this article, I will explain how to check the size of a file using these four commands and their use cases. The find command helps you search for files of a certain size.The stat command gives you more details about a particular file, including its size.The ls command shows you information about files, including their size.The du command tells you how much space a particular file or directory is taking up on your system.To check file size in Linux, you can use du, ls, stat, or find commands. What is the best way to check file size in Linux?.How can I find out how much space a directory takes up in Linux?.How can I find the total size of all files and folders in a directory in Linux?.How can I check the size of a file in Linux?.Recently we got some questions from our readers about how to check file size in Linux.
