find size of the files
Hi all,
To find the space occupied by files modified more than 4 years ago, i tried following.I am wondering if it is right ? Code:
find /temp -type d ! -name ".*" -mtime +1460 | wc -l |du -sh P.S.: SHELL=bash OS=RHEL5 |
Two things. The ".*" will match a file in the current directory,
namely "..". Changing it to '.*' will prevent matching and actually send .* to the command. Second, the find command is piped to wc -l, which will output a number. Then this number is piped to du. I don't think this is what you want. Try this and see if it gives you what you want: Code:
find /temp -type d ! -name ".*" -mtime +1460 -exec du -sh {} \; |
Hi carltm,
Thank you for quick reply. I included ".*" to avoid counting hidden files (not sure if that is correct) The below command did not give me any output. Code:
find /temp -type d ! -name ".*" -mtime +1460 -exec du -sh {} \; |
The -type d predicate restricts the results to directories. Maybe this is not what you want, since modification time of directories is often updated every time you change the content of the directory itself. This means you hardly have a directory modified more than 4 years ago!
If you want the total size of the files matching the -mtime condition, you might do something like: Code:
find . -type f ! -name '.*' -mtime +1460 -printf "%s\n" | awk '{sum+=$1}END{print sum}' |
Hi colucix,
thank you. It does work. does this size in bytes or MB ? |
Quote:
Code:
%s File’s size in bytes. |
Hi colucix,
I got 11686287604 as an answer for this command. I doubt this is true because 11686287604 is almost like 10.8TB. The total filesystem size is not more than 3TB. I am wondering what went wrong. As i said i am trying to find size of the files modified 4 years back (that is those files are no longer used meanwhile). Thanks! |
Code:
11686287604 bytes = 11e+9 bytes = 11 Gb |
Hi colucix,
I did my math assuming they are in KB. My bad. Thanks for all the help. |
You're welcome! :)
|
All times are GMT -5. The time now is 08:38 PM. |