du -ch -- **/*.jpg | grep total
Especially, what do the --
(double dash) and **
(double asterisk) really mean?
Using the Z shell
du -ch -- **/*.jpg | grep total
Especially, what do the --
(double dash) and **
(double asterisk) really mean?
Using the Z shell
The **
in zsh
matches just like *
, but allows for matching across /
in pathnames. The pattern **/*.jpg
will therefore expand to the pathname of any file that has a filename suffix of .jpg
anywhere in or below the current directory.
The **
pattern is available in bash
as well, if enabled with shopt -s globstar
. The ksh93
shell has it too, if enabled with set -o globstar
.
The --
prevents any pathname (matching the above pattern) that starts with a dash from being interpreted by du
as a command line option. The --
stops the command line parsing of du
from looking for further options. This is not dependent on the shell but is a POSIX "utility guideline" for standard utilities.
The --
could be removed if the filename globbing pattern was changed to ./**/*.jpg
.
The command would give you the total size of all *.jpg
files in or below the current directory by extracting the line with the total from the output of du
(run the command without | grep total
to see what du
produces).
**
alone is not special in zsh
. **/
is and is short for extended_glob (*/)#
. tcsh
, yash
and fish
now also have one form or the other of **
. Your description matches more closely the fish
implementation. See The result of ls * , ls ** and ls *** for more details
– Stéphane Chazelas
Jul 23 '18 at 16:08
From man-page of du usage
du [OPTION][PARAM]
du - lists disk space used by files
c - displays total
h - human readable format (24M= meaning 24 MB)
--
- usually means end of option parameters
**/*.jpg
- glob to go find all paths matching this path (foo/bar.jpg)
|
-pipe
grep total- this option is not required and is redundant, since -c[OPTION] is giving you grand total anyways.
TL;DR: This lists the total disk size of pictures in .jpg format from one step inside directory from current directory.
Eg- If your current Directory is ~/Pictures
then running this command will list file size of all .jpg files inside recursively.(~/Pictures/EuropeTrip/pic134.jpg) [*] means all for regex.
Not sure what (grep total) is doing/ or adding to the output, and maybe unnecessary here.
.*/.*\.jpg
(regex) vs **/*.jpg
(glob).
– ctrl-alt-delor
Jul 20 '18 at 16:58
**/*.jpg
depends on the shell you are using. Please edit you question and tell us which shell are you using. – andcoz Jul 20 '18 at 09:54