Unix & Linux Asked on January 3, 2022
This is probably something basic but I’m not able to make it work. I’m trying to use DU to get a total size of files minus certain directories. I need to exclude one specific directory called uploads
but not every directory called uploads
. For example, my file structure looks a bit like this:
/store
/uploads
/junk_to_ignore
/more_junk_to_ignore
/user_one
/uploads
/user_two
I can run the following command:
du -ch --exclude=uploads*
and it gives me the file size minus all the “uploads” directories. However, in trying to exclude certain directories (and all its sub-directories) I fail. I’ve tried variations of:
du -ch --exclude=./uploads*
du -ch --exclude='/full/path/to/uploads/*'
but can’t seem to figure it out. How do I exclude a specific directory?
To get the total size of files in files/
excluding all sub-directories
du -ch path/to/files --exclude=path/to/files/*/*
Answered by michfuer on January 3, 2022
Just adding a Mac example
du -skI "Downloads" -I "Caches" -I "Logs" -I "OneDrive" .
I do not see a way to use the -I
with a path, so for example, I haven't gotten
du -skI "Downloads" -I "Caches" -I "Logs" -I "OneDrive" -I "Library/Application Support" .
to work. May be possible, but I haven't gotten it yet.
Answered by Rob Morton on January 3, 2022
To exclude multiple folders
du -ch --exclude={path/to/folder1,path/to_folder2/,...,}
Answered by jedi on January 3, 2022
If you have to be on macOS, you install GNU Coreutils with the following command.
brew install coreutils
Most of the commands installed by Coreutils are prefixed by g
, since they have a BSD namesake preinstalled on macOS. Then you can do the following.
gdu --exclude=Microsoft /Library/Fonts/
Answered by Lei Zhao on January 3, 2022
awesome to skip the virtual file systems like so
du -hsx --exclude=/{proc,sys,dev} /*
Answered by Ben Lutgens on January 3, 2022
To exclude multiple directories, just pass the --exclude flag again.
du -ch --exclude=relative/path/to/uploads --exclude other/path/to/exclude
Answered by Dave Neeley on January 3, 2022
You've almost found it :)
du -ch --exclude=./relative/path/to/uploads
Note no asterisk at the end. The asterisk means all subdirectories under "upload" should be omitted - but not the files directly in that directory.
Answered by rozcietrzewiacz on January 3, 2022
1 Asked on December 29, 2021
1 Asked on December 29, 2021 by syed-tahoor-ali
1 Asked on December 29, 2021 by rovanion
2 Asked on December 29, 2021
1 Asked on December 29, 2021
2 Asked on December 29, 2021 by philip-couling
2 Asked on December 29, 2021 by kon
2 Asked on December 27, 2021 by nicols
1 Asked on December 27, 2021 by user176867
0 Asked on December 26, 2021
1 Asked on December 26, 2021 by mabri
1 Asked on December 26, 2021
4 Asked on December 26, 2021 by nas-ahmet
4 Asked on December 24, 2021
1 Asked on December 24, 2021 by lesenger
Get help from others!
Recent Questions
Recent Answers
© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP