I'm trying to write a script that will calculate a directory size and if the size is less than 10GB, and greater then 2GB do some action. Where do I need to mention my folder name?
# 10GB SIZE="1074747474" # check the current size CHECK="`du /data/sflow_log/`" if [ "$CHECK" -gt "$SIZE" ]; then echo "DONE" fi
Add the argument -c to see a Total line at the end. Example: du -hcs or du -hc . Remove the argument -h to see the sizes in exact KiB instead of human-readable MiB or GiB formats. Example: du -s or du -cs .
To get the total size of a directory in Linux, you can use the du (disk-usage) command.
In File explorer, right click on folder for which you want to see folder size, and click on "Properties" in context menu. This will display folder properties dialog showing folder size in "Size" and "Size on disk" display field.
Display the size of one or more directories, subdirectories, and files by using the du command. Sizes are displayed in 512-byte blocks. Displays the size of each directory that you specify, including each subdirectory beneath it.
We will be looking at various ways to check the file or folder size available on the Linux system. The du in the “du” command specifies the disk usage, which is available in all Linux distributions by default. Run the below command for checking the disk usage for your Linux system.
This tutorial will discuss quick methods you can use in a bash script to get file size in the specified format such as Bytes, Kilobytes, Megabytes, or Gigabytes. The first method is to use the good old ls command.
A directory may have directories inside (called subdirectories ), or it may only contain files. The du command stands for disk usage. This command is included by default in most Linux distributions. You can display the size of your current directory by typing du in the command line:
However, the command line - sometimes known as the terminal - doesn’t have an intuitive interface for checking disk space in Linux. This guide shows you how to find the size of a specific directory in Linux from the command line. Note: In Linux, a directory is the equivalent of a folder in Windows.
You can do:
du -hs your_directory
which will give you a brief output of the size of your target directory. Using a wildcard like *
can select multiple directories.
If you want a full listing of sizes for all files and sub-directories inside your target, you can do:
du -h your_directory
Tips:
Add the argument -c
to see a Total line at the end. Example: du -hcs
or du -hc
.
Remove the argument -h
to see the sizes in exact KiB instead of human-readable MiB or GiB formats. Example: du -s
or du -cs
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With