How to list directory sizes in /home/guest/

Technical issues/questions of an intermediate or advanced nature.
User avatar
Ed_P
Contributor
Contributor
Posts: 8374
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

How to list directory sizes in /home/guest/

Post#1 by Ed_P » 04 Dec 2023, 04:16

du -h lists the directories but includes all the hidden directories. I tried:

Code: Select all

du -h | grep -v "./."
but it excludes "./" directories also.

Code: Select all

guest@porteus:~$ du -h | grep -v "./."
419M	.
guest@porteus:~$ 
How do I list just the ./ directories? :%)

Code: Select all

349M	./.cache
36K	./Pictures/tmp
5.3M	./Pictures
0	./Music
220K	./Downloads/Ignispkg - Porteus Community_files
812K	./Downloads/Ignisgrub2
1.1M	./Downloads
0	./Documents
24K	./Desktop
Ed

User avatar
Rava
Contributor
Contributor
Posts: 5416
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

How to list directory sizes in /home/guest/

Post#2 by Rava » 04 Dec 2023, 06:01

Try

Code: Select all

du -h .??*/ */
or in case one of the two possibilities given doesn't exist, use

Code: Select all

du -h .??*/ */ 2>/dev/null
to suppress the error message.
.??*/ lists all hidden folders that have at least 2 characters (to exclude the listing of the special .. folder) - so when you happen to have a hidden folder that only has one character it would not be listed, but for now I have not seen any such folder in /home/guest/ .
*/ lists all other folders.

Some background; unlike with regex a "." is here seen literally.
By that, .??* means:
"a literal ."+"any character"+"any character"+"0 or more characters"

Real live Example:

Code: Select all

guest@rava:~$ cd /tmp
guest@rava:/tmp$ mkdir TESTDIR
guest@rava:/tmp$ cd TESTDIR
guest@rava:/tmp/TESTDIR$ ls -la
total 0
drwxr-xr-x  2 guest users  40 2023-12-04 06:48 .
drwxrwxrwt 14 root  root  420 2023-12-04 06:48 ..
guest@rava:/tmp/TESTDIR$ mkdir .test
guest@rava:/tmp/TESTDIR$ mkdir .t
guest@rava:/tmp/TESTDIR$ mkdir .tt
guest@rava:/tmp/TESTDIR$ mkdir test
guest@rava:/tmp/TESTDIR$ ls -la
total 0
drwxr-xr-x  6 guest users 120 2023-12-04 06:49 .
drwxrwxrwt 14 root  root  420 2023-12-04 06:48 ..
drwxr-xr-x  2 guest users  40 2023-12-04 06:48 .t
drwxr-xr-x  2 guest users  40 2023-12-04 06:48 .test
drwxr-xr-x  2 guest users  40 2023-12-04 06:48 .tt
drwxr-xr-x  2 guest users  40 2023-12-04 06:49 test
guest@rava:/tmp/TESTDIR$ du -h .??*/ */
0	.test/
0	.tt/
0	test/
guest@rava:/tmp/TESTDIR$ 
as you can see, all folders but . .. and .t are listed.

User avatar
Ed_P
Contributor
Contributor
Posts: 8374
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

How to list directory sizes in /home/guest/

Post#3 by Ed_P » 04 Dec 2023, 17:56

The hidden directories all still get listed, just without the ./ in front.

Code: Select all

guest@porteus:~$ du -h .??*/ */
24K	.PySolFC/
14M	.cache/mozilla/firefox/ple67xm3.default-release/safebrowsing/google4
16M	.cache/mozilla/firefox/ple67xm3.default-release/safebrowsing
8.0K	.cache/mozilla/firefox/ple67xm3.default-release/settings/main/ms-language-packs/browser/newtab
8.0K	.cache/mozilla/firefox/ple67xm3.default-release/settings/main/ms-language-packs/browser
8.0K	.cache/mozilla/firefox/ple67xm3.default-release/settings/main/ms-language-packs
580K
 :
 :
Added in 12 minutes 14 seconds:
Same with this option.

Code: Select all

guest@porteus:~$ du -h .??*/ */ 2>/dev/null
24K	.PySolFC/
14M	.cache/mozilla/firefox/ple67xm3.default-release/safebrowsing/google4
16M	.cache/mozilla/firefox/ple67xm3.default-release/safebrowsing
8.0K	.cache/mozilla/firefox/ple67xm3.default-release/settings/main/ms-language-packs/browser/newtab
8.0K	.cache/mozilla/firefox/ple67xm3.default-release/settings/main/ms-language-packs/browser
8.0K	.cache/mozilla/firefox/ple67xm3.default-release/settings/main/ms-language-packs
580K	.cache/mozilla/firefox/ple67xm3.default-release/settings/main/quicksuggest
588K	.cache/mozilla/firefox/ple67xm3.default-release/settings/main
588K	.cache/mozilla/firefox/ple67xm3.default-release/settings
40K	.cache/mozilla/firefox/ple67xm3.default-release/thumbnails
4.0K	.cache/mozilla/firefox/ple67xm3.default-release/cache2/doomed
 :
 :
Added in 45 minutes 1 second:
This approach is helping:

Code: Select all

guest@porteus:~$ du -h | grep -v -e'./.cache/' -e'./.mozilla/' -e'config/' -e'./.cinnamon/' -e'./.local/'
4.0K	./.dbus/session-bus
4.0K	./.dbus
36K	./savedat
16K	./porteus-usb/SecureBoot
68K	./porteus-usb
84K	./mkmods
0	./Videos
0	./Public
84M	./.cache
36K	./Pictures/tmp
5.3M	./Pictures
0	./Music
220K	./Downloads/Ignispkg - Porteus Community_files
812K	./Downloads/Ignisgrub2
1.1M	./Downloads
0	./Documents
24K	./Desktop
24K	./Backups/PySolFC
1.7M	./Backups/FireFox
24K	./Backups/Desktop
1.8M	./Backups
60M	./.mozilla
4.0K	./.java/deployment/security
4.0K	./.java/deployment
4.0K	./.java
4.0K	./.hplip
124K	./.config
64K	./.cinnamon
24K	./.PySolFC
153M	.
guest@porteus:~$ 
:)
Ed

User avatar
Rava
Contributor
Contributor
Posts: 5416
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

How to list directory sizes in /home/guest/

Post#4 by Rava » 04 Dec 2023, 19:56

You don't need several grep commands.
When you want to exclude stuff, just use this:
command whatever | egrep -v "[Cc]ache|mozilla|pale moon|basilisk|chrom[ei]|Brave-B"
This excludes all that matches the strings in between each separator "|"

Added in 6 minutes 7 seconds:
When you want to use grep instead of egrep, the command would be
command whatever | grep -vE "[Cc]ache|mozilla|pale moon|basilisk|chrom[ei]|Brave-B"
Cheers!
Yours Rava

User avatar
Ed_P
Contributor
Contributor
Posts: 8374
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

How to list directory sizes in /home/guest/

Post#5 by Ed_P » 04 Dec 2023, 20:23

Code: Select all

guest@porteus:~$ du -h |egrep -v './.cache/'|'./.mozilla/'|'./.config/'|'./.cinnamon/'|'./.local/'
bash: ./.mozilla/: Is a directory
bash: ./.config/: Is a directory
bash: ./.cinnamon/: Is a directory
bash: ./.local/: Is a directory
guest@porteus:~$ 
guest@porteus:~$ du -h -d1 | egrep -v './.cache/'|'./.mozilla/'|'./.config/'|'./.cinnamon/'|'./.local/'
bash: ./.mozilla/: Is a directory
bash: ./.config/: Is a directory
bash: ./.cinnamon/: Is a directory
bash: ./.local/: Is a directory
guest@porteus:~$ 
Ed

User avatar
Rava
Contributor
Contributor
Posts: 5416
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

How to list directory sizes in /home/guest/

Post#6 by Rava » 04 Dec 2023, 21:53

^
You are doing it wrong. Try this:

Code: Select all

guest@porteus:~$ du -h -d1 | egrep -v './.cache/|./.mozilla/|./.config/|./.cinnamon/|./.local/'
Cheers!
Yours Rava

User avatar
Ed_P
Contributor
Contributor
Posts: 8374
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

How to list directory sizes in /home/guest/

Post#7 by Ed_P » 04 Dec 2023, 22:15

Thank you Rava. :good: That does indeed help. :happy62:

Code: Select all

guest@porteus:~$ du -h -d1 | egrep -v './.cache/|./.mozilla/|./.config/|./.cinnamon/|./.local/'
4.0K	./.dbus
40K	./.local
36K	./savedat
68K	./porteus-usb
84K	./mkmods
0	./Videos
0	./Public
32M	./.cache
5.3M	./Pictures
0	./Music
4.0K	./Downloads
0	./Documents
24K	./Desktop
 :
 :
Added in 4 minutes 18 seconds:
So does this. :lol:

Code: Select all

guest@porteus:~$ du -h -d1 | egrep -v './.c*/|./.m*/|./.l*/'
4.0K	./.dbus
68K	./.local
36K	./savedat
68K	./porteus-usb
84K	./mkmods
0	./Videos
0	./Public
62M	./.cache
5.3M	./Pictures
0	./Music
4.0K	./Downloads
0	./Documents
24K	./Desktop
Added in 3 minutes 43 seconds:
And this: :o

Code: Select all

guest@porteus:~$ du -h -d1 | egrep -v './.?*/'
4.0K	./.dbus
68K	./.local
36K	./savedat
68K	./porteus-usb
84K	./mkmods
0	./Videos
0	./Public
62M	./.cache
5.3M	./Pictures
0	./Music
 :
 :
Added in 1 minute 33 seconds:
Now if I could sort them by size.... :)
Ed

User avatar
Rava
Contributor
Contributor
Posts: 5416
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

How to list directory sizes in /home/guest/

Post#8 by Rava » 05 Dec 2023, 01:24

Ed_P wrote:
04 Dec 2023, 22:24
Now if I could sort them by size.... :)
using -m instead of -h would help in that regard.
looking forward to what you come up with for sorting -h output mathematically correct.

User avatar
Ed_P
Contributor
Contributor
Posts: 8374
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

How to list directory sizes in /home/guest/

Post#9 by Ed_P » 05 Dec 2023, 05:54

Rava wrote:
05 Dec 2023, 01:24
using -m instead of -h would help in that regard.
Not really. But this works.

Code: Select all

du -hd1 | egrep -v './.?*/' | sort -n
Added in 47 minutes 52 seconds:

Code: Select all

guest@porteus:~$ du -hd1 | egrep -v './.?*/' | sort -n
0	./Documents
0	./Music
0	./Public
0	./Videos
1.8M	./Backups
4.0K	./.dbus
4.0K	./.hplip
4.0K	./.java
4.0K	./Downloads
5.3M	./Pictures
24K	./.PySolFC
24K	./Desktop
28M	./.mozilla
 :
 :
Granted the Ms & Ks are a little out of sequence but easier to relate to imo.

Code: Select all

guest@porteus:~$ du -md1 | egrep -v './.?*/' | sort -n
0	./Documents
0	./Music
0	./Public
0	./Videos
1	./.PySolFC
1	./.cinnamon
1	./.config
1	./.dbus
1	./.hplip
1	./.java
1	./.local
1	./Desktop
1	./Downloads
1	./mkmods
 :
 :
Added in 13 hours 49 minutes 53 seconds:
This simpler approach seems to work with better results then the previous one!

Code: Select all

guest@porteus:~$ du -kd1 | sort -n
0	./Documents
0	./Music
0	./Public
0	./Videos
4	./.dbus
4	./.hplip
4	./.java
4	./Downloads
24	./.PySolFC
24	./Desktop
36	./savedat
:happy62:
Ed

Rapha_
Shogun
Shogun
Posts: 238
Joined: 12 Jun 2021, 21:59
Distribution: Xfce 4.12 - 5.rc3 - x86_64
Location: France

How to list directory sizes in /home/guest/

Post#10 by Rapha_ » 06 Dec 2023, 00:39

Ed_P wrote:
04 Dec 2023, 22:24
So does this. :lol:

Code: Select all

guest@porteus:~$ du -h -d1 | egrep -v './.c*/|./.m*/|./.l*/'
4.0K	./.dbus
68K	./.local
36K	./savedat
68K	./porteus-usb
84K	./mkmods
0	./Videos
0	./Public
62M	./.cache
5.3M	./Pictures
0	./Music
4.0K	./Downloads
0	./Documents
24K	./Desktop
This works for me :

Code: Select all

du -h -d1 | egrep -v '/.d|/.c|/.m|/.l|/.b'
0	./Vidéos
0	./Musique
0	./Documents
0	./Public
0	./Téléchargements
4,0K	./Desktop
136M	
or this :

Code: Select all

du -h -d 1 | egrep -v '/.[dcmlb]'
0	./Vidéos
0	./Musique
0	./Documents
0	./Public
0	./Téléchargements
4,0K	./Desktop
136M	.
.

Ed_P wrote:
04 Dec 2023, 04:16
du -h lists the directories but includes all the hidden directories. I tried:

Code: Select all

du -h | grep -v "./."
but it excludes "./" directories also.
Maybe an explanation ... ?
Within a regular expression, dot (.) finds any single character....
https://docs.oracle.com/cd/E19683-01/80 ... index.html


Searching for Metacharacters

To use the grep command to search for metacharacters such as & ! . * ? and \, precede the metacharacter with a backslash (\). The backslash tells grep to ignore (escape) the metacharacter.
https://docs.oracle.com/cd/E19683-01/80 ... lesearch-5



This works for me with backslash bebore '.' ;

Code: Select all

du -h | grep -v "/\."
0	./Vidéos
0	./Images
0	./Musique
0	./Documents
0	./Public
0	./Téléchargements
460K	./folder
4,0K	./Desktop
158M	.
or :

Code: Select all

du -h -d 1 | grep  "/\."
4,0K	./.dbus
115M	./.cache
54M	./.mozilla
36K	./.local
304K	./.config
2,9M	./.binary outcast

User avatar
Ed_P
Contributor
Contributor
Posts: 8374
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

How to list directory sizes in /home/guest/

Post#11 by Ed_P » 06 Dec 2023, 06:49

Rapha_ wrote:
06 Dec 2023, 00:39
This works for me :

Code: Select all

du -h -d1 | egrep -v '/.d|/.c|/.m|/.l|/.b'
 :
 :
or this :

Code: Select all

du -h -d 1 | egrep -v '/.[dcmlb]'
 :
 :
Very clever Rapha. :happy62:
Rapha_ wrote:
06 Dec 2023, 00:39
This works for me with backslash bebore '.' ;

Code: Select all

du -h | grep -v "/\."
0	./Vidéos
0	./Images
0	./Musique
0	./Documents
0	./Public
 :
 :
or :

Code: Select all

du -h -d 1 | grep  "/\."
4,0K	./.dbus
115M	./.cache
54M	./.mozilla
36K	./.local
304K	./.config
2,9M	./.binary outcast
:o This one I will have to play with. Thank you :worthy: Ralpha. :good:
Rapha_ wrote:
06 Dec 2023, 00:39
https://docs.oracle.com/cd/E19683-01/806-7612/6jgfmsvq1/index.html#filesearch-5 wrote:Searching for Metacharacters

To use the grep command to search for metacharacters such as & ! . * ? and \, precede the metacharacter with a backslash (\). The backslash tells grep to ignore (escape) the metacharacter.
https://docs.oracle.com/cd/E19683-01/80 ... lesearch-5
Ed

Post Reply