LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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
 
LinkBack Search this Thread
Old 03-02-2009, 03:49 AM   #1
sahil.jammu
Member
 
Registered: Jun 2008
Distribution: Ubuntu
Posts: 83

Rep: Reputation: 15
Find the space for files owned by specific users


Hi All,

I was trying to fetch data to calculate results for all the users , the issue is to find the files owned by one particular user in the server , display them and then also give the size for them and then total size!!

i was trying with :-

find -user user1 | sort -nr |du --max-depth=1 -h | more

This is not giving desired results.

Can you suggest few useful commands.

Many thanks in advance.

Regards,
Sahil
 
Old 03-02-2009, 12:24 PM   #2
john test
Member
 
Registered: Jul 2008
Distribution: ubuntu 9.10
Posts: 527
Blog Entries: 1

Rep: Reputation: 35
what is not working? If I cut the command string from your post and paste it into my command line and then substitute my user name for userrname1 and execute, it shows all my stuff and totals to 657 megabytes.
That seems to satisfy your criteria. What is it not doing properly?
 
Old 03-02-2009, 01:19 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,950
Blog Entries: 11

Rep: Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860
Code:
find -xdev -type f -user user1 -exec ls -l --full-time {} \;| awk '{print; total+=$5} END{printf "\ntotal bytes: %s\n ", total}'
 
Old 03-04-2009, 12:30 AM   #4
sahil.jammu
Member
 
Registered: Jun 2008
Distribution: Ubuntu
Posts: 83

Original Poster
Rep: Reputation: 15
Thanks John/Tinkster For the reply.

The Scenario is if i run the string posted by me at top level.....it scan the complete directory structure, which is perfect. and then it displays the size of all the underlying folders.
If the directory belong to the particular user then its fine. But if its a shared access then its a case of conflict where significant results doesnt come.What i am interested in is - I only want details of all the files owned by User1 along with their sizes not of others.

--------------------------------
The command i got from Tinkster is :-

find -xdev -type f -user user1 -exec ls -l --full-time {} \;| awk '{print; total+=$5} END{printf "\ntotal bytes: %s\n ", total}'

almost served the purpose, just that it will be really nice if i get the size in GB's or Mb's . Some kind of conversion that can happen at the end of the string will be perfect.

-----------
total bytes: 1.62027e+10

real 40m54.802s
user 0m13.599s
sys 1m34.448s


----------

Can you please suggest some further action where we can convert this bytes result into GB's or MB's.

Many thanks for the reply.!!
 
Old 03-04-2009, 12:48 AM   #5
win32sux
Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 371Reputation: 371Reputation: 371Reputation: 371
I haven't tried the command but if "total" is in bytes then "total/1024" would give you KB, "total/1048576" would give you MB, etc.

Last edited by win32sux; 03-04-2009 at 12:50 AM.
 
Old 03-04-2009, 01:14 AM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,950
Blog Entries: 11

Rep: Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860
heh ... tutoring maths, eh? ;}
 
Old 03-04-2009, 02:32 AM   #7
sahil.jammu
Member
 
Registered: Jun 2008
Distribution: Ubuntu
Posts: 83

Original Poster
Rep: Reputation: 15
Hi Tinkster,

It would be really useful if u can explain this command also though i got the solution , still some explanation about this command will be really useful like -
Some info about parameters used -
$5 ??
full time

Also how shall i go about converting results from bytes to GB's.

Thnx..

Regards,
Sahil
 
Old 03-04-2009, 02:35 AM   #8
win32sux
Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 371Reputation: 371Reputation: 371Reputation: 371
Quote:
Originally Posted by sahil.jammu View Post
Also how shall i go about converting results from bytes to GB's.
Did you not read my post about this? Just multiply the denominator by 1024 until you get where you want.

1024 bytes is a KB, 1024^2 bytes is a MB, 1024^3 bytes is a GB, 1024^4 bytes is a TB, etc, etc, etc.

Last edited by win32sux; 03-04-2009 at 02:45 AM.
 
Old 03-04-2009, 02:59 AM   #9
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
There is a -ls action for the find command which gives the size of files in 1024 byte blocks (unless POSIXLY_CORRECT is set). This could make it easier to calculate totals if the units are the same.

Last edited by jschiwal; 03-04-2009 at 03:01 AM.
 
Old 03-04-2009, 03:05 AM   #10
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,950
Blog Entries: 11

Rep: Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860
Quote:
Originally Posted by sahil.jammu View Post

Some info about parameters used -
$5 ??
$5 is the fifth field in the output of ls (from awks
perspective - awk [by default, can easily be changed]
uses whitespace of any sort as delimiter). The fifth
column in ls' output is file size.



Quote:
Originally Posted by sahil.jammu View Post

--full time
A habit of mine to keep ls' output consistent. If you have
"recent" and "old" files in a file-system ls will use
different output formats by default ... depending on your
locale, of course; but it's not uncommon to get 3 columns
for date for recent (< 6 months old) and 2 for older,
either way it often screws up the column ordering ...
forcing long-iso always gives me a) properly sortable
dates and b) a fixed number of columns (up to the file
names, which on my systems won't contain spaces).



Quote:
Originally Posted by sahil.jammu View Post
Also how shall i go about converting results from bytes to GB's.

Thnx..

Regards,
Sahil
Goodness ... /1024 and so forth ... ?



Cheers,
Tink

Last edited by Tinkster; 03-04-2009 at 03:06 AM.
 
Old 03-04-2009, 03:50 AM   #11
sahil.jammu
Member
 
Registered: Jun 2008
Distribution: Ubuntu
Posts: 83

Original Poster
Rep: Reputation: 15
Thanks Tink,

That was useful..

I am familiar with the conversions of Kb,Mb,Gb's . the reason that i asked again was , i was getting this kindaa output :-
--------
total bytes:9.05991e-05

real 1m33.698s
user 0m9.849s
sys 0m34.890s
--------

Can u provide complete command again which is working for u and giving results in Mb's or Gb's ...!!

Thnx!!
 
Old 03-04-2009, 03:57 AM   #12
sahil.jammu
Member
 
Registered: Jun 2008
Distribution: Ubuntu
Posts: 83

Original Poster
Rep: Reputation: 15
and if i use -ls option with find command as suggested by jschiwal , this give better results with size of each file. but for total result nothing is coming....!!

Command :-

--------------
time find -xdev -ls -type f -user `whoami` -exec ls -lrt --full-time {} \;| awk '{print; total=+$5} END{printf "\ntotal bytes:%s\n ", total}'
--------------

Output :-

--------------
total bytes:0

real 3m46.098s
user 0m12.158s
sys 0m39.382s

--------------

Thnx!!
 
Old 03-04-2009, 09:48 AM   #13
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,950
Blog Entries: 11

Rep: Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860
Quote:
Originally Posted by sahil.jammu View Post
and if i use -ls option with find command as suggested by jschiwal , this give better results with size of each file. but for total result nothing is coming....!!

Command :-

--------------
time find -xdev -ls -type f -user `whoami` -exec ls -lrt --full-time {} \;| awk '{print; total=+$5} END{printf "\ntotal bytes:%s\n ", total}'
--------------

Output :-

--------------
total bytes:0

real 3m46.098s
user 0m12.158s
sys 0m39.382s

--------------

Thnx!!
how exactly is the output with -ls on find "better"?
As far as I can see all it does is re-arrange the columns,
and print the size in blocks in K in the 2nd column ...
You still need to add the maths yourself considering
the total sizes you got.

And if you scroll up you'll find my explanation on
$5 and positions; apply that to your new command.
Count the columns.


Cheers,
Tink
 
Old 03-04-2009, 10:04 AM   #14
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,950
Blog Entries: 11

Rep: Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860
Quote:
Originally Posted by sahil.jammu View Post
Thanks Tink,

That was useful..

I am familiar with the conversions of Kb,Mb,Gb's . the reason that i asked again was , i was getting this kindaa output :-
--------
total bytes:9.05991e-05

real 1m33.698s
user 0m9.849s
sys 0m34.890s
--------

Can u provide complete command again which is working for u and giving results in Mb's or Gb's ...!!

Thnx!!
I guess I could; but my idea on what I'm doing here is
different from what you're apparently looking for. I'm not
part of a free body shop on the net - I'm here trying to
help other Linux enthusiasts to get going on their own.


Now, if you look at the "offending" line
Quote:
total bytes:9.05991e-05
and check where in my command it comes from, you'll notice
a variable name "total" ... what do you think needs to happen
to it to be given a result that is in a different unit?
Look at what win32sux said above ...



Cheers,
Tink
 
Old 03-04-2009, 11:35 AM   #15
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
Untested, but using -ls in find may be faster than an external command. Also, the format of the external ls command depends on $LS_OPTIONS, aliasing and sometimes the locale (for numbers). Another problem can turn up if in another part of the script, IFS is changed and ls is aliased. Aliased commands will fail if the space doesn't separate the command from the arguments. Using /bin/ls explicitly would prevent the last two potential problems.

If the username & filesizes are all that are used, then using -printf '%u %s\n' might be more straightforward.
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to find files containing specific text? SurfTurtle Linux - Newbie 7 01-05-2008 05:57 AM
How to find those files having specific string??? saeed Red Hat 4 07-19-2006 11:50 AM
all users have access to root owned files sakatola Linux - Security 2 07-22-2005 12:45 AM
how to find a specific file over several *.tgz files eeyoree Slackware 6 08-09-2004 12:37 AM
Find files, directories that are own by specific user mikeshn Linux - General 2 02-12-2004 03:52 PM


All times are GMT -5. The time now is 02:24 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration