Using --exclude with the du command
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?
command-line disk-usage
add a comment |
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?
command-line disk-usage
username: store$ du -ch --exclude=./uploads
worked (with and without the wildcard) for me, from within the store directory. Are you running that command exactly and from within the store folder? And it has to be the relative path (that find sees/prints), not absolute.
– Kevin
Oct 31 '11 at 18:19
add a comment |
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?
command-line disk-usage
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?
command-line disk-usage
command-line disk-usage
asked Oct 31 '11 at 17:47
WillWill
398135
398135
username: store$ du -ch --exclude=./uploads
worked (with and without the wildcard) for me, from within the store directory. Are you running that command exactly and from within the store folder? And it has to be the relative path (that find sees/prints), not absolute.
– Kevin
Oct 31 '11 at 18:19
add a comment |
username: store$ du -ch --exclude=./uploads
worked (with and without the wildcard) for me, from within the store directory. Are you running that command exactly and from within the store folder? And it has to be the relative path (that find sees/prints), not absolute.
– Kevin
Oct 31 '11 at 18:19
username: store$ du -ch --exclude=./uploads
worked (with and without the wildcard) for me, from within the store directory. Are you running that command exactly and from within the store folder? And it has to be the relative path (that find sees/prints), not absolute.– Kevin
Oct 31 '11 at 18:19
username: store$ du -ch --exclude=./uploads
worked (with and without the wildcard) for me, from within the store directory. Are you running that command exactly and from within the store folder? And it has to be the relative path (that find sees/prints), not absolute.– Kevin
Oct 31 '11 at 18:19
add a comment |
4 Answers
4
active
oldest
votes
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.
4
Strange... syntax with dot (du -sb --exclude=./relative/path/to/uploads
) doesn't work for me. This does:du -sb --exclude relative/path/to/uploads
– Nux
Oct 22 '14 at 17:01
4
@Nux probably your flavor ofdu
. Mine (OSX) doesn't even have--exclude
, instead it has-I mask
to "Ignore files and directories matching the specified mask." In your working example you also omit the=
, making me further think it's just your version ofdu
being slightlydu
fferent.
– phatskat
Nov 21 '14 at 15:51
Yes [OSX][1] version seems quite more simplified version of [Linux du][2]. [1]: developer.apple.com/library/mac/documentation/Darwin/Reference/… [2]: linux.die.net/man/1/du
– Nux
Nov 23 '14 at 14:53
What if I want to exclude multiple directories for example here excluding directories junk_to_ignore and uploads directories?
– Kiran K Telukunta
Sep 10 '16 at 8:35
Why does it work with a relative path, but not an absolute path? Very odd!
– Nick
Feb 24 '17 at 16:55
|
show 2 more comments
To exclude multiple directories, just pass the --exclude flag again.
du -ch --exclude=relative/path/to/uploads --exclude other/path/to/exclude
you ca also usedu -ch --exclude={relative/path/to/uploads,other/path/to/exclude}
– Hajo Thelen
Jul 5 '18 at 10:43
add a comment |
awesome to skip the virtual file systems like so
du -hsx --exclude=/{proc,sys,dev} /*
add a comment |
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/
New contributor
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f23692%2fusing-exclude-with-the-du-command%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
4
Strange... syntax with dot (du -sb --exclude=./relative/path/to/uploads
) doesn't work for me. This does:du -sb --exclude relative/path/to/uploads
– Nux
Oct 22 '14 at 17:01
4
@Nux probably your flavor ofdu
. Mine (OSX) doesn't even have--exclude
, instead it has-I mask
to "Ignore files and directories matching the specified mask." In your working example you also omit the=
, making me further think it's just your version ofdu
being slightlydu
fferent.
– phatskat
Nov 21 '14 at 15:51
Yes [OSX][1] version seems quite more simplified version of [Linux du][2]. [1]: developer.apple.com/library/mac/documentation/Darwin/Reference/… [2]: linux.die.net/man/1/du
– Nux
Nov 23 '14 at 14:53
What if I want to exclude multiple directories for example here excluding directories junk_to_ignore and uploads directories?
– Kiran K Telukunta
Sep 10 '16 at 8:35
Why does it work with a relative path, but not an absolute path? Very odd!
– Nick
Feb 24 '17 at 16:55
|
show 2 more comments
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.
4
Strange... syntax with dot (du -sb --exclude=./relative/path/to/uploads
) doesn't work for me. This does:du -sb --exclude relative/path/to/uploads
– Nux
Oct 22 '14 at 17:01
4
@Nux probably your flavor ofdu
. Mine (OSX) doesn't even have--exclude
, instead it has-I mask
to "Ignore files and directories matching the specified mask." In your working example you also omit the=
, making me further think it's just your version ofdu
being slightlydu
fferent.
– phatskat
Nov 21 '14 at 15:51
Yes [OSX][1] version seems quite more simplified version of [Linux du][2]. [1]: developer.apple.com/library/mac/documentation/Darwin/Reference/… [2]: linux.die.net/man/1/du
– Nux
Nov 23 '14 at 14:53
What if I want to exclude multiple directories for example here excluding directories junk_to_ignore and uploads directories?
– Kiran K Telukunta
Sep 10 '16 at 8:35
Why does it work with a relative path, but not an absolute path? Very odd!
– Nick
Feb 24 '17 at 16:55
|
show 2 more comments
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.
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 Oct 31 '11 at 18:25
rozcietrzewiaczrozcietrzewiacz
29.4k47392
29.4k47392
4
Strange... syntax with dot (du -sb --exclude=./relative/path/to/uploads
) doesn't work for me. This does:du -sb --exclude relative/path/to/uploads
– Nux
Oct 22 '14 at 17:01
4
@Nux probably your flavor ofdu
. Mine (OSX) doesn't even have--exclude
, instead it has-I mask
to "Ignore files and directories matching the specified mask." In your working example you also omit the=
, making me further think it's just your version ofdu
being slightlydu
fferent.
– phatskat
Nov 21 '14 at 15:51
Yes [OSX][1] version seems quite more simplified version of [Linux du][2]. [1]: developer.apple.com/library/mac/documentation/Darwin/Reference/… [2]: linux.die.net/man/1/du
– Nux
Nov 23 '14 at 14:53
What if I want to exclude multiple directories for example here excluding directories junk_to_ignore and uploads directories?
– Kiran K Telukunta
Sep 10 '16 at 8:35
Why does it work with a relative path, but not an absolute path? Very odd!
– Nick
Feb 24 '17 at 16:55
|
show 2 more comments
4
Strange... syntax with dot (du -sb --exclude=./relative/path/to/uploads
) doesn't work for me. This does:du -sb --exclude relative/path/to/uploads
– Nux
Oct 22 '14 at 17:01
4
@Nux probably your flavor ofdu
. Mine (OSX) doesn't even have--exclude
, instead it has-I mask
to "Ignore files and directories matching the specified mask." In your working example you also omit the=
, making me further think it's just your version ofdu
being slightlydu
fferent.
– phatskat
Nov 21 '14 at 15:51
Yes [OSX][1] version seems quite more simplified version of [Linux du][2]. [1]: developer.apple.com/library/mac/documentation/Darwin/Reference/… [2]: linux.die.net/man/1/du
– Nux
Nov 23 '14 at 14:53
What if I want to exclude multiple directories for example here excluding directories junk_to_ignore and uploads directories?
– Kiran K Telukunta
Sep 10 '16 at 8:35
Why does it work with a relative path, but not an absolute path? Very odd!
– Nick
Feb 24 '17 at 16:55
4
4
Strange... syntax with dot (
du -sb --exclude=./relative/path/to/uploads
) doesn't work for me. This does: du -sb --exclude relative/path/to/uploads
– Nux
Oct 22 '14 at 17:01
Strange... syntax with dot (
du -sb --exclude=./relative/path/to/uploads
) doesn't work for me. This does: du -sb --exclude relative/path/to/uploads
– Nux
Oct 22 '14 at 17:01
4
4
@Nux probably your flavor of
du
. Mine (OSX) doesn't even have --exclude
, instead it has -I mask
to "Ignore files and directories matching the specified mask." In your working example you also omit the =
, making me further think it's just your version of du
being slightly du
fferent.– phatskat
Nov 21 '14 at 15:51
@Nux probably your flavor of
du
. Mine (OSX) doesn't even have --exclude
, instead it has -I mask
to "Ignore files and directories matching the specified mask." In your working example you also omit the =
, making me further think it's just your version of du
being slightly du
fferent.– phatskat
Nov 21 '14 at 15:51
Yes [OSX][1] version seems quite more simplified version of [Linux du][2]. [1]: developer.apple.com/library/mac/documentation/Darwin/Reference/… [2]: linux.die.net/man/1/du
– Nux
Nov 23 '14 at 14:53
Yes [OSX][1] version seems quite more simplified version of [Linux du][2]. [1]: developer.apple.com/library/mac/documentation/Darwin/Reference/… [2]: linux.die.net/man/1/du
– Nux
Nov 23 '14 at 14:53
What if I want to exclude multiple directories for example here excluding directories junk_to_ignore and uploads directories?
– Kiran K Telukunta
Sep 10 '16 at 8:35
What if I want to exclude multiple directories for example here excluding directories junk_to_ignore and uploads directories?
– Kiran K Telukunta
Sep 10 '16 at 8:35
Why does it work with a relative path, but not an absolute path? Very odd!
– Nick
Feb 24 '17 at 16:55
Why does it work with a relative path, but not an absolute path? Very odd!
– Nick
Feb 24 '17 at 16:55
|
show 2 more comments
To exclude multiple directories, just pass the --exclude flag again.
du -ch --exclude=relative/path/to/uploads --exclude other/path/to/exclude
you ca also usedu -ch --exclude={relative/path/to/uploads,other/path/to/exclude}
– Hajo Thelen
Jul 5 '18 at 10:43
add a comment |
To exclude multiple directories, just pass the --exclude flag again.
du -ch --exclude=relative/path/to/uploads --exclude other/path/to/exclude
you ca also usedu -ch --exclude={relative/path/to/uploads,other/path/to/exclude}
– Hajo Thelen
Jul 5 '18 at 10:43
add a comment |
To exclude multiple directories, just pass the --exclude flag again.
du -ch --exclude=relative/path/to/uploads --exclude other/path/to/exclude
To exclude multiple directories, just pass the --exclude flag again.
du -ch --exclude=relative/path/to/uploads --exclude other/path/to/exclude
answered Aug 30 '17 at 21:42
Dave NeeleyDave Neeley
15913
15913
you ca also usedu -ch --exclude={relative/path/to/uploads,other/path/to/exclude}
– Hajo Thelen
Jul 5 '18 at 10:43
add a comment |
you ca also usedu -ch --exclude={relative/path/to/uploads,other/path/to/exclude}
– Hajo Thelen
Jul 5 '18 at 10:43
you ca also use
du -ch --exclude={relative/path/to/uploads,other/path/to/exclude}
– Hajo Thelen
Jul 5 '18 at 10:43
you ca also use
du -ch --exclude={relative/path/to/uploads,other/path/to/exclude}
– Hajo Thelen
Jul 5 '18 at 10:43
add a comment |
awesome to skip the virtual file systems like so
du -hsx --exclude=/{proc,sys,dev} /*
add a comment |
awesome to skip the virtual file systems like so
du -hsx --exclude=/{proc,sys,dev} /*
add a comment |
awesome to skip the virtual file systems like so
du -hsx --exclude=/{proc,sys,dev} /*
awesome to skip the virtual file systems like so
du -hsx --exclude=/{proc,sys,dev} /*
answered Jul 18 '18 at 11:37
Ben LutgensBen Lutgens
1313
1313
add a comment |
add a comment |
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/
New contributor
add a comment |
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/
New contributor
add a comment |
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/
New contributor
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/
New contributor
New contributor
answered 4 mins ago
Lei ZhaoLei Zhao
11
11
New contributor
New contributor
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f23692%2fusing-exclude-with-the-du-command%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
username: store$ du -ch --exclude=./uploads
worked (with and without the wildcard) for me, from within the store directory. Are you running that command exactly and from within the store folder? And it has to be the relative path (that find sees/prints), not absolute.– Kevin
Oct 31 '11 at 18:19