[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: adding a feature to the du util
From: |
Bernhard Voelker |
Subject: |
Re: adding a feature to the du util |
Date: |
Mon, 11 Jan 2021 18:39:24 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 |
On 12/22/20 11:02 PM, Noam Yizraeli wrote:
> I would like to add an option to view du output from du -sh for a certain
> directory with also including hidden files and dirs.
I'm not sure what exactly you mean, and you didn't provide an example.
'du' already includes the count for "hidden" files.
My guess is that you mean a call like:
$ du -sh *
The point is that 'du' only processes the entries explicitly
passed to it. And it doesn't do the expansion of '*' itself;
in fact, it doesn't see the '*' at all. Instead, the calling
shell does the expansion. There's nothing we can do about in 'du'.
Example:
$ ls -alog
total 956
drwxr-xr-x 4 4096 Jan 11 18:28 .
drwxrwxrwt 30 663552 Jan 11 18:27 ..
-rw-r--r-- 1 1235 Aug 14 2018 .profile
drwx------ 2 4096 Aug 11 22:45 .ssh
drwxr-x--- 16 4096 Dec 18 19:07 dir1
-rwxr-xr-x 1 291352 Jan 11 18:28 file1
$ du -sh *
63M dir1
288K file1
To see how the shell calls 'du', you could use the 'echo' command
in front of it:
$ echo du -sh *
du -sh dir1 file1
So 'du' is called with those 2 file names only, but not the hidden ones.
This is because the shell globbing doesn't expand '*' to hidden files
per default.
E.g. in 'bash' as the calling shell, you could change this by the 'dotglob'
option via `shopt -s dotglob`.
$ shopt -s dotglob
$ echo du -sh *
du -sh .profile .ssh dir1 file1
Is that what you mean?
Have a nice day,
Berny
- Re: adding a feature to the du util,
Bernhard Voelker <=