• Re: Folder size and number of files

    From G@21:1/5 to dieterhansbritz@gmail.com on Wed Sep 25 09:26:42 2024
    db <dieterhansbritz@gmail.com> wrote:
    I like typing in commands at the console. Is there
    a command that gives me the size of a given folder,
    and the number of files in it? I can do that with
    the GUI, right klick on the folder and Proprties,
    but would prefer to do it from a typed in command.

    Is there one?


    You can use "du" with some options for the size of folders, but the best prog is "ncdu" (probably you'll have to install it). It gives a list of dir with sizes and, with options "c", number of files and you can "walk" the tree with arrows.

    G

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to dieterhansbritz@gmail.com on Wed Sep 25 13:47:40 2024
    db <dieterhansbritz@gmail.com> wrote:
    I like typing in commands at the console. Is there
    a command that gives me the size of a given folder,
    and the number of files in it? I can do that with
    the GUI, right klick on the folder and Proprties,
    but would prefer to do it from a typed in command.

    Is there one?

    A single rollup command that does all this, no.

    You construct what you need by combining the primitives together to get
    what you are looking for.

    For size (if by 'size' you really mean the sum of the disk space
    consumed by the files inside the folder) then du with the --max-depth=
    (short form -d) option to prevent it from descending into sub-folders
    will give you the "disk used by all files inside".

    du --max-depth=1 folder/

    For count, there are several options. If all the filenames inside are
    sane (as in do not themselves contain newlines) then this will give you
    the count:

    ls folder/ | wc -l

    If your filenames contain newlines, well, you've got a lot more work
    ahead....

    If you really want a 'rollup' (because you use this often) you can
    create either a shell function or a shell script file somewhere on your
    path with a new name, i.e. size-count which does both of the above and
    then you can run:

    size-count folder/

    to get both the disk usage and files count.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Fritz Wuehler@21:1/5 to All on Wed Sep 25 22:44:01 2024
    db <dieterhansbr...@gmail.com> [d]:
    Is there a command that gives me the size of a given folder, and
    the number of files in it?

    No, but you can always define your own:


    dir_size_and_number_of_files(){
    # collect the output of du/find
    set $(
    du -sh "${1:-.}"; find "${1:-.}" -type f | wc -l
    )
    # and print it nicely
    echo -e "$2\t$1\t$3"
    }


    And then use it with or without a directory argument:


    dir_size_and_number_of_files /home/user123
    /home/user123 2.7M 263

    # when run with no arguments, it will check the current directory dir_size_and_number_of_files
    . 324k 19

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to All on Wed Sep 25 21:33:37 2024
    On Wed, 25 Sep 2024 08:14:51 -0000 (UTC), db wrote:

    Is there a command that gives me the size of a given folder ...

    du -s «folder»

    ... and the number of files in it?

    I currently use

    ls «folder» | wc -l

    ... not sure if there’s a more efficient way ...

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Fritz Wuehler on Wed Sep 25 21:34:21 2024
    On Wed, 25 Sep 2024 22:44:01 +0200, Fritz Wuehler wrote:

    ... find "${1:-.}" -type f | wc -l ...

    This counts the total number of files in all descendant subdirectories as
    well. Might or might not be what you want.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mike Scott@21:1/5 to Lawrence D'Oliveiro on Thu Sep 26 09:14:25 2024
    On 25/09/2024 22:33, Lawrence D'Oliveiro wrote:
    On Wed, 25 Sep 2024 08:14:51 -0000 (UTC), db wrote:

    Is there a command that gives me the size of a given folder ...

    du -s «folder»

    ... and the number of files in it?

    I currently use

    ls «folder» | wc -l

    ... not sure if there’s a more efficient way ...

    find ~ -ls | awk -v total=0 -v files=0 'END {print files, total} {total
    = total + $7; ++files}'

    maybe?

    --
    Mike Scott
    Harlow, England

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From G@21:1/5 to Lawrence D'Oliveiro on Thu Sep 26 08:56:09 2024
    Lawrence D'Oliveiro <ldo@nz.invalid> wrote:
    On Wed, 25 Sep 2024 08:14:51 -0000 (UTC), db wrote:

    Is there a command that gives me the size of a given folder ...

    du -s «folder»

    Use "du -sh" it's more readable.


    ... and the number of files in it?

    I currently use

    ls «folder» | wc -l

    ... not sure if there’s a more efficient way ...

    Yes, install "ncdu" it does both size and number of files (with option "--show-itemcount" or "c" when inside), and you can navigate the folder tree.

    G

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)