LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Find the space for files owned by specific users (https://www.linuxquestions.org/questions/linux-newbie-8/find-the-space-for-files-owned-by-specific-users-708533/)

sahil.jammu 03-02-2009 03:49 AM

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

john test 03-02-2009 12:24 PM

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?

Tinkster 03-02-2009 01:19 PM

Code:

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

sahil.jammu 03-04-2009 12:30 AM

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.!!

win32sux 03-04-2009 12:48 AM

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.

Tinkster 03-04-2009 01:14 AM

heh ... tutoring maths, eh? ;}

sahil.jammu 03-04-2009 02:32 AM

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

win32sux 03-04-2009 02:35 AM

Quote:

Originally Posted by sahil.jammu (Post 3464272)
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.

jschiwal 03-04-2009 02:59 AM

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.

Tinkster 03-04-2009 03:05 AM

Quote:

Originally Posted by sahil.jammu (Post 3464272)

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 (Post 3464272)

--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 (Post 3464272)
Also how shall i go about converting results from bytes to GB's.

Thnx..

Regards,
Sahil

Goodness ... /1024 and so forth ... ?



Cheers,
Tink

sahil.jammu 03-04-2009 03:50 AM

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!!

sahil.jammu 03-04-2009 03:57 AM

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!!

Tinkster 03-04-2009 09:48 AM

Quote:

Originally Posted by sahil.jammu (Post 3464341)
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

Tinkster 03-04-2009 10:04 AM

Quote:

Originally Posted by sahil.jammu (Post 3464338)
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

jschiwal 03-04-2009 11:35 AM

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.


All times are GMT -5. The time now is 09:18 PM.