check file size with du command

·

3 min read

In this blog post, we will discuss how to check the size of a file in Linux using the du command. This is a very handy command that can be used for a variety of purposes. We will go over some of the most common uses for the du command and show you how to use it in practice. Stay tuned, because by the end of this blog post you will be able to check file sizes like a pro!

You can also use ls command, stat command or find command. Each command has a different benefit.

This post explains more info about how to use Linux commands to check file size.

The du command is a great way to quickly check the size of a file, directory, or other type of file system object. When used with no options, it will return the total disk space used by each file or directory and all its children. This information can be useful for identifying large files that are taking up too much space on a hard drive.

If you want to check the size of a single file, you can use the du command with the -h option. This will show the size of that particular file in human-readable form (like kbytes or megabytes).

for example:

$ du -h my_file.txt

This command will return the size of my_file.txt.

You can use the du command to show a summary of disk space usage in a given directory (including subdirectories). To do this, you can add the -s option. This will cause the command to display only total disk space used instead of showing each individual file’s size.

For example:

$ du -sh my_dir

This command will return the total disk space used by all files and subdirectories in my_dir.

The du command can also be used with the -a option. This will show an individual file or directory’s size, as well as any hidden files and directories within it. This can be useful for finding large files that might otherwise be difficult to locate.

For example:

$ du -ah my_dir

This command will return the size of all files, directories, and hidden items in my_dir.

The du command can also be used to skip certain directories on different file systems. This is done with the -x option. For example, if you wanted to check the size of a directory but didn’t want to include its subdirectories on the different file system:

$ du -xh my_dir/

This command will return the size of all files in my_dir, but not on the different file system.

Overall, the du command is a great way to quickly check the size of files and directories in Linux. With these simple options, you can now easily find large files or directories that are taking up more space than they should be. We hope this article was helpful in understanding how to use the du command! Good luck!