Linux Bash: to find the biggest folder in a directory.

Linux Bash: to find the biggest folder in a directory.

In order to find the biggest folder in a directory.

You need the

find command and xargs

The output:

find . -type d -iname „Linu*“ -print0 | xargs -0 ls -ldhS
drwxr-xr-x. 1 sven sven 490 19. Mai 15:07 ./Videos/eigene_Aufnahmen/Linux
drwxr-xr-x. 1 sven sven 348 6. Jul 21:06 ./Linux_PC
drwxr-xr-x. 1 sven sven 194 4. Sep 2024 ./.local/lib/python3.12/site-packages/debugpy/_vendored/pydevd/pydevd_attach_to_process/linux_and_mac
drwxr-xr-x. 1 sven sven 194 14. Mai 07:59 ./.local/lib/python3.13/site-packages/debugpy/_vendored/pydevd/pydevd_attach_to_process/linux_and_mac
drwxr-xr-x. 1 sven sven 172 9. Mai 07:26 ./.vscode/extensions/ms-python.debugpy-2025.8.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/pydevd_attach_to_process/linux_and_mac
drwx——. 1 sven sven 34 16. Mär 08:42 ./.config/chromium/WidevineCdm/4.10.2891.0/_platform_specific/linux_x64
drwxr-xr-x. 1 sven sven 32 6. Jul 16:43 ./.local/lib/python3.13/site-packages/selenium/webdriver/common/linux
drwx——. 1 sven sven 24 20. Mai 06:15 ./.mozilla/firefox/gzwul6fj.default-release/gmp/Linux_x86_64-gcc3
drwx——. 1 sven sven 0 16. Mär 10:16 ./.mozilla/seamonkey/yb4j3vpb.default/gmp/Linux_x86_64-gcc3

. = in the same directory

-type d = only folders

– iname = case-insentive

-print0: This is a very important switch! It ensures that find separates the found file names with a null character (\0) instead of a line break. This is crucial if file names contain spaces or special characters, as xargs would otherwise interpret them incorrectly.

xargs -0: This command takes the zero-separated input from find (because of -0) and passes it as arguments to the following command

ls List information about the FILEs (the current directory by default).

-ldhS

-l: Long list (details such as authorizations, owner, size, date).

-d: Only displays the directory itself, not its contents.

-h: Displays the sizes in a human-readable format (e.g. K, M, G for kilobytes, megabytes, gigabytes)

-S: sorts the results by file size, in descending order (largest files/directories first)

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

error: Content is protected !!