Reputation:
I want to find the size of the current checked-out files in a folder/project, but ignore the git directory.
Something like:
du . --ignore '.git'
Is there a way to find the size of all the files ignoring what's in the .git folder? When I do this:
du . --exclude='.git'
du . --exclude='./.git' # or this
Either way, I get:
du: --exclude=./.git: No such file or directory
What do I do?
Upvotes: 3
Views: 1112
Reputation: 17481
For whatever reason (likely the BSD history of the Mac's utilities), the macOS version of du
does not include --exclude
. However, at least as of 10.14.x, it does include the much-less-obviously-named -I
option which ignores items that are in the "mask" that is provided--in this case "mask" is just another name for some form of regular expression which at least takes simple *
and ?
wildcards.
Running
du -I .git .
gives the size heirarchy, and
du -s -I .git .
gives the summary. In both cases, the .git
directory is ignored.
Upvotes: 3
Reputation: 488453
If your du
has no --exclude
option, you have two easy ways you can deal with this. This first one assumes that there are no hard-links between files in .git
and files elsewhere in the tree, but that's usually true:
du
to get the total usagedu
on .git
itself to get the .git
usageThe second easy way is to install a version of du
that does have --exclude
.
There is a third way to handle this, which is also pretty easy but a little tricky: just move .git
out of the way:
mv .git ../save-git
du ...
mv ../save-git .git
If you use this method, make sure nothing is trying to do anything Git-like in between. Or, make .git
a symbolic link to ../save-git
, or (if your Git is new enough) a plain-text file containing a redirect. Both of those methods can mess with the total, but only by one disk-block worth of space (the symlink or plain-text direct takes a disk block, unless the OS / file-system uses in-inode symlinks and the symlink is short enough to fit in-inode).
Upvotes: 0