Score:3

How to output all files/folders ordered by size, including hidden ones

us flag

How can I output all files/directories, ordered by size, including hidden ones
(those whose name starts with a dot), all in one go? 1

The difference to How can I sort du -h output by size is that I'm requesting an output
that includes all files and directories – whether hidden or not.

References


1 By size of a directory, I mean the sum of all file sizes in the directory and all of its subdirectory tree.

Score:10
us flag

How can I output all files/directories, ordered by size, including hidden ones?

Use the du (disk usage) command, which is part of GNU coreutils : 1

du -hs -- * .[^.]* | sort -h

The .[^.]* regular expression makes sure that hidden files and directories are included.

To list only hidden files and directories :

du -hs -- .[^.]* | sort -h

Some more cases

List only directories, sorted increasing in size :

du -hs -- */ .[^.]*/ | sort -h

List only files, sorted increasing in size : 2

ls -AhlS | grep '^-' | tac

List only hidden files, sorted increasing in size :

ls -hldS .* | grep '^-' | tac

List only regular files, sorted increasing in size :

ls -lS | grep '^-' | tac

References


1 I gratefully attribute my solution to this comment. The -- argument marks the end of options.
The du command can be painfully slow for very large files/folders. Consider using the ncdu command instead.
To install on a Debian derivative, including Ubuntu, run: sudo apt install -y ncdu.
On Arch Linux, including MSYS2, run: yes | pacman -Syu ncdu.
To use it, type ncdu, and press .

2 The -h flag of ls outputs the file sizes in a human-readable style.
The -S flag sorts the output in the order of decreasing size.
The pipe | grep '^-' excludes directories and symbolic links.
The pipe | tac reverses the output.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.