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 |
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? |
Code:
find -xdev -type f -user user1 -exec ls -l --full-time {} \;| awk '{print; total+=$5} END{printf "\ntotal bytes: %s\n ", total}' |
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.!! |
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.
|
heh ... tutoring maths, eh? ;}
|
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 |
Quote:
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. |
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.
|
Quote:
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:
"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:
Cheers, Tink |
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!! |
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!! |
Quote:
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 |
Quote:
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:
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 |
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. |