Syntax:
# find <pathname> -user <username> -ls | awk '{sum += $8} END {printf "Total size: %8.4f MB\n", sum/1024/1024}'
Example:
[root@nasllm01-ih ~]# find /nasllm-ih -user rram -ls | awk '{sum += $8} END {printf "Total size: %8.4f MB\n", sum/1024/1024}'
Total size: 958.7282 MB
[root@nasllm01-ih ~]#
Validation:
Here I have created a folder /root/ashok consists files owned by user “adevaraju” of total size: 160 MB.
[root@oralsb11-new ~]# ls -lRh /root/ashok
/root/ashok:
total 21M
drwxr-xr-x 3 adevaraju root 4.0K Dec 14 06:30 d1
drwxr-xr-x 2 adevaraju root 4.0K Dec 14 06:35 d2
-rw-r--r-- 1 adevaraju root 10M Dec 14 06:21 file1
-rw-r--r-- 1 adevaraju root 10M Dec 14 06:22 file4
/root/ashok/d1:
total 21M
drwxr-xr-x 2 adevaraju root 4.0K Dec 14 06:35 dx
-rw-r--r-- 1 adevaraju root 10M Dec 14 06:22 file2
-rw-r--r-- 1 adevaraju root 10M Dec 14 06:22 file3
/root/ashok/d1/dx:
total 21M
-rw-r--r-- 1 adevaraju root 10M Dec 14 06:30 file5
-rw-r--r-- 1 adevaraju root 10M Dec 14 06:30 file6
/root/ashok/d2:
total 101M
-rw-r--r-- 1 adevaraju root 100M Dec 14 06:30 file7
[root@oralsb11-new ~]#
[root@oralsb11-new ~]# du -sh ashok/
161M ashok/
[root@oralsb11-new ~]# find /root/ashok -user adevaraju -ls | awk '{sum += $7} END {printf "SUM: %8.4f MB\n", sum/1024/1024}'
SUM: 160.0156 MB
[root@oralsb11-new ~]#
PS: Please note there is a difference in AWK statement. The Field separator value will be one count more for Domain users since it has an extra space in-between (domain users).
[root@oralsb11-new ~]# find /root/ashok -user adevaraju -ls
15073319 4 drwxr-xr-x 4 adevaraju root 4096 Dec 14 06:22 /root/ashok
15073320 4 drwxr-xr-x 3 adevaraju root 4096 Dec 14 06:30 /root/ashok/d1
15073323 10256 -rw-r--r-- 1 adevaraju root 10485760 Dec 14 06:22 /root/ashok/d1/file2
.
.
[root@oralsb11-new ~]# find /home/tcprod/adevaraju/ -user adevaraju -ls
9371731 4 drwxr-xr-x 4 adevaraju domain users 4096 Dec 13 12:21 /home/tcprod/adevaraju/
9371732 4 -rw-r--r-- 1 adevaraju domain users 33 Oct 14 09:09 /home/tcprod/adevaraju/.bash_logout
9372649 1420 -rw-r--r-- 1 adevaraju domain users 1446232 Dec 10 09:51 /home/tcprod/adevaraju/lshw-2.15-1.el5.rf.x86_64.rpm
.
.
No comments:
Post a Comment