Find out which users are hogging the most disk space on our data serverquotas not linked to users but to directoriesWhich installed software packages use the most disk space on Debian?How to find free disk space and analyze disk usage?How to find out what is wasting space on “/”?Which directory is taking up the most spacedu space more than the disk sizeFind out most frequent strings in section of fileFigure out the total disk space utilization per processFind out which process has data open on the hard drive that is no longer visible in the directory treeHow do I find what's hogging my storage space?Unable to find disk space usage

Short story about space worker geeks who zone out by 'listening' to radiation from stars

What is paid subscription needed for in Mortal Kombat 11?

System.debug(JSON.Serialize(o)) Not longer shows full string

How to run a prison with the smallest amount of guards?

Applicability of Single Responsibility Principle

How to draw lines on a tikz-cd diagram

Why are there no referendums in the US?

What is the intuitive meaning of having a linear relationship between the logs of two variables?

How to safely derail a train during transit?

How can a function with a hole (removable discontinuity) equal a function with no hole?

Fastening aluminum fascia to wooden subfascia

How can I kill an app using Terminal?

Did Dumbledore lie to Harry about how long he had James Potter's invisibility cloak when he was examining it? If so, why?

How to be diplomatic in refusing to write code that breaches the privacy of our users

How to Reset Passwords on Multiple Websites Easily?

Customer Requests (Sometimes) Drive Me Bonkers!

Why not increase contact surface when reentering the atmosphere?

Was Spock the First Vulcan in Starfleet?

A particular customize with green line and letters for subfloat

What is the best translation for "slot" in the context of multiplayer video games?

How to write papers efficiently when English isn't my first language?

Term for the "extreme-extension" version of a straw man fallacy?

Class Action - which options I have?

Avoiding estate tax by giving multiple gifts



Find out which users are hogging the most disk space on our data server


quotas not linked to users but to directoriesWhich installed software packages use the most disk space on Debian?How to find free disk space and analyze disk usage?How to find out what is wasting space on “/”?Which directory is taking up the most spacedu space more than the disk sizeFind out most frequent strings in section of fileFigure out the total disk space utilization per processFind out which process has data open on the hard drive that is no longer visible in the directory treeHow do I find what's hogging my storage space?Unable to find disk space usage













0















We are supposed to store our ongoing projects on a rather small (~4TB) data server. Not surprisingly, it is constantly overflowing and people need to move off less recent files manually.

Is there an easy (aka standard command-line) way to find out which users take up the most space in a directory? i.e. summing up the size of all files in a directory and all sub-directories belonging to each user?



Edit: ideally not following symlinks










share|improve this question









New contributor




MechEng is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 1





    Have you considered enabling disk quotas?

    – Kusalananda
    yesterday
















0















We are supposed to store our ongoing projects on a rather small (~4TB) data server. Not surprisingly, it is constantly overflowing and people need to move off less recent files manually.

Is there an easy (aka standard command-line) way to find out which users take up the most space in a directory? i.e. summing up the size of all files in a directory and all sub-directories belonging to each user?



Edit: ideally not following symlinks










share|improve this question









New contributor




MechEng is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 1





    Have you considered enabling disk quotas?

    – Kusalananda
    yesterday














0












0








0








We are supposed to store our ongoing projects on a rather small (~4TB) data server. Not surprisingly, it is constantly overflowing and people need to move off less recent files manually.

Is there an easy (aka standard command-line) way to find out which users take up the most space in a directory? i.e. summing up the size of all files in a directory and all sub-directories belonging to each user?



Edit: ideally not following symlinks










share|improve this question









New contributor




MechEng is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












We are supposed to store our ongoing projects on a rather small (~4TB) data server. Not surprisingly, it is constantly overflowing and people need to move off less recent files manually.

Is there an easy (aka standard command-line) way to find out which users take up the most space in a directory? i.e. summing up the size of all files in a directory and all sub-directories belonging to each user?



Edit: ideally not following symlinks







disk-usage sort storage






share|improve this question









New contributor




MechEng is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




MechEng is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited yesterday







MechEng













New contributor




MechEng is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked yesterday









MechEngMechEng

11




11




New contributor




MechEng is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





MechEng is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






MechEng is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







  • 1





    Have you considered enabling disk quotas?

    – Kusalananda
    yesterday













  • 1





    Have you considered enabling disk quotas?

    – Kusalananda
    yesterday








1




1





Have you considered enabling disk quotas?

– Kusalananda
yesterday






Have you considered enabling disk quotas?

– Kusalananda
yesterday











2 Answers
2






active

oldest

votes


















0














To find the disk usage by all users on the disk, you can use the following script:



#! /bin/bash

DIRECTORY_TO_SCAN=/home

readarray -t user_list<<<"$(cat /etc/passwd | cut -d ':' -f 1)"

for u in "$user_list[@]" ; do
printf "Scanning for user: %30s" "$u"
du -ch $(find "$DIRECTORY_TO_SCAN" -user "$u" 2>/dev/null) 2>/dev/null | sed -e '/total/!d;s/^/ /'
done


This script will scan the list of all users, find the files you can read and they own and compute the total space those files use.




(The part below is kept for the sake of completeness)



If you want to know the full size of a directory, you can use the du command:



du -sh directory1 directory2


will print the size of the directory and all its contents.



To actually solve your problem, you could use user (or group) quotas. This would allow you to get a detailled report of how much space each user/group is taking and set hard limits about how much space they may use.






share|improve this answer










New contributor




Simon Doppler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • I can't actually solve the problem since I am not the admin. What usually happens is: I realise that the storage is full again and have to ask around who could free up some space. The response I usually get is: "I barely use any space on the server, so I can't". The directory tree is not branched by users, but by projects since more than one person is working on the same project.

    – MechEng
    yesterday












  • The problem with the non-admin approach is that if the permissions on a directory are set that you cannot read it/list its contents, you cannot know what is in there and cannot find the space it uses. If it is such a problem, I think the server admin should do something (like group quotas and set one group per project or set up directory quotas).

    – Simon Doppler
    yesterday











  • The solution only working for dirs that I have permission to read would be fine. I agree that it should be the responsibility of the admin... but can we for now just pretend that this is not an option and I would like an answer to the initial question.

    – MechEng
    yesterday











  • @MechEng I updated my answer with a script that does what you want

    – Simon Doppler
    yesterday


















0














In situations like this, I usually first use du -kx | sort -rn | less to list the directories in a largest-first order. That tells me where the biggest individual disk hogs are, so I'll know where to look. But as @SimonDoppler said, if you don't have at least r-x access to all the sub-directories, your listing will be incomplete: you'll only be able to get the sizes of directories you'll be able to access.



Remember: normally you only need to have write access to a directory to delete any files in it. Only if the directory has the sticky bit set (i.e. the last letter in the permission letter string is a t instead of x), you need be the owner of the file in order to delete it.



If there is no quota available, you may need to do something like this:



#!/bin/sh
if [ "$1" = "" ] || [ "$1" = "-h" ]
then
echo "Usage: $0##*/ <directory> <username(s)...>" >&2
exit 64 # EX_USAGE
fi
if ! [ -d "$1" ]
then
echo "ERROR: directory $1 does not exist" >&2
exit 66 # EX_NOINPUT
fi

REPORTROOT="$1"
shift
for U in "$@"
do
# Find all files under $REPORTROOT owned by a particular user,
# get their sizes and sum them together.
DISKUSE=$(find "$REPORTROOT" -type f -user "$U"
-exec stat -c %s + 2>/dev/null
| awk 's+=$1 END printf("%ldn", s)')
# Display the result for this user.
printf "%16s: %dn" "$U" "$DISKUSE"
done


Note that running this may take a while.



The "calculate a sum of a list of numbers" awk one-liner is from this Stack Overflow post. Note the comments of the answer.






share|improve this answer






















    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );






    MechEng is a new contributor. Be nice, and check out our Code of Conduct.









    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f508673%2ffind-out-which-users-are-hogging-the-most-disk-space-on-our-data-server%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    To find the disk usage by all users on the disk, you can use the following script:



    #! /bin/bash

    DIRECTORY_TO_SCAN=/home

    readarray -t user_list<<<"$(cat /etc/passwd | cut -d ':' -f 1)"

    for u in "$user_list[@]" ; do
    printf "Scanning for user: %30s" "$u"
    du -ch $(find "$DIRECTORY_TO_SCAN" -user "$u" 2>/dev/null) 2>/dev/null | sed -e '/total/!d;s/^/ /'
    done


    This script will scan the list of all users, find the files you can read and they own and compute the total space those files use.




    (The part below is kept for the sake of completeness)



    If you want to know the full size of a directory, you can use the du command:



    du -sh directory1 directory2


    will print the size of the directory and all its contents.



    To actually solve your problem, you could use user (or group) quotas. This would allow you to get a detailled report of how much space each user/group is taking and set hard limits about how much space they may use.






    share|improve this answer










    New contributor




    Simon Doppler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.




















    • I can't actually solve the problem since I am not the admin. What usually happens is: I realise that the storage is full again and have to ask around who could free up some space. The response I usually get is: "I barely use any space on the server, so I can't". The directory tree is not branched by users, but by projects since more than one person is working on the same project.

      – MechEng
      yesterday












    • The problem with the non-admin approach is that if the permissions on a directory are set that you cannot read it/list its contents, you cannot know what is in there and cannot find the space it uses. If it is such a problem, I think the server admin should do something (like group quotas and set one group per project or set up directory quotas).

      – Simon Doppler
      yesterday











    • The solution only working for dirs that I have permission to read would be fine. I agree that it should be the responsibility of the admin... but can we for now just pretend that this is not an option and I would like an answer to the initial question.

      – MechEng
      yesterday











    • @MechEng I updated my answer with a script that does what you want

      – Simon Doppler
      yesterday















    0














    To find the disk usage by all users on the disk, you can use the following script:



    #! /bin/bash

    DIRECTORY_TO_SCAN=/home

    readarray -t user_list<<<"$(cat /etc/passwd | cut -d ':' -f 1)"

    for u in "$user_list[@]" ; do
    printf "Scanning for user: %30s" "$u"
    du -ch $(find "$DIRECTORY_TO_SCAN" -user "$u" 2>/dev/null) 2>/dev/null | sed -e '/total/!d;s/^/ /'
    done


    This script will scan the list of all users, find the files you can read and they own and compute the total space those files use.




    (The part below is kept for the sake of completeness)



    If you want to know the full size of a directory, you can use the du command:



    du -sh directory1 directory2


    will print the size of the directory and all its contents.



    To actually solve your problem, you could use user (or group) quotas. This would allow you to get a detailled report of how much space each user/group is taking and set hard limits about how much space they may use.






    share|improve this answer










    New contributor




    Simon Doppler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.




















    • I can't actually solve the problem since I am not the admin. What usually happens is: I realise that the storage is full again and have to ask around who could free up some space. The response I usually get is: "I barely use any space on the server, so I can't". The directory tree is not branched by users, but by projects since more than one person is working on the same project.

      – MechEng
      yesterday












    • The problem with the non-admin approach is that if the permissions on a directory are set that you cannot read it/list its contents, you cannot know what is in there and cannot find the space it uses. If it is such a problem, I think the server admin should do something (like group quotas and set one group per project or set up directory quotas).

      – Simon Doppler
      yesterday











    • The solution only working for dirs that I have permission to read would be fine. I agree that it should be the responsibility of the admin... but can we for now just pretend that this is not an option and I would like an answer to the initial question.

      – MechEng
      yesterday











    • @MechEng I updated my answer with a script that does what you want

      – Simon Doppler
      yesterday













    0












    0








    0







    To find the disk usage by all users on the disk, you can use the following script:



    #! /bin/bash

    DIRECTORY_TO_SCAN=/home

    readarray -t user_list<<<"$(cat /etc/passwd | cut -d ':' -f 1)"

    for u in "$user_list[@]" ; do
    printf "Scanning for user: %30s" "$u"
    du -ch $(find "$DIRECTORY_TO_SCAN" -user "$u" 2>/dev/null) 2>/dev/null | sed -e '/total/!d;s/^/ /'
    done


    This script will scan the list of all users, find the files you can read and they own and compute the total space those files use.




    (The part below is kept for the sake of completeness)



    If you want to know the full size of a directory, you can use the du command:



    du -sh directory1 directory2


    will print the size of the directory and all its contents.



    To actually solve your problem, you could use user (or group) quotas. This would allow you to get a detailled report of how much space each user/group is taking and set hard limits about how much space they may use.






    share|improve this answer










    New contributor




    Simon Doppler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.










    To find the disk usage by all users on the disk, you can use the following script:



    #! /bin/bash

    DIRECTORY_TO_SCAN=/home

    readarray -t user_list<<<"$(cat /etc/passwd | cut -d ':' -f 1)"

    for u in "$user_list[@]" ; do
    printf "Scanning for user: %30s" "$u"
    du -ch $(find "$DIRECTORY_TO_SCAN" -user "$u" 2>/dev/null) 2>/dev/null | sed -e '/total/!d;s/^/ /'
    done


    This script will scan the list of all users, find the files you can read and they own and compute the total space those files use.




    (The part below is kept for the sake of completeness)



    If you want to know the full size of a directory, you can use the du command:



    du -sh directory1 directory2


    will print the size of the directory and all its contents.



    To actually solve your problem, you could use user (or group) quotas. This would allow you to get a detailled report of how much space each user/group is taking and set hard limits about how much space they may use.







    share|improve this answer










    New contributor




    Simon Doppler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.









    share|improve this answer



    share|improve this answer








    edited yesterday





















    New contributor




    Simon Doppler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.









    answered yesterday









    Simon DopplerSimon Doppler

    1063




    1063




    New contributor




    Simon Doppler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





    New contributor





    Simon Doppler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






    Simon Doppler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.












    • I can't actually solve the problem since I am not the admin. What usually happens is: I realise that the storage is full again and have to ask around who could free up some space. The response I usually get is: "I barely use any space on the server, so I can't". The directory tree is not branched by users, but by projects since more than one person is working on the same project.

      – MechEng
      yesterday












    • The problem with the non-admin approach is that if the permissions on a directory are set that you cannot read it/list its contents, you cannot know what is in there and cannot find the space it uses. If it is such a problem, I think the server admin should do something (like group quotas and set one group per project or set up directory quotas).

      – Simon Doppler
      yesterday











    • The solution only working for dirs that I have permission to read would be fine. I agree that it should be the responsibility of the admin... but can we for now just pretend that this is not an option and I would like an answer to the initial question.

      – MechEng
      yesterday











    • @MechEng I updated my answer with a script that does what you want

      – Simon Doppler
      yesterday

















    • I can't actually solve the problem since I am not the admin. What usually happens is: I realise that the storage is full again and have to ask around who could free up some space. The response I usually get is: "I barely use any space on the server, so I can't". The directory tree is not branched by users, but by projects since more than one person is working on the same project.

      – MechEng
      yesterday












    • The problem with the non-admin approach is that if the permissions on a directory are set that you cannot read it/list its contents, you cannot know what is in there and cannot find the space it uses. If it is such a problem, I think the server admin should do something (like group quotas and set one group per project or set up directory quotas).

      – Simon Doppler
      yesterday











    • The solution only working for dirs that I have permission to read would be fine. I agree that it should be the responsibility of the admin... but can we for now just pretend that this is not an option and I would like an answer to the initial question.

      – MechEng
      yesterday











    • @MechEng I updated my answer with a script that does what you want

      – Simon Doppler
      yesterday
















    I can't actually solve the problem since I am not the admin. What usually happens is: I realise that the storage is full again and have to ask around who could free up some space. The response I usually get is: "I barely use any space on the server, so I can't". The directory tree is not branched by users, but by projects since more than one person is working on the same project.

    – MechEng
    yesterday






    I can't actually solve the problem since I am not the admin. What usually happens is: I realise that the storage is full again and have to ask around who could free up some space. The response I usually get is: "I barely use any space on the server, so I can't". The directory tree is not branched by users, but by projects since more than one person is working on the same project.

    – MechEng
    yesterday














    The problem with the non-admin approach is that if the permissions on a directory are set that you cannot read it/list its contents, you cannot know what is in there and cannot find the space it uses. If it is such a problem, I think the server admin should do something (like group quotas and set one group per project or set up directory quotas).

    – Simon Doppler
    yesterday





    The problem with the non-admin approach is that if the permissions on a directory are set that you cannot read it/list its contents, you cannot know what is in there and cannot find the space it uses. If it is such a problem, I think the server admin should do something (like group quotas and set one group per project or set up directory quotas).

    – Simon Doppler
    yesterday













    The solution only working for dirs that I have permission to read would be fine. I agree that it should be the responsibility of the admin... but can we for now just pretend that this is not an option and I would like an answer to the initial question.

    – MechEng
    yesterday





    The solution only working for dirs that I have permission to read would be fine. I agree that it should be the responsibility of the admin... but can we for now just pretend that this is not an option and I would like an answer to the initial question.

    – MechEng
    yesterday













    @MechEng I updated my answer with a script that does what you want

    – Simon Doppler
    yesterday





    @MechEng I updated my answer with a script that does what you want

    – Simon Doppler
    yesterday













    0














    In situations like this, I usually first use du -kx | sort -rn | less to list the directories in a largest-first order. That tells me where the biggest individual disk hogs are, so I'll know where to look. But as @SimonDoppler said, if you don't have at least r-x access to all the sub-directories, your listing will be incomplete: you'll only be able to get the sizes of directories you'll be able to access.



    Remember: normally you only need to have write access to a directory to delete any files in it. Only if the directory has the sticky bit set (i.e. the last letter in the permission letter string is a t instead of x), you need be the owner of the file in order to delete it.



    If there is no quota available, you may need to do something like this:



    #!/bin/sh
    if [ "$1" = "" ] || [ "$1" = "-h" ]
    then
    echo "Usage: $0##*/ <directory> <username(s)...>" >&2
    exit 64 # EX_USAGE
    fi
    if ! [ -d "$1" ]
    then
    echo "ERROR: directory $1 does not exist" >&2
    exit 66 # EX_NOINPUT
    fi

    REPORTROOT="$1"
    shift
    for U in "$@"
    do
    # Find all files under $REPORTROOT owned by a particular user,
    # get their sizes and sum them together.
    DISKUSE=$(find "$REPORTROOT" -type f -user "$U"
    -exec stat -c %s + 2>/dev/null
    | awk 's+=$1 END printf("%ldn", s)')
    # Display the result for this user.
    printf "%16s: %dn" "$U" "$DISKUSE"
    done


    Note that running this may take a while.



    The "calculate a sum of a list of numbers" awk one-liner is from this Stack Overflow post. Note the comments of the answer.






    share|improve this answer



























      0














      In situations like this, I usually first use du -kx | sort -rn | less to list the directories in a largest-first order. That tells me where the biggest individual disk hogs are, so I'll know where to look. But as @SimonDoppler said, if you don't have at least r-x access to all the sub-directories, your listing will be incomplete: you'll only be able to get the sizes of directories you'll be able to access.



      Remember: normally you only need to have write access to a directory to delete any files in it. Only if the directory has the sticky bit set (i.e. the last letter in the permission letter string is a t instead of x), you need be the owner of the file in order to delete it.



      If there is no quota available, you may need to do something like this:



      #!/bin/sh
      if [ "$1" = "" ] || [ "$1" = "-h" ]
      then
      echo "Usage: $0##*/ <directory> <username(s)...>" >&2
      exit 64 # EX_USAGE
      fi
      if ! [ -d "$1" ]
      then
      echo "ERROR: directory $1 does not exist" >&2
      exit 66 # EX_NOINPUT
      fi

      REPORTROOT="$1"
      shift
      for U in "$@"
      do
      # Find all files under $REPORTROOT owned by a particular user,
      # get their sizes and sum them together.
      DISKUSE=$(find "$REPORTROOT" -type f -user "$U"
      -exec stat -c %s + 2>/dev/null
      | awk 's+=$1 END printf("%ldn", s)')
      # Display the result for this user.
      printf "%16s: %dn" "$U" "$DISKUSE"
      done


      Note that running this may take a while.



      The "calculate a sum of a list of numbers" awk one-liner is from this Stack Overflow post. Note the comments of the answer.






      share|improve this answer

























        0












        0








        0







        In situations like this, I usually first use du -kx | sort -rn | less to list the directories in a largest-first order. That tells me where the biggest individual disk hogs are, so I'll know where to look. But as @SimonDoppler said, if you don't have at least r-x access to all the sub-directories, your listing will be incomplete: you'll only be able to get the sizes of directories you'll be able to access.



        Remember: normally you only need to have write access to a directory to delete any files in it. Only if the directory has the sticky bit set (i.e. the last letter in the permission letter string is a t instead of x), you need be the owner of the file in order to delete it.



        If there is no quota available, you may need to do something like this:



        #!/bin/sh
        if [ "$1" = "" ] || [ "$1" = "-h" ]
        then
        echo "Usage: $0##*/ <directory> <username(s)...>" >&2
        exit 64 # EX_USAGE
        fi
        if ! [ -d "$1" ]
        then
        echo "ERROR: directory $1 does not exist" >&2
        exit 66 # EX_NOINPUT
        fi

        REPORTROOT="$1"
        shift
        for U in "$@"
        do
        # Find all files under $REPORTROOT owned by a particular user,
        # get their sizes and sum them together.
        DISKUSE=$(find "$REPORTROOT" -type f -user "$U"
        -exec stat -c %s + 2>/dev/null
        | awk 's+=$1 END printf("%ldn", s)')
        # Display the result for this user.
        printf "%16s: %dn" "$U" "$DISKUSE"
        done


        Note that running this may take a while.



        The "calculate a sum of a list of numbers" awk one-liner is from this Stack Overflow post. Note the comments of the answer.






        share|improve this answer













        In situations like this, I usually first use du -kx | sort -rn | less to list the directories in a largest-first order. That tells me where the biggest individual disk hogs are, so I'll know where to look. But as @SimonDoppler said, if you don't have at least r-x access to all the sub-directories, your listing will be incomplete: you'll only be able to get the sizes of directories you'll be able to access.



        Remember: normally you only need to have write access to a directory to delete any files in it. Only if the directory has the sticky bit set (i.e. the last letter in the permission letter string is a t instead of x), you need be the owner of the file in order to delete it.



        If there is no quota available, you may need to do something like this:



        #!/bin/sh
        if [ "$1" = "" ] || [ "$1" = "-h" ]
        then
        echo "Usage: $0##*/ <directory> <username(s)...>" >&2
        exit 64 # EX_USAGE
        fi
        if ! [ -d "$1" ]
        then
        echo "ERROR: directory $1 does not exist" >&2
        exit 66 # EX_NOINPUT
        fi

        REPORTROOT="$1"
        shift
        for U in "$@"
        do
        # Find all files under $REPORTROOT owned by a particular user,
        # get their sizes and sum them together.
        DISKUSE=$(find "$REPORTROOT" -type f -user "$U"
        -exec stat -c %s + 2>/dev/null
        | awk 's+=$1 END printf("%ldn", s)')
        # Display the result for this user.
        printf "%16s: %dn" "$U" "$DISKUSE"
        done


        Note that running this may take a while.



        The "calculate a sum of a list of numbers" awk one-liner is from this Stack Overflow post. Note the comments of the answer.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered yesterday









        telcoMtelcoM

        20.1k12450




        20.1k12450




















            MechEng is a new contributor. Be nice, and check out our Code of Conduct.









            draft saved

            draft discarded


















            MechEng is a new contributor. Be nice, and check out our Code of Conduct.












            MechEng is a new contributor. Be nice, and check out our Code of Conduct.











            MechEng is a new contributor. Be nice, and check out our Code of Conduct.














            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f508673%2ffind-out-which-users-are-hogging-the-most-disk-space-on-our-data-server%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown