From my tests the safest approach is this...
du -sm -- * .[^.]*
TIP: Prefer megabytes (-m
option).
NOTE: Occasional side effect du: cannot access '.[^.]*': No such file or directory
. When there is no hidden files/folders? 🤔
Thanks! 😎
PLUS
Sortly list by megabytes the 15 largest files/folders...
du -sm -- * .[^.]* | sort -nr | head -15
FURTHER
It seems to me that an approach with ls -A
might be safer as this command is suitable for listing files (-A
including hiddem ones). However, we have discrepancies in the outputs and problems with single quotes even using xargs
to try to handle the situation.
SAMPLES
[eduardolac-pc eduardolac]# du -sm -- * .[^.]* | sort -nr | head -15
553002 Data1
140123 Data0
37718 .PlayOnLinux
17349 .local
13424 .cache
8654 .config
7931 .var
3423 .pyenv
2833 .npm
2051 .stremio-server
2001 .Phoenicis
1896 .wine
1479 .conda
1451 .nvm
1402 .vscode
[eduardolac-pc eduardolac]# ls -A | xargs -I {} du -sm {} | sort -nr | head -15
xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option
553002 Data1
140123 Data0
37718 .PlayOnLinux
17349 .local
13416 .cache
8654 .config
2833 .npm
2001 .Phoenicis
1479 .conda
1451 .nvm
962 .goldendict
932 GoldenDict_Glossaries
803 .mozilla
785 .m2
570 .googleearth
[Ref(s).: https://serverfault.com/a/1116989/276753 ,
https://superuser.com/a/1739605/195840 ]