LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 04-05-2012, 07:10 AM   #1
nicksrulz
LQ Newbie
 
Registered: Mar 2012
Posts: 4

Rep: Reputation: Disabled
calculate total size


Was just wondering if anyone knows a script that can be used to find total size of all the files of a user's disk quota in Linux.

Any suggestions?
 
Old 04-05-2012, 07:37 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
that is not a script but a single command: du (disk usage). Just look at the man page.
 
Old 04-05-2012, 07:46 AM   #3
uhelp
Member
 
Registered: Nov 2011
Location: Germany, Bavaria, Nueremberg area
Distribution: openSUSE, Debian, LFS
Posts: 205

Rep: Reputation: 43
repquota -u YourUser

@pan64
that might be useful if one is only interested in the total size of the users home dir.
But does not report the total size of all files.
There could be much more files in dirs not belonging to the users home.
Think of /temp or alike

Last edited by uhelp; 04-05-2012 at 07:50 AM.
 
Old 04-06-2012, 02:17 AM   #4
nicksrulz
LQ Newbie
 
Registered: Mar 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thanks!!!! pan64 and uhelp

#!/bin/bash

total_size=0

for file in * ; do
file_size=$( ls -ld ${file} | awk '{print $3 }' )
echo "${file_size} ${file}"
((total_size=total_size+file_size))
done

echo "------------"
echo "Total size: ${total_size}"


This is what i have done, but it give me sizes of all the files.... i want to print size used by paticular users.. but m not gettng it
 
Old 04-06-2012, 02:26 AM   #5
deep27ak
Senior Member
 
Registered: Aug 2011
Location: Bangalore, India
Distribution: RHEL 7.x, SLES 11 SP2/3/4
Posts: 1,195
Blog Entries: 4

Rep: Reputation: 221Reputation: 221Reputation: 221
I am not sure about the script as I am not so good with it but the same can be done through du

Code:
# du -sch /home/deepak/*
4.0K    /home/deepak/Desktop
4.0K    /home/deepak/Documents
4.0K    /home/deepak/Downloads
112K    /home/deepak/Maildir
4.0K    /home/deepak/Music
4.0K    /home/deepak/Pictures
4.0K    /home/deepak/Public
4.0K    /home/deepak/Templates
4.0K    /home/deepak/Videos
144K    total
 
Old 04-06-2012, 02:35 AM   #6
nicksrulz
LQ Newbie
 
Registered: Mar 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thanks Deepak!!! your command prints the size of each files and give total size... But i want to print total size used by a paticular user in a directory.... Any suggestions
 
Old 04-06-2012, 03:11 AM   #7
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
You almost made it....
Code:
find <dir> -type f -user <user> -exec ls -l {} \; | awk ' { a += $5 } END { print a } '
 
Old 04-06-2012, 06:06 AM   #8
deep27ak
Senior Member
 
Registered: Aug 2011
Location: Bangalore, India
Distribution: RHEL 7.x, SLES 11 SP2/3/4
Posts: 1,195
Blog Entries: 4

Rep: Reputation: 221Reputation: 221Reputation: 221
you can run this command

Code:
#find / -type f -user $USER -exec du -sch {} \;
you can try different switch option with du

you can copy the o/p to some file as well for refrence
Code:
#find / -type f -user $USER -exec du -sch {} > size.txt \;
 
Old 04-06-2012, 07:20 AM   #9
uhelp
Member
 
Registered: Nov 2011
Location: Germany, Bavaria, Nueremberg area
Distribution: openSUSE, Debian, LFS
Posts: 205

Rep: Reputation: 43
and another variant:
Code:
UsedSpace=$( ( find / -user username | du -s ) 2>/dev/null )
echo ${UsedSpace%% *}
Outputs just the amount of Bytes.
"du -sh" will output it human readable.
 
  


Reply



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
Calculate total memory consumed by user emymcse Linux - General 12 09-23-2010 05:26 AM
how to calculate total cpu time of task in percentage using task_struct namit2010 Linux - Kernel 1 05-24-2009 11:43 PM
Calculate total number of mailq items a1phanumeric Linux - Newbie 1 11-15-2007 11:29 AM
How to calculate the total RAM used by several processes rjlee Linux - Software 3 07-19-2007 05:33 PM
I don't understand how to calculate the total value of (ls -l) greeting Linux - General 7 08-12-2006 05:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:38 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
Open Source Consulting | Domain Registration