Number of home directories in children of /

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I have to count the number of children directories of / that contain one or more home directories.
For instance, if john, emily and rick have their home directories in /home/john , /home/emily and /var/lib, the answer would be 2.



I assume I have to use a pipe with cut and grep, but I do not know exactly how.










share|improve this question







New contributor




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



















  • I don't understand how /var/lib is different from /home/john or /home/emily in this regard. None of them are direct children of /; two of them contain /home, if that's what you're checking...?
    – Jeff Schaller
    40 mins ago










  • Is the algorithm that "/home" contains two homedirs and /var contains one, so there are two unique top-level directories that contain home directories?
    – Jeff Schaller
    39 mins ago










  • Are the paths to test predetermined or are you reading them from the /etc/passwd file? And would 3 the answer to this list: /home/john , /home/emily , /varlib , /home/sally/Documents/Earth , /var/www ?
    – RubberStamp
    29 mins ago






  • 1




    You only need to find out where the home directory is set which you can get from getent passwd | awk - F : 'print $6'. It is most likely /home for everyone unless it's been set as a different location for some of the users. Assuming that it is, you can use find /home -maxdepth 1 -type d | awk 'END print $NR' and that will give you the total number. You can swap out /home if it's elsewhere.
    – Nasir Riley
    28 mins ago















up vote
0
down vote

favorite












I have to count the number of children directories of / that contain one or more home directories.
For instance, if john, emily and rick have their home directories in /home/john , /home/emily and /var/lib, the answer would be 2.



I assume I have to use a pipe with cut and grep, but I do not know exactly how.










share|improve this question







New contributor




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



















  • I don't understand how /var/lib is different from /home/john or /home/emily in this regard. None of them are direct children of /; two of them contain /home, if that's what you're checking...?
    – Jeff Schaller
    40 mins ago










  • Is the algorithm that "/home" contains two homedirs and /var contains one, so there are two unique top-level directories that contain home directories?
    – Jeff Schaller
    39 mins ago










  • Are the paths to test predetermined or are you reading them from the /etc/passwd file? And would 3 the answer to this list: /home/john , /home/emily , /varlib , /home/sally/Documents/Earth , /var/www ?
    – RubberStamp
    29 mins ago






  • 1




    You only need to find out where the home directory is set which you can get from getent passwd | awk - F : 'print $6'. It is most likely /home for everyone unless it's been set as a different location for some of the users. Assuming that it is, you can use find /home -maxdepth 1 -type d | awk 'END print $NR' and that will give you the total number. You can swap out /home if it's elsewhere.
    – Nasir Riley
    28 mins ago













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have to count the number of children directories of / that contain one or more home directories.
For instance, if john, emily and rick have their home directories in /home/john , /home/emily and /var/lib, the answer would be 2.



I assume I have to use a pipe with cut and grep, but I do not know exactly how.










share|improve this question







New contributor




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











I have to count the number of children directories of / that contain one or more home directories.
For instance, if john, emily and rick have their home directories in /home/john , /home/emily and /var/lib, the answer would be 2.



I assume I have to use a pipe with cut and grep, but I do not know exactly how.







grep directory pipe home






share|improve this question







New contributor




Teodora Argintaru 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




Teodora Argintaru 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






New contributor




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









asked 43 mins ago









Teodora Argintaru

1




1




New contributor




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





New contributor





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






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











  • I don't understand how /var/lib is different from /home/john or /home/emily in this regard. None of them are direct children of /; two of them contain /home, if that's what you're checking...?
    – Jeff Schaller
    40 mins ago










  • Is the algorithm that "/home" contains two homedirs and /var contains one, so there are two unique top-level directories that contain home directories?
    – Jeff Schaller
    39 mins ago










  • Are the paths to test predetermined or are you reading them from the /etc/passwd file? And would 3 the answer to this list: /home/john , /home/emily , /varlib , /home/sally/Documents/Earth , /var/www ?
    – RubberStamp
    29 mins ago






  • 1




    You only need to find out where the home directory is set which you can get from getent passwd | awk - F : 'print $6'. It is most likely /home for everyone unless it's been set as a different location for some of the users. Assuming that it is, you can use find /home -maxdepth 1 -type d | awk 'END print $NR' and that will give you the total number. You can swap out /home if it's elsewhere.
    – Nasir Riley
    28 mins ago

















  • I don't understand how /var/lib is different from /home/john or /home/emily in this regard. None of them are direct children of /; two of them contain /home, if that's what you're checking...?
    – Jeff Schaller
    40 mins ago










  • Is the algorithm that "/home" contains two homedirs and /var contains one, so there are two unique top-level directories that contain home directories?
    – Jeff Schaller
    39 mins ago










  • Are the paths to test predetermined or are you reading them from the /etc/passwd file? And would 3 the answer to this list: /home/john , /home/emily , /varlib , /home/sally/Documents/Earth , /var/www ?
    – RubberStamp
    29 mins ago






  • 1




    You only need to find out where the home directory is set which you can get from getent passwd | awk - F : 'print $6'. It is most likely /home for everyone unless it's been set as a different location for some of the users. Assuming that it is, you can use find /home -maxdepth 1 -type d | awk 'END print $NR' and that will give you the total number. You can swap out /home if it's elsewhere.
    – Nasir Riley
    28 mins ago
















I don't understand how /var/lib is different from /home/john or /home/emily in this regard. None of them are direct children of /; two of them contain /home, if that's what you're checking...?
– Jeff Schaller
40 mins ago




I don't understand how /var/lib is different from /home/john or /home/emily in this regard. None of them are direct children of /; two of them contain /home, if that's what you're checking...?
– Jeff Schaller
40 mins ago












Is the algorithm that "/home" contains two homedirs and /var contains one, so there are two unique top-level directories that contain home directories?
– Jeff Schaller
39 mins ago




Is the algorithm that "/home" contains two homedirs and /var contains one, so there are two unique top-level directories that contain home directories?
– Jeff Schaller
39 mins ago












Are the paths to test predetermined or are you reading them from the /etc/passwd file? And would 3 the answer to this list: /home/john , /home/emily , /varlib , /home/sally/Documents/Earth , /var/www ?
– RubberStamp
29 mins ago




Are the paths to test predetermined or are you reading them from the /etc/passwd file? And would 3 the answer to this list: /home/john , /home/emily , /varlib , /home/sally/Documents/Earth , /var/www ?
– RubberStamp
29 mins ago




1




1




You only need to find out where the home directory is set which you can get from getent passwd | awk - F : 'print $6'. It is most likely /home for everyone unless it's been set as a different location for some of the users. Assuming that it is, you can use find /home -maxdepth 1 -type d | awk 'END print $NR' and that will give you the total number. You can swap out /home if it's elsewhere.
– Nasir Riley
28 mins ago





You only need to find out where the home directory is set which you can get from getent passwd | awk - F : 'print $6'. It is most likely /home for everyone unless it's been set as a different location for some of the users. Assuming that it is, you can use find /home -maxdepth 1 -type d | awk 'END print $NR' and that will give you the total number. You can swap out /home if it's elsewhere.
– Nasir Riley
28 mins ago











1 Answer
1






active

oldest

votes

















up vote
0
down vote













(export LC_ALL=C
getent passwd | cut -d: -f6 | sort -t/ -uk2,2 | grep -c ..)


Counts the number of unique second components of user's home directories.






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',
    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
    );



    );






    Teodora Argintaru 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%2f480447%2fnumber-of-home-directories-in-children-of%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    (export LC_ALL=C
    getent passwd | cut -d: -f6 | sort -t/ -uk2,2 | grep -c ..)


    Counts the number of unique second components of user's home directories.






    share|improve this answer
























      up vote
      0
      down vote













      (export LC_ALL=C
      getent passwd | cut -d: -f6 | sort -t/ -uk2,2 | grep -c ..)


      Counts the number of unique second components of user's home directories.






      share|improve this answer






















        up vote
        0
        down vote










        up vote
        0
        down vote









        (export LC_ALL=C
        getent passwd | cut -d: -f6 | sort -t/ -uk2,2 | grep -c ..)


        Counts the number of unique second components of user's home directories.






        share|improve this answer












        (export LC_ALL=C
        getent passwd | cut -d: -f6 | sort -t/ -uk2,2 | grep -c ..)


        Counts the number of unique second components of user's home directories.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 27 mins ago









        Stéphane Chazelas

        292k54543883




        292k54543883




















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









             

            draft saved


            draft discarded


















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












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











            Teodora Argintaru 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%2f480447%2fnumber-of-home-directories-in-children-of%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay