LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   find size of the files (https://www.linuxquestions.org/questions/linux-newbie-8/find-size-of-the-files-885206/)

linuxandtsm 06-08-2011 08:42 AM

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
I tried this, but this sits there for long time (of couse the path i tried has lot of files) So i am not sure if this is right.

P.S.: SHELL=bash
OS=RHEL5

carltm 06-08-2011 08:59 AM

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 {} \;

linuxandtsm 06-08-2011 09:07 AM

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 {} \;
Where should i be getting the result ?

colucix 06-08-2011 09:17 AM

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}'

linuxandtsm 06-08-2011 09:37 AM

Hi colucix,
thank you.
It does work. does this size in bytes or MB ?

colucix 06-08-2011 10:01 AM

Quote:

Originally Posted by linuxandtsm (Post 4379946)
does this size in bytes or MB ?

In bytes! Check the man page of find and see all the formats available to the -printf option:
Code:

        %s    File’s size in bytes.

linuxandtsm 06-08-2011 10:08 AM

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!

colucix 06-08-2011 10:11 AM

Code:

11686287604 bytes = 11e+9 bytes = 11 Gb
;)

linuxandtsm 06-08-2011 10:15 AM

Hi colucix,

I did my math assuming they are in KB.
My bad.
Thanks for all the help.

colucix 06-08-2011 10:18 AM

You're welcome! :)


All times are GMT -5. The time now is 08:38 PM.