Getting size with du of files only
Clash Royale CLAN TAG#URR8PPP
How can I get the size of all files and all files in its subdirectories using the du command.
I am trying the following command to get the size of all files (and files in subdirectories)
find . -type f | du -a
But this prints out the folder sizes as well. How can I get a listing of sizes of all files and files in subdirectories? I also tried the exec flag
but I am not sure how to pipe the output into another command after it executes the results of find
into du
.
The operating system is AIX 6.1 with ksh shell.
files find disk-usage aix ksh
add a comment |
How can I get the size of all files and all files in its subdirectories using the du command.
I am trying the following command to get the size of all files (and files in subdirectories)
find . -type f | du -a
But this prints out the folder sizes as well. How can I get a listing of sizes of all files and files in subdirectories? I also tried the exec flag
but I am not sure how to pipe the output into another command after it executes the results of find
into du
.
The operating system is AIX 6.1 with ksh shell.
files find disk-usage aix ksh
add a comment |
How can I get the size of all files and all files in its subdirectories using the du command.
I am trying the following command to get the size of all files (and files in subdirectories)
find . -type f | du -a
But this prints out the folder sizes as well. How can I get a listing of sizes of all files and files in subdirectories? I also tried the exec flag
but I am not sure how to pipe the output into another command after it executes the results of find
into du
.
The operating system is AIX 6.1 with ksh shell.
files find disk-usage aix ksh
How can I get the size of all files and all files in its subdirectories using the du command.
I am trying the following command to get the size of all files (and files in subdirectories)
find . -type f | du -a
But this prints out the folder sizes as well. How can I get a listing of sizes of all files and files in subdirectories? I also tried the exec flag
but I am not sure how to pipe the output into another command after it executes the results of find
into du
.
The operating system is AIX 6.1 with ksh shell.
files find disk-usage aix ksh
files find disk-usage aix ksh
edited Dec 16 '18 at 4:16
Rui F Ribeiro
40.1k1479136
40.1k1479136
asked Oct 11 '11 at 19:12
Shardul UpadhyayShardul Upadhyay
318135
318135
add a comment |
add a comment |
5 Answers
5
active
oldest
votes
I usually use the -exec
utility. Like this:
find . -type f -exec du -a +
I tried it both on bash and ksh with GNU find. I never tried AIX, but I'm sure your version of find has some -exec
syntax.
The following snippet sorts the list, largest first:
find . -type f -exec du -a + | sort -n -r | less
3
I'd go with this answer if you don't have access tofind -print0
or other GNU features. If available, replacing;
with+
will result in fewer invocations ofdu
and thus better performance.
– jw013
Oct 11 '11 at 22:02
Thanks, this works out great especially since du offers a flag for size in different units.
– Shardul Upadhyay
Oct 12 '11 at 12:59
I could not find information on the+
option. Is that an option fordu
or forfind
? And why does it result in less calls?
– Amelio Vazquez-Reina
Jul 19 '13 at 22:41
1
It's a standard option offind
. It specifies toexec
the command (in our casedu
) only once, with all the results offind
given as successive arguments to the command.
– rahmu
Jul 20 '13 at 2:25
wtf, why isn't there a command likedu -f --threshold=1G
– Alexander Mills
Dec 22 '18 at 3:41
|
show 1 more comment
If you have GNU utilities, try
find . -type f -print0 | du --files0-from=-
The command is failing saying print0 is not a valid command and that last minus was not a recognized flag. I don't think this approach will work becauseman du
doesn't list afiles
orfrom
flag.
– Shardul Upadhyay
Oct 11 '11 at 20:00
You should add your operating system as a tag to the question. I assumed you had GNU but forgot to mention that.
– jw013
Oct 11 '11 at 20:04
1
Have an upvote on me! Your particular solution works withdu -ch
to get a grand total of matching files:find . -name 'blah blah.*' -print0 | du --files0-from=- -ch
– Michael Goldshteyn
Jul 15 '18 at 14:05
add a comment |
I generally use:
find . -type f -print0 | xargs -r0 du -a
Xargs usually calls the command, even if there are no arguments passed; xargs du </dev/null
will still be called, xargs -r du </dev/null
will not call du. The -0
argument looks for null-terminated strings instead of newline terminated.
Then I usually add | awk 'sum+=$1 END print sum'
on the end to get the total.
2
Thethen I usually add
is worth of gold :-)
– Radek
Oct 2 '12 at 0:56
add a comment |
Here's a version with long parameter names and human sorting.
find . -type f -exec du --human + | sort --human --reverse | head
I also saw no need for -a/--all
to be passed to du
.
add a comment |
specific files in current dir
du -ch files*
is shorter and works for me
du -sh .
for current dir and all files in sub
du (GNU coreutils) 8.30
1
(1) What do you mean bydu -ch files*
? Suppose the current directory containsant
,apple
,banana
,bat
,cat
,corn
,date
, anddog
, where the animal names are subdirectories and the fruit / vegetable names are files — what command would you use to get just the files? Or is that not what you meant? (2)du -sh .
will report only a grand total of everything in and under the current directory, and not the files themselves at all. This is pretty much the exact opposite of what the question asked for.
– G-Man
Jan 25 at 23:09
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%2f22432%2fgetting-size-with-du-of-files-only%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
I usually use the -exec
utility. Like this:
find . -type f -exec du -a +
I tried it both on bash and ksh with GNU find. I never tried AIX, but I'm sure your version of find has some -exec
syntax.
The following snippet sorts the list, largest first:
find . -type f -exec du -a + | sort -n -r | less
3
I'd go with this answer if you don't have access tofind -print0
or other GNU features. If available, replacing;
with+
will result in fewer invocations ofdu
and thus better performance.
– jw013
Oct 11 '11 at 22:02
Thanks, this works out great especially since du offers a flag for size in different units.
– Shardul Upadhyay
Oct 12 '11 at 12:59
I could not find information on the+
option. Is that an option fordu
or forfind
? And why does it result in less calls?
– Amelio Vazquez-Reina
Jul 19 '13 at 22:41
1
It's a standard option offind
. It specifies toexec
the command (in our casedu
) only once, with all the results offind
given as successive arguments to the command.
– rahmu
Jul 20 '13 at 2:25
wtf, why isn't there a command likedu -f --threshold=1G
– Alexander Mills
Dec 22 '18 at 3:41
|
show 1 more comment
I usually use the -exec
utility. Like this:
find . -type f -exec du -a +
I tried it both on bash and ksh with GNU find. I never tried AIX, but I'm sure your version of find has some -exec
syntax.
The following snippet sorts the list, largest first:
find . -type f -exec du -a + | sort -n -r | less
3
I'd go with this answer if you don't have access tofind -print0
or other GNU features. If available, replacing;
with+
will result in fewer invocations ofdu
and thus better performance.
– jw013
Oct 11 '11 at 22:02
Thanks, this works out great especially since du offers a flag for size in different units.
– Shardul Upadhyay
Oct 12 '11 at 12:59
I could not find information on the+
option. Is that an option fordu
or forfind
? And why does it result in less calls?
– Amelio Vazquez-Reina
Jul 19 '13 at 22:41
1
It's a standard option offind
. It specifies toexec
the command (in our casedu
) only once, with all the results offind
given as successive arguments to the command.
– rahmu
Jul 20 '13 at 2:25
wtf, why isn't there a command likedu -f --threshold=1G
– Alexander Mills
Dec 22 '18 at 3:41
|
show 1 more comment
I usually use the -exec
utility. Like this:
find . -type f -exec du -a +
I tried it both on bash and ksh with GNU find. I never tried AIX, but I'm sure your version of find has some -exec
syntax.
The following snippet sorts the list, largest first:
find . -type f -exec du -a + | sort -n -r | less
I usually use the -exec
utility. Like this:
find . -type f -exec du -a +
I tried it both on bash and ksh with GNU find. I never tried AIX, but I'm sure your version of find has some -exec
syntax.
The following snippet sorts the list, largest first:
find . -type f -exec du -a + | sort -n -r | less
edited Apr 2 '13 at 22:57
Gilles
537k12810841602
537k12810841602
answered Oct 11 '11 at 21:52
rahmurahmu
10.4k1970112
10.4k1970112
3
I'd go with this answer if you don't have access tofind -print0
or other GNU features. If available, replacing;
with+
will result in fewer invocations ofdu
and thus better performance.
– jw013
Oct 11 '11 at 22:02
Thanks, this works out great especially since du offers a flag for size in different units.
– Shardul Upadhyay
Oct 12 '11 at 12:59
I could not find information on the+
option. Is that an option fordu
or forfind
? And why does it result in less calls?
– Amelio Vazquez-Reina
Jul 19 '13 at 22:41
1
It's a standard option offind
. It specifies toexec
the command (in our casedu
) only once, with all the results offind
given as successive arguments to the command.
– rahmu
Jul 20 '13 at 2:25
wtf, why isn't there a command likedu -f --threshold=1G
– Alexander Mills
Dec 22 '18 at 3:41
|
show 1 more comment
3
I'd go with this answer if you don't have access tofind -print0
or other GNU features. If available, replacing;
with+
will result in fewer invocations ofdu
and thus better performance.
– jw013
Oct 11 '11 at 22:02
Thanks, this works out great especially since du offers a flag for size in different units.
– Shardul Upadhyay
Oct 12 '11 at 12:59
I could not find information on the+
option. Is that an option fordu
or forfind
? And why does it result in less calls?
– Amelio Vazquez-Reina
Jul 19 '13 at 22:41
1
It's a standard option offind
. It specifies toexec
the command (in our casedu
) only once, with all the results offind
given as successive arguments to the command.
– rahmu
Jul 20 '13 at 2:25
wtf, why isn't there a command likedu -f --threshold=1G
– Alexander Mills
Dec 22 '18 at 3:41
3
3
I'd go with this answer if you don't have access to
find -print0
or other GNU features. If available, replacing ;
with +
will result in fewer invocations of du
and thus better performance.– jw013
Oct 11 '11 at 22:02
I'd go with this answer if you don't have access to
find -print0
or other GNU features. If available, replacing ;
with +
will result in fewer invocations of du
and thus better performance.– jw013
Oct 11 '11 at 22:02
Thanks, this works out great especially since du offers a flag for size in different units.
– Shardul Upadhyay
Oct 12 '11 at 12:59
Thanks, this works out great especially since du offers a flag for size in different units.
– Shardul Upadhyay
Oct 12 '11 at 12:59
I could not find information on the
+
option. Is that an option for du
or for find
? And why does it result in less calls?– Amelio Vazquez-Reina
Jul 19 '13 at 22:41
I could not find information on the
+
option. Is that an option for du
or for find
? And why does it result in less calls?– Amelio Vazquez-Reina
Jul 19 '13 at 22:41
1
1
It's a standard option of
find
. It specifies to exec
the command (in our case du
) only once, with all the results of find
given as successive arguments to the command.– rahmu
Jul 20 '13 at 2:25
It's a standard option of
find
. It specifies to exec
the command (in our case du
) only once, with all the results of find
given as successive arguments to the command.– rahmu
Jul 20 '13 at 2:25
wtf, why isn't there a command like
du -f --threshold=1G
– Alexander Mills
Dec 22 '18 at 3:41
wtf, why isn't there a command like
du -f --threshold=1G
– Alexander Mills
Dec 22 '18 at 3:41
|
show 1 more comment
If you have GNU utilities, try
find . -type f -print0 | du --files0-from=-
The command is failing saying print0 is not a valid command and that last minus was not a recognized flag. I don't think this approach will work becauseman du
doesn't list afiles
orfrom
flag.
– Shardul Upadhyay
Oct 11 '11 at 20:00
You should add your operating system as a tag to the question. I assumed you had GNU but forgot to mention that.
– jw013
Oct 11 '11 at 20:04
1
Have an upvote on me! Your particular solution works withdu -ch
to get a grand total of matching files:find . -name 'blah blah.*' -print0 | du --files0-from=- -ch
– Michael Goldshteyn
Jul 15 '18 at 14:05
add a comment |
If you have GNU utilities, try
find . -type f -print0 | du --files0-from=-
The command is failing saying print0 is not a valid command and that last minus was not a recognized flag. I don't think this approach will work becauseman du
doesn't list afiles
orfrom
flag.
– Shardul Upadhyay
Oct 11 '11 at 20:00
You should add your operating system as a tag to the question. I assumed you had GNU but forgot to mention that.
– jw013
Oct 11 '11 at 20:04
1
Have an upvote on me! Your particular solution works withdu -ch
to get a grand total of matching files:find . -name 'blah blah.*' -print0 | du --files0-from=- -ch
– Michael Goldshteyn
Jul 15 '18 at 14:05
add a comment |
If you have GNU utilities, try
find . -type f -print0 | du --files0-from=-
If you have GNU utilities, try
find . -type f -print0 | du --files0-from=-
edited Oct 11 '11 at 20:04
answered Oct 11 '11 at 19:43
jw013jw013
36.4k6100125
36.4k6100125
The command is failing saying print0 is not a valid command and that last minus was not a recognized flag. I don't think this approach will work becauseman du
doesn't list afiles
orfrom
flag.
– Shardul Upadhyay
Oct 11 '11 at 20:00
You should add your operating system as a tag to the question. I assumed you had GNU but forgot to mention that.
– jw013
Oct 11 '11 at 20:04
1
Have an upvote on me! Your particular solution works withdu -ch
to get a grand total of matching files:find . -name 'blah blah.*' -print0 | du --files0-from=- -ch
– Michael Goldshteyn
Jul 15 '18 at 14:05
add a comment |
The command is failing saying print0 is not a valid command and that last minus was not a recognized flag. I don't think this approach will work becauseman du
doesn't list afiles
orfrom
flag.
– Shardul Upadhyay
Oct 11 '11 at 20:00
You should add your operating system as a tag to the question. I assumed you had GNU but forgot to mention that.
– jw013
Oct 11 '11 at 20:04
1
Have an upvote on me! Your particular solution works withdu -ch
to get a grand total of matching files:find . -name 'blah blah.*' -print0 | du --files0-from=- -ch
– Michael Goldshteyn
Jul 15 '18 at 14:05
The command is failing saying print0 is not a valid command and that last minus was not a recognized flag. I don't think this approach will work because
man du
doesn't list a files
or from
flag.– Shardul Upadhyay
Oct 11 '11 at 20:00
The command is failing saying print0 is not a valid command and that last minus was not a recognized flag. I don't think this approach will work because
man du
doesn't list a files
or from
flag.– Shardul Upadhyay
Oct 11 '11 at 20:00
You should add your operating system as a tag to the question. I assumed you had GNU but forgot to mention that.
– jw013
Oct 11 '11 at 20:04
You should add your operating system as a tag to the question. I assumed you had GNU but forgot to mention that.
– jw013
Oct 11 '11 at 20:04
1
1
Have an upvote on me! Your particular solution works with
du -ch
to get a grand total of matching files: find . -name 'blah blah.*' -print0 | du --files0-from=- -ch
– Michael Goldshteyn
Jul 15 '18 at 14:05
Have an upvote on me! Your particular solution works with
du -ch
to get a grand total of matching files: find . -name 'blah blah.*' -print0 | du --files0-from=- -ch
– Michael Goldshteyn
Jul 15 '18 at 14:05
add a comment |
I generally use:
find . -type f -print0 | xargs -r0 du -a
Xargs usually calls the command, even if there are no arguments passed; xargs du </dev/null
will still be called, xargs -r du </dev/null
will not call du. The -0
argument looks for null-terminated strings instead of newline terminated.
Then I usually add | awk 'sum+=$1 END print sum'
on the end to get the total.
2
Thethen I usually add
is worth of gold :-)
– Radek
Oct 2 '12 at 0:56
add a comment |
I generally use:
find . -type f -print0 | xargs -r0 du -a
Xargs usually calls the command, even if there are no arguments passed; xargs du </dev/null
will still be called, xargs -r du </dev/null
will not call du. The -0
argument looks for null-terminated strings instead of newline terminated.
Then I usually add | awk 'sum+=$1 END print sum'
on the end to get the total.
2
Thethen I usually add
is worth of gold :-)
– Radek
Oct 2 '12 at 0:56
add a comment |
I generally use:
find . -type f -print0 | xargs -r0 du -a
Xargs usually calls the command, even if there are no arguments passed; xargs du </dev/null
will still be called, xargs -r du </dev/null
will not call du. The -0
argument looks for null-terminated strings instead of newline terminated.
Then I usually add | awk 'sum+=$1 END print sum'
on the end to get the total.
I generally use:
find . -type f -print0 | xargs -r0 du -a
Xargs usually calls the command, even if there are no arguments passed; xargs du </dev/null
will still be called, xargs -r du </dev/null
will not call du. The -0
argument looks for null-terminated strings instead of newline terminated.
Then I usually add | awk 'sum+=$1 END print sum'
on the end to get the total.
answered Oct 11 '11 at 20:08
ArcegeArcege
17.1k44257
17.1k44257
2
Thethen I usually add
is worth of gold :-)
– Radek
Oct 2 '12 at 0:56
add a comment |
2
Thethen I usually add
is worth of gold :-)
– Radek
Oct 2 '12 at 0:56
2
2
The
then I usually add
is worth of gold :-)– Radek
Oct 2 '12 at 0:56
The
then I usually add
is worth of gold :-)– Radek
Oct 2 '12 at 0:56
add a comment |
Here's a version with long parameter names and human sorting.
find . -type f -exec du --human + | sort --human --reverse | head
I also saw no need for -a/--all
to be passed to du
.
add a comment |
Here's a version with long parameter names and human sorting.
find . -type f -exec du --human + | sort --human --reverse | head
I also saw no need for -a/--all
to be passed to du
.
add a comment |
Here's a version with long parameter names and human sorting.
find . -type f -exec du --human + | sort --human --reverse | head
I also saw no need for -a/--all
to be passed to du
.
Here's a version with long parameter names and human sorting.
find . -type f -exec du --human + | sort --human --reverse | head
I also saw no need for -a/--all
to be passed to du
.
answered Dec 7 '15 at 10:00
TarraschTarrasch
1664
1664
add a comment |
add a comment |
specific files in current dir
du -ch files*
is shorter and works for me
du -sh .
for current dir and all files in sub
du (GNU coreutils) 8.30
1
(1) What do you mean bydu -ch files*
? Suppose the current directory containsant
,apple
,banana
,bat
,cat
,corn
,date
, anddog
, where the animal names are subdirectories and the fruit / vegetable names are files — what command would you use to get just the files? Or is that not what you meant? (2)du -sh .
will report only a grand total of everything in and under the current directory, and not the files themselves at all. This is pretty much the exact opposite of what the question asked for.
– G-Man
Jan 25 at 23:09
add a comment |
specific files in current dir
du -ch files*
is shorter and works for me
du -sh .
for current dir and all files in sub
du (GNU coreutils) 8.30
1
(1) What do you mean bydu -ch files*
? Suppose the current directory containsant
,apple
,banana
,bat
,cat
,corn
,date
, anddog
, where the animal names are subdirectories and the fruit / vegetable names are files — what command would you use to get just the files? Or is that not what you meant? (2)du -sh .
will report only a grand total of everything in and under the current directory, and not the files themselves at all. This is pretty much the exact opposite of what the question asked for.
– G-Man
Jan 25 at 23:09
add a comment |
specific files in current dir
du -ch files*
is shorter and works for me
du -sh .
for current dir and all files in sub
du (GNU coreutils) 8.30
specific files in current dir
du -ch files*
is shorter and works for me
du -sh .
for current dir and all files in sub
du (GNU coreutils) 8.30
answered Jan 25 at 17:44
shortyshorty
1
1
1
(1) What do you mean bydu -ch files*
? Suppose the current directory containsant
,apple
,banana
,bat
,cat
,corn
,date
, anddog
, where the animal names are subdirectories and the fruit / vegetable names are files — what command would you use to get just the files? Or is that not what you meant? (2)du -sh .
will report only a grand total of everything in and under the current directory, and not the files themselves at all. This is pretty much the exact opposite of what the question asked for.
– G-Man
Jan 25 at 23:09
add a comment |
1
(1) What do you mean bydu -ch files*
? Suppose the current directory containsant
,apple
,banana
,bat
,cat
,corn
,date
, anddog
, where the animal names are subdirectories and the fruit / vegetable names are files — what command would you use to get just the files? Or is that not what you meant? (2)du -sh .
will report only a grand total of everything in and under the current directory, and not the files themselves at all. This is pretty much the exact opposite of what the question asked for.
– G-Man
Jan 25 at 23:09
1
1
(1) What do you mean by
du -ch files*
? Suppose the current directory contains ant
, apple
, banana
, bat
, cat
, corn
, date
, and dog
, where the animal names are subdirectories and the fruit / vegetable names are files — what command would you use to get just the files? Or is that not what you meant? (2) du -sh .
will report only a grand total of everything in and under the current directory, and not the files themselves at all. This is pretty much the exact opposite of what the question asked for.– G-Man
Jan 25 at 23:09
(1) What do you mean by
du -ch files*
? Suppose the current directory contains ant
, apple
, banana
, bat
, cat
, corn
, date
, and dog
, where the animal names are subdirectories and the fruit / vegetable names are files — what command would you use to get just the files? Or is that not what you meant? (2) du -sh .
will report only a grand total of everything in and under the current directory, and not the files themselves at all. This is pretty much the exact opposite of what the question asked for.– G-Man
Jan 25 at 23:09
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%2f22432%2fgetting-size-with-du-of-files-only%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