I'm trying to get the size of the directories named "bak" with find and du.
I do that : find -name bak -type d -exec du -ch '{}' \;
But it returns the size for each folder named "bak" not the total.
Anyway to get them ? Thanks :)
Go to Windows Explorer and right-click on the file, folder or drive that you're investigating. From the menu that appears, go to Properties. This will show you the total file/drive size.
Right-click the file and click Properties. The image below shows that you can determine the size of the file or files you have highlighted from in the file properties window. In this example, the chrome. jpg file is 18.5 KB (19,032 bytes), and that the size on disk is 20.0 KB (20,480 bytes).
To get the total size of a directory in Linux, you can use the du (disk-usage) command.
You can run "df" UNIX command with the current directory or any specified directory. See below example of df command in UNIX to find out the size of a directory along with space left in file system. $ df -h .
Use xargs(1)
instead of -exec
:
find . -name bak -type d | xargs du -ch
-exec
executes the command for each file found (check the find(1)
documentation). Piping to xargs
lets you aggregate those filenames and only run du
once. You could also do:
find -name bak -type d -exec du -ch '{}' \; +
If your version of find
supports it.
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