Skip to main content
added 107 characters in body
Source Link
Kusalananda
  • 356.2k
  • 42
  • 737
  • 1.1k

To sort all regular files in or under the current directory by size, the zsh shell provides the handy ** globbing pattern that matches across / in pathnames (i.e. "recursively down into subdirectories). It also allows for qualifying a pattern so that you e.g. get only a match of regular files, and that the results are sorted according to the size of these files.

In the zsh shell, this pattern would look like

**/*(.OL)

This would return all regular files (.) ordered in reverse (O) size order (L).

To get the listing of just the files, use

printf '%s\n' **/*(.OL)

To get ls "long listing" output, use

ls -fl **/*(.OL)

(the -f option prevents ls from doing its own sorting of the files).

If zsh is not your ordinary shell, you can still use these commands, assuming zsh is installed on your system:

zsh -c 'ls -fl **/*(.OL)'

You could obviously also add --block-size=M to that if you're using GNU ls.

If you are interested in just the ten largest files, use the pattern

**/*(.OL[1,10])

instead.

To sort all regular files in or under the current directory by size, the zsh shell provides the handy ** globbing pattern that matches across / in pathnames (i.e. "recursively down into subdirectories). It also allows for qualifying a pattern so that you e.g. get only a match of regular files, and that the results are sorted according to the size of these files.

In the zsh shell, this pattern would look like

**/*(.OL)

This would return all regular files (.) ordered in reverse (O) size order (L).

To get the listing of just the files, use

printf '%s\n' **/*(.OL)

To get ls "long listing" output, use

ls -fl **/*(.OL)

(the -f option prevents ls from doing its own sorting of the files).

If zsh is not your ordinary shell, you can still use these commands, assuming zsh is installed on your system:

zsh -c 'ls -fl **/*(.OL)'

You could obviously also add --block-size=M to that if you're using GNU ls.

To sort all regular files in or under the current directory by size, the zsh shell provides the handy ** globbing pattern that matches across / in pathnames (i.e. "recursively down into subdirectories). It also allows for qualifying a pattern so that you e.g. get only a match of regular files, and that the results are sorted according to the size of these files.

In the zsh shell, this pattern would look like

**/*(.OL)

This would return all regular files (.) ordered in reverse (O) size order (L).

To get the listing of just the files, use

printf '%s\n' **/*(.OL)

To get ls "long listing" output, use

ls -fl **/*(.OL)

(the -f option prevents ls from doing its own sorting of the files).

If zsh is not your ordinary shell, you can still use these commands, assuming zsh is installed on your system:

zsh -c 'ls -fl **/*(.OL)'

You could obviously also add --block-size=M to that if you're using GNU ls.

If you are interested in just the ten largest files, use the pattern

**/*(.OL[1,10])

instead.

Source Link
Kusalananda
  • 356.2k
  • 42
  • 737
  • 1.1k

To sort all regular files in or under the current directory by size, the zsh shell provides the handy ** globbing pattern that matches across / in pathnames (i.e. "recursively down into subdirectories). It also allows for qualifying a pattern so that you e.g. get only a match of regular files, and that the results are sorted according to the size of these files.

In the zsh shell, this pattern would look like

**/*(.OL)

This would return all regular files (.) ordered in reverse (O) size order (L).

To get the listing of just the files, use

printf '%s\n' **/*(.OL)

To get ls "long listing" output, use

ls -fl **/*(.OL)

(the -f option prevents ls from doing its own sorting of the files).

If zsh is not your ordinary shell, you can still use these commands, assuming zsh is installed on your system:

zsh -c 'ls -fl **/*(.OL)'

You could obviously also add --block-size=M to that if you're using GNU ls.