[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Sorting directories by size
From: |
hancooper |
Subject: |
Sorting directories by size |
Date: |
Tue, 24 Aug 2021 13:12:41 +0000 |
-‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Tuesday, August 24, 2021 12:52 PM, Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com>
wrote:
> i guess you didnt set $dir
You are correct, it was not being set up properly, so added some checks.
> On Tue, Aug 24, 2021, 14:12 hancooper <hancooper@protonmail.com> wrote:
>
>> ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
>> On Tuesday, August 24, 2021 3:31 AM, Kerin Millar <kfm@plushkava.net> wrote:
>>
>>> On Tue, 24 Aug 2021 02:21:28 +0000
>>> hancooper via help-bash@gnu.org wrote:
>>>
>>> > I have a directory stored in `dir`. I want to store the names of
>>> > directories at a particular level
>>> > and sort them by size.
>>> > I have started with listing the directory names in `dlc` and computing
>>> > the total number of
>>> > directories present. But still have to sort `dlc` by size, the with the
>>> > biggest first.
>>> > My initial plan is to use a command such as `du -h | sort -h`.
>>> > daggr=( -mindepth "$depth" -maxdepth "$depth" )
>>> > dlc=$( find "$dir" "${daggr[@]}" -type d | tr "\n" " " )
>>> > ndr=$( echo "$dlc;" | grep -o " " | wc -l )
>>>
>>> The last two of these three commands should be jettisoned. Further, you
>>> ought to be using an array to store the directory names. As you appear to
>>> be using GNU, consider the following.
>>>
>>> daggr=(-mindepth "$depth" -maxdepth "$depth")
>>> mapfile -td '' dlc < <(find "$dir" "${daggr[@]}" -type d -exec du -0 {} + |
>>> sort -zrn | cut -z -f2-)
>>> ndr=${#dlc[@]}
>>>
>>> This relies on the fact that GNU du(1), given the -0 option, employs an
>>> output format of "%d\t%s\0", <size>, <pathname>.
>>>
>>> --
>>>
>>> Kerin Millar
>>
>> I agree with your assessment. Have seen that I get the following errer
>>
>> find: ‘’: No such file or directory
- Sorting directories by size, hancooper, 2021/08/23
- Re: Sorting directories by size, Kerin Millar, 2021/08/23
- Sorting directories by size, hancooper, 2021/08/24
- Re: Sorting directories by size, Alex fxmbsw7 Ratchev, 2021/08/24
- Sorting directories by size,
hancooper <=
- Sorting directories by size, hancooper, 2021/08/24
- Sorting directories by size, hancooper, 2021/08/24
- Re: Sorting directories by size, Dennis Williamson, 2021/08/24
- Re: Sorting directories by size, Kerin Millar, 2021/08/24
- Sorting directories by size, hancooper, 2021/08/24
- Sorting directories by size, hancooper, 2021/08/24
- Re: Sorting directories by size, Dennis Williamson, 2021/08/24
- Re: Sorting directories by size, Kerin Millar, 2021/08/24
- Sorting directories by size, hancooper, 2021/08/24
- Re: Sorting directories by size, Kerin Millar, 2021/08/24