LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-08-2011, 09:42 AM   #1
linuxandtsm
Member
 
Registered: May 2011
Posts: 194

Rep: Reputation: Disabled
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
 
Old 06-08-2011, 09:59 AM   #2
carltm
Member
 
Registered: Jan 2007
Location: Canton, MI
Distribution: CentOS, SuSE, Red Hat, Debian, etc.
Posts: 703

Rep: Reputation: 97
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 {} \;
 
Old 06-08-2011, 10:07 AM   #3
linuxandtsm
Member
 
Registered: May 2011
Posts: 194

Original Poster
Rep: Reputation: Disabled
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 ?
 
Old 06-08-2011, 10:17 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
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}'
 
Old 06-08-2011, 10:37 AM   #5
linuxandtsm
Member
 
Registered: May 2011
Posts: 194

Original Poster
Rep: Reputation: Disabled
Hi colucix,
thank you.
It does work. does this size in bytes or MB ?
 
Old 06-08-2011, 11:01 AM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by linuxandtsm View Post
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.
 
Old 06-08-2011, 11:08 AM   #7
linuxandtsm
Member
 
Registered: May 2011
Posts: 194

Original Poster
Rep: Reputation: Disabled
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!
 
Old 06-08-2011, 11:11 AM   #8
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Code:
11686287604 bytes = 11e+9 bytes = 11 Gb
 
1 members found this post helpful.
Old 06-08-2011, 11:15 AM   #9
linuxandtsm
Member
 
Registered: May 2011
Posts: 194

Original Poster
Rep: Reputation: Disabled
Hi colucix,

I did my math assuming they are in KB.
My bad.
Thanks for all the help.
 
Old 06-08-2011, 11:18 AM   #10
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
You're welcome!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to find grand total size of all files in a directory fakhrul Red Hat 4 04-17-2010 01:28 AM
How to recursively find files over a certain size beckettisdogg Linux - Newbie 1 04-15-2010 05:56 PM
how to show size of files in FIND command packets Linux - General 5 04-17-2007 11:49 PM
How to find files within certain size boundaries? kornerr Linux - General 2 06-18-2006 01:14 AM
what command can i use to find files of a certain size? abutzki Linux - Newbie 2 01-31-2006 08:43 AM


All times are GMT -5. The time now is 07:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration