Background
Let us use the du command.
The du command stands for disk used.
It is a commonly used command in the Linux world.
OS
OS / Linux
Arguments
Here are some of the arguments supported by the dh command.
Argument | Meaning | Explanation |
---|---|---|
-h , –human-readable | Human Readable | -h |
-s, –summarize | Summarize | -s |
–time | Timestamp of last modification | –time |
-X, –exclude=Pattern | Exclude file name pattern | -X=“*.bak” |
Syntax
du
Samples
Sample – One Subfolder down, Human Readable, and last modification
Outline
- Get disk used by the indicated folder
- The name of the sub-folder is .git
- Only go down one folder
- –max-depth of 1
- Human Readable
- -h
- Time of last modification
- –time
Command
du .git --max-depth 1 -h --time
Output
Output – Text
>du .git --max-depth 1 -h --time 40K 2022-06-03 04:26 .git/hooks 0 2021-11-10 18:55 .git/info 1.1G 2022-06-03 04:28 .git/lfs 24K 2022-06-03 04:28 .git/logs 1.7G 2022-06-03 04:27 .git/objects 0 2022-06-03 04:28 .git/refs 2.8G 2022-06-03 04:28 .git >
Output – Image
Sample – One Subfolder down, Human Readable, and last modification -AND- Sort Output Using Order By in reverse order
Outline
- du command
- Get disk used by the indicated folder
- The name of the sub-folder is .git
- Only go down one folder
- –max-depth of 1
- Human Readable
- -h
- Time of last modification
- –time
- Get disk used by the indicated folder
- sort command
- Human Readable Input
- -h
- Reverse Order
- -r
- Human Readable Input
Command
du .git --max-depth 1 -h --time | sort -h -r
Output
Output – Text
>du .git --max-depth 1 -h --time | sort -h -r 2.8G 2022-06-03 04:28 .git 1.7G 2022-06-03 04:27 .git/objects 1.1G 2022-06-03 04:28 .git/lfs 40K 2022-06-03 04:26 .git/hooks 24K 2022-06-03 04:28 .git/logs 0 2022-06-03 04:28 .git/refs 0 2021-11-10 18:55 .git/info >
Output – Image
OS / MS Windows – SysInternals – du
Artifacts
The du command is not built into MS Windows.
One can get a working version courtesy of SysInternals.
Here is the link
https://docs.microsoft.com/en-us/sysinternals/downloads/du ( link )
Arguments
Here are some of the arguments supported by the dh command.
Argument | Meaning | Explanation |
---|---|---|
-l | Specify subdirectory depth of information (default is all levels). | -l 1 ( calculation done on all subfolders, but one the first level subfolder is displayed ) |
-nobanner | No Banner | Do not display program info
DU v1.62 – Directory disk usage reporter |
Syntax
du
Samples
Sample – One Subfolder down
Outline
- Get disk used by the indicated folder
- The name of the sub-folder is .git
- Only go down one folder
- -l of 1
- No Banner
- -nobanner
- Quiet Mode
- -q
Command
du -nobanner -q -l 1 .git
Output
Output – Text
>du -nobanner -q -l 1 .git 23 \.git\hooks 0 \.git\info 1,133,180 \.git\lfs 19 \.git\logs 1,753,906 \.git\objects 0 \.git\refs Files: 923 Directories: 283 Size: 2,956,516,587 bytes Size on disk: 2,963,533,824 bytes >
Output – Image
Sample – One Subfolder down And Strip Out Summary Lines At the Bottom of the Output
Outline
- Get disk used by the indicated folder
- The name of the sub-folder is .git
- Only go down one folder
- -l of 1
- No Banner
- -nobanner
- Quiet Mode
- -q
Command
du -q -nobanner -l 1 .git 2>nul | findstr /v /c "Processing Totals Files Directories Size"
Output
Output – Text
>du -q -nobanner -l 1 .git 2>nul | findstr /v /c "Processing Totals Files Directories Size" FINDSTR: /c ignored 23 \.git\hooks 0 \.git\info 1,133,180 \.git\lfs 19 \.git\logs 1,753,906 \.git\objects 0 \.git\refs
Output – Image
Lab Environment
Our exercise was conducted on a MS Windows machine.
We used WSH to launch a Linux Environment and use the same folder for both the MS Windows and Linux tests.
Summary
Relative to SysInternals’s du re-incarnation, the Linux du command is far more capable.
Because the Linux Sort command supports human readable numeric numbers such as KB, MB and GB we are able to display the numbers aesthetically, yet correctly sorted.