calculate total used disk space by files older than 180 days using find
@PeterT is right. Almost all these answers invoke a command (du) for each file, which is very resource intensive and slow and unnecessary. The simplest and fastest way is this:
find . -type f -mtime +356 -printf '%s\n' | awk '{total=total+$1}END{print total/1024}'
calculate in TB total used disk space by files newer than X days using find
Well not quite the same logic but I'm here to explain:
{ echo -n \(; find -type f -mtime -30 -printf "%s+"; echo 0\)/1024/1024/1024/1024; } | bc
Let's break this down:
echo -n \(
- prints(
without a line break.find …
- that same ol' command you used with the+
sign for calculation.echo 0\)/1024…
- we're printing0
so the expression won't end with a+
sign, print the closing parentheses and then dividing by 1024 four times to get to the relevant result.| bc
- this is the calculation tool, you can simply pipe the formula to this tool, try runningecho 1+2 | bc
and play with it to understand its concept.
Have fun, and cool name BTW :)
Calculate disk usage on bash. sum of files bigger than space used,
Using
du --apparent-size
Solve my problem as pointed by @matias-barrios and @barmar
More info at https://superuser.com/questions/94217/why-ls-and-du-show-different-size
Need help to write a shell script to calculate the directory space used & free
It sounds like you are looking for the command "df". Unfortunately, the output and options depend on whatever flavor of UNIX you happen to be using.
Type "man df" or try "df -h" on a command line to learn more.
Here's an example from my Mac:
kim-burgaards-macbook-pro:~ kim$ df
Filesystem 512-blocks Used Available Capacity Mounted on
/dev/disk0s2 976101344 912544576 63044768 94% /
devfs 224 224 0 100% /dev
map -hosts 0 0 0 100% /net
map auto_home 0 0 0 100% /home
/dev/disk1s1 976773104 761379976 215393128 78% /Volumes/Photo Vault
/dev/disk2s2 1952853344 1844058136 108795208 95% /Volumes/Backup
As far as I remember, the output looks very similar on Solaris.
Monitoring total size of disk access of a process in Linux
Check these Linux commands pidstat, iostat, iotop. Also you can find quickly at /proc/<PID>/io
.
Release disk space used by cgi.FieldStorage temp files
This problem I encountered was unrelated to cgi.FieldStorage, pyramid actually uses WebOb for serializing data.
The cause of the high disk space usage was pyramid_debugtoolbar
. The debugger states in it's documentation that it maintains the data from the previous 100 requests, which took up a great amount of memory and disk space in my case. Removing the include for the debugger from __init__.py
and restarting the server resolved the problem.
Execute a command which will check if the disk space on somepartion is greater than 1 KB, return -1 else return 0
This may do:
df | awk 'END {print ($4<1024?"-1":"0")}'
0
You can change the number to any that fits your need.END
is used to get last line, instead of tail
To get it into an exit/return code do:
(exit $(df | awk 'END {print ($4<1024?"-1":"0")}')); echo "$?"
PS exit -1
will give 255
Related Topics
The Address Where Filename Has Been Loaded Is Missing [Gdb]
How to Prefill Command Line Input
Udev - Run Program on Usb Flash Drive Insert
Export Variables Defined in Another File
Error Running Make: Missing Separator (Did You Mean Tab Instead of 8 Spaces)
Converting Avi Frames to Jpgs on Linux
How to Change Perf_Event_Open Max Sample Rate
Why Gcc 4.X Default Reserve 8 Bytes for Stack on Linux When Calling a Method
A Way to Determine a Process'S "Real" Memory Usage, I.E. Private Dirty Rss
Is It Safe to Issue Blocking Write() Calls on the Same Tcp Socket from Multiple Threads
Elf Program Header Virtual Address and File Offset
Using the Linux Sysfs_Notify Call
Git - Windows and Linux Line-Endings
Interrupt Handling and User Space Notification
Jmeter - Could Not Find the Testplan Class
Comparison of Integer and Floating Point Numbers in Shell Script