LinuxQuestions.org
Help answer threads with 0 replies.
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 12-28-2009, 11:55 AM   #1
kirukan
Senior Member
 
Registered: Jun 2008
Location: Eelam
Distribution: Redhat, Solaris, Suse
Posts: 1,274

Rep: Reputation: 148Reputation: 148
Total particular files size in a directory


Please give some idea, i need to count total size of files which were created in a particular date(Ex:-the files were created on Dec 25)

I have used following
#ls -l | grep "Dec 25" | du -k
I believe this is wrong
Note:- This is for Solaris 8 environment
 
Old 12-28-2009, 01:09 PM   #2
GooseYArd
Member
 
Registered: Jul 2009
Location: Reston, VA
Distribution: Slackware, Ubuntu, RHEL
Posts: 183

Rep: Reputation: 46
Quote:
Originally Posted by kirukan View Post
Please give some idea, i need to count total size of files which were created in a particular date(Ex:-the files were created on Dec 25)

I have used following
#ls -l | grep "Dec 25" | du -k
I believe this is wrong
Note:- This is for Solaris 8 environment

ls -l | grep "Dec 25" | awk '{ SUM += $5} END { print SUM/1024/1024 }'

should do it.

You can also use the unix find command in place of ls and grep, but by the time you read the find manpage to figure out how to use the find time parameters, you could have finished the command with ls and grep already
 
Old 01-03-2010, 11:47 AM   #3
kirukan
Senior Member
 
Registered: Jun 2008
Location: Eelam
Distribution: Redhat, Solaris, Suse
Posts: 1,274

Original Poster
Rep: Reputation: 148Reputation: 148
Quote:
ls -l | grep "Dec 25"
This also wont give us perfect size because if there is any subdirectories within the main direcoty, ls -l count subdirectories also, I just need only regular files size which were created on a particular date(Ex:- 25th December 2009 ).

In find command
#find * -type f -mtime 10, from today(3rd January 2010)
The above command may print the files which were created on 25th December 2009 (but it doesn't print, i don't know what mistake is there)
But as i have seen find command, it only print the files name so how can i calculate the total size?

Please anybody have idea?
 
Old 01-03-2010, 02:48 PM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Quote:
Originally Posted by kirukan View Post
find * -type f -mtime 10
This does not print anything since you cannot use a wildcard as the search path: if you want to start your search from the current directory use a dot or if you want to start from another point, just use its full (or relative) path. For example, these ones are valid
Code:
find . -type f -mtime 10
find /usr/local -type f -mtime 10
Take in mind that the wildcard is expanded by the shell with all the (not hidden) items in the current directory and the resulting command line is a non-sense.

Another clue is that you will not find exactly the files last modified on December 25th using -mtime 10, first because if you subtract 10 days from 3rd of January you get the 24th of December, second because you have to consider the rounding effect of timestamp. Here is an explanation for the -atime predicate from the GNU find man
Code:
When find figures out how many 24-hour periods ago the file was last accessed,
any fractional part is ignored, so to match -atime +1, a file has to have been
accessed at least two days ago.
The GNU find has addressed the problem introducing the -daystart option, to match relative times from the 00:00 of the current day. Unfortunately you don't have this facility in solaris.

Regarding the total size calculation here are two methods (depending on what commands are available on your solaris box):

1) just use find and ls (using the -exec predicate) and sum the file sizes by piping the output to awk (as suggested by GooseYArd above)
Code:
find . -type f -mtime 10 -exec ls -l {} \; | awk '{sum += $5} END{print sum}'
2) if you have the GNU find (Solaris 8 provided a lot of GNU commands prepending a "g" to the command name) you can take advantage of the -printf predicate to print out just the file sizes:
Code:
gfind . -type f -mtime 10 -printf "%s\n" | awk '{sum += $1} END{print sum}'
Hope this helps.
 
  


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
BASH : Total directory size xgreen Programming 7 03-04-2013 05:33 AM
How to find grand total size of all files in a directory fakhrul Red Hat 4 04-17-2010 12:28 AM
Total size of directory and zipped files veeruk101 Linux - Newbie 1 07-17-2007 10:32 PM
finding size of total files in a directory blackzone Linux - Newbie 3 01-07-2005 03:01 AM
How to list total file size of a directory phil1076 Linux - General 3 12-18-2003 03:47 PM


All times are GMT -5. The time now is 12:34 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