Quickest way to find the largest file in a directory and subdirectories [duplicate]

Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
This question already has an answer here:
Finding largest file recursively
4 answers
I need to find the largest file in the current and subsequent directory. I tried
ls -Rlh | awk 'print $3 " " $5 " " $9'
but do not know if it is ok, how to sort and select the largest file.
shell-script files sort size
marked as duplicate by Jeff Schaller, roaima, GAD3R, Stephen Rauch, Stéphane Chazelas
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 20 '17 at 17:13
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
up vote
0
down vote
favorite
This question already has an answer here:
Finding largest file recursively
4 answers
I need to find the largest file in the current and subsequent directory. I tried
ls -Rlh | awk 'print $3 " " $5 " " $9'
but do not know if it is ok, how to sort and select the largest file.
shell-script files sort size
marked as duplicate by Jeff Schaller, roaima, GAD3R, Stephen Rauch, Stéphane Chazelas
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 20 '17 at 17:13
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
This question already has an answer here:
Finding largest file recursively
4 answers
I need to find the largest file in the current and subsequent directory. I tried
ls -Rlh | awk 'print $3 " " $5 " " $9'
but do not know if it is ok, how to sort and select the largest file.
shell-script files sort size
This question already has an answer here:
Finding largest file recursively
4 answers
I need to find the largest file in the current and subsequent directory. I tried
ls -Rlh | awk 'print $3 " " $5 " " $9'
but do not know if it is ok, how to sort and select the largest file.
This question already has an answer here:
Finding largest file recursively
4 answers
shell-script files sort size
edited Nov 20 '17 at 15:37
Archemar
19k93366
19k93366
asked Nov 20 '17 at 15:22
Alex
1104
1104
marked as duplicate by Jeff Schaller, roaima, GAD3R, Stephen Rauch, Stéphane Chazelas
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 20 '17 at 17:13
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Jeff Schaller, roaima, GAD3R, Stephen Rauch, Stéphane Chazelas
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 20 '17 at 17:13
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
GNU find + sort + head solution (for any directory depth level), assuming file paths don't contain newline characters:
find . -type f -printf "%s %pn" | sort -nr | head -1
%s- format specificator pointing to file size (in bytes)%p- format specificator pointing to file namesort -nr- sort records numerically in reversed orderhead -1- print the TOP first line/record
To get a human-readable file size value - extend the pipeline with GNU numfmt command (if supported):
find . -type f -printf "%s %pn" | sort -nr | head -1 | numfmt --to=si
I would need human readable disk usage. Do you have any recommendations? It works perfect so far.
â Alex
Nov 20 '17 at 16:12
@JamesW, se my update
â RomanPerekhrest
Nov 20 '17 at 16:33
Worked perfect! I didn't know there is an actual function for converting to human readable
â Alex
Nov 20 '17 at 17:19
add a comment |Â
up vote
0
down vote
With zsh, for the biggest regular file:
ls -ld -- **/*(.DOL[1])
(of course you can replace ls -ld -- with any command. If using GNU ls or compatible see also the -h option for human readable sizes)
.: only regular files (not directories, symlinks, devices, fifos...)D: include hidden ones and descend into hidden dirsOL: reverse-ordered by size (Length).[1]: only the first match.
If there are ties, you'll get any one of them at random. If you want the first in alphabetical order, add an extra on (order by name) to sort ties alphabetically.
I might do something wrong but it does not work
â Alex
Nov 20 '17 at 16:12
@JamesW, I suspect you missed the "Withzsh" part. What shell are you trying it in? In which way does it not work?
â Stéphane Chazelas
Nov 20 '17 at 16:16
I am running bash. So I have to put that in a script, right and execute with zsh. Can I do it straight from the command line?
â Alex
Nov 20 '17 at 16:29
Frombash, you can always dozsh -c 'ls -ld -- **/*(.DOL[1])'but if you're often finding yourself looking for the quickest way, you may want to consider switching your shell tozsh(also for safest way , best way and more efficient way).
â Stéphane Chazelas
Nov 20 '17 at 16:32
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
GNU find + sort + head solution (for any directory depth level), assuming file paths don't contain newline characters:
find . -type f -printf "%s %pn" | sort -nr | head -1
%s- format specificator pointing to file size (in bytes)%p- format specificator pointing to file namesort -nr- sort records numerically in reversed orderhead -1- print the TOP first line/record
To get a human-readable file size value - extend the pipeline with GNU numfmt command (if supported):
find . -type f -printf "%s %pn" | sort -nr | head -1 | numfmt --to=si
I would need human readable disk usage. Do you have any recommendations? It works perfect so far.
â Alex
Nov 20 '17 at 16:12
@JamesW, se my update
â RomanPerekhrest
Nov 20 '17 at 16:33
Worked perfect! I didn't know there is an actual function for converting to human readable
â Alex
Nov 20 '17 at 17:19
add a comment |Â
up vote
2
down vote
accepted
GNU find + sort + head solution (for any directory depth level), assuming file paths don't contain newline characters:
find . -type f -printf "%s %pn" | sort -nr | head -1
%s- format specificator pointing to file size (in bytes)%p- format specificator pointing to file namesort -nr- sort records numerically in reversed orderhead -1- print the TOP first line/record
To get a human-readable file size value - extend the pipeline with GNU numfmt command (if supported):
find . -type f -printf "%s %pn" | sort -nr | head -1 | numfmt --to=si
I would need human readable disk usage. Do you have any recommendations? It works perfect so far.
â Alex
Nov 20 '17 at 16:12
@JamesW, se my update
â RomanPerekhrest
Nov 20 '17 at 16:33
Worked perfect! I didn't know there is an actual function for converting to human readable
â Alex
Nov 20 '17 at 17:19
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
GNU find + sort + head solution (for any directory depth level), assuming file paths don't contain newline characters:
find . -type f -printf "%s %pn" | sort -nr | head -1
%s- format specificator pointing to file size (in bytes)%p- format specificator pointing to file namesort -nr- sort records numerically in reversed orderhead -1- print the TOP first line/record
To get a human-readable file size value - extend the pipeline with GNU numfmt command (if supported):
find . -type f -printf "%s %pn" | sort -nr | head -1 | numfmt --to=si
GNU find + sort + head solution (for any directory depth level), assuming file paths don't contain newline characters:
find . -type f -printf "%s %pn" | sort -nr | head -1
%s- format specificator pointing to file size (in bytes)%p- format specificator pointing to file namesort -nr- sort records numerically in reversed orderhead -1- print the TOP first line/record
To get a human-readable file size value - extend the pipeline with GNU numfmt command (if supported):
find . -type f -printf "%s %pn" | sort -nr | head -1 | numfmt --to=si
edited Nov 20 '17 at 16:32
answered Nov 20 '17 at 15:27
RomanPerekhrest
22.4k12145
22.4k12145
I would need human readable disk usage. Do you have any recommendations? It works perfect so far.
â Alex
Nov 20 '17 at 16:12
@JamesW, se my update
â RomanPerekhrest
Nov 20 '17 at 16:33
Worked perfect! I didn't know there is an actual function for converting to human readable
â Alex
Nov 20 '17 at 17:19
add a comment |Â
I would need human readable disk usage. Do you have any recommendations? It works perfect so far.
â Alex
Nov 20 '17 at 16:12
@JamesW, se my update
â RomanPerekhrest
Nov 20 '17 at 16:33
Worked perfect! I didn't know there is an actual function for converting to human readable
â Alex
Nov 20 '17 at 17:19
I would need human readable disk usage. Do you have any recommendations? It works perfect so far.
â Alex
Nov 20 '17 at 16:12
I would need human readable disk usage. Do you have any recommendations? It works perfect so far.
â Alex
Nov 20 '17 at 16:12
@JamesW, se my update
â RomanPerekhrest
Nov 20 '17 at 16:33
@JamesW, se my update
â RomanPerekhrest
Nov 20 '17 at 16:33
Worked perfect! I didn't know there is an actual function for converting to human readable
â Alex
Nov 20 '17 at 17:19
Worked perfect! I didn't know there is an actual function for converting to human readable
â Alex
Nov 20 '17 at 17:19
add a comment |Â
up vote
0
down vote
With zsh, for the biggest regular file:
ls -ld -- **/*(.DOL[1])
(of course you can replace ls -ld -- with any command. If using GNU ls or compatible see also the -h option for human readable sizes)
.: only regular files (not directories, symlinks, devices, fifos...)D: include hidden ones and descend into hidden dirsOL: reverse-ordered by size (Length).[1]: only the first match.
If there are ties, you'll get any one of them at random. If you want the first in alphabetical order, add an extra on (order by name) to sort ties alphabetically.
I might do something wrong but it does not work
â Alex
Nov 20 '17 at 16:12
@JamesW, I suspect you missed the "Withzsh" part. What shell are you trying it in? In which way does it not work?
â Stéphane Chazelas
Nov 20 '17 at 16:16
I am running bash. So I have to put that in a script, right and execute with zsh. Can I do it straight from the command line?
â Alex
Nov 20 '17 at 16:29
Frombash, you can always dozsh -c 'ls -ld -- **/*(.DOL[1])'but if you're often finding yourself looking for the quickest way, you may want to consider switching your shell tozsh(also for safest way , best way and more efficient way).
â Stéphane Chazelas
Nov 20 '17 at 16:32
add a comment |Â
up vote
0
down vote
With zsh, for the biggest regular file:
ls -ld -- **/*(.DOL[1])
(of course you can replace ls -ld -- with any command. If using GNU ls or compatible see also the -h option for human readable sizes)
.: only regular files (not directories, symlinks, devices, fifos...)D: include hidden ones and descend into hidden dirsOL: reverse-ordered by size (Length).[1]: only the first match.
If there are ties, you'll get any one of them at random. If you want the first in alphabetical order, add an extra on (order by name) to sort ties alphabetically.
I might do something wrong but it does not work
â Alex
Nov 20 '17 at 16:12
@JamesW, I suspect you missed the "Withzsh" part. What shell are you trying it in? In which way does it not work?
â Stéphane Chazelas
Nov 20 '17 at 16:16
I am running bash. So I have to put that in a script, right and execute with zsh. Can I do it straight from the command line?
â Alex
Nov 20 '17 at 16:29
Frombash, you can always dozsh -c 'ls -ld -- **/*(.DOL[1])'but if you're often finding yourself looking for the quickest way, you may want to consider switching your shell tozsh(also for safest way , best way and more efficient way).
â Stéphane Chazelas
Nov 20 '17 at 16:32
add a comment |Â
up vote
0
down vote
up vote
0
down vote
With zsh, for the biggest regular file:
ls -ld -- **/*(.DOL[1])
(of course you can replace ls -ld -- with any command. If using GNU ls or compatible see also the -h option for human readable sizes)
.: only regular files (not directories, symlinks, devices, fifos...)D: include hidden ones and descend into hidden dirsOL: reverse-ordered by size (Length).[1]: only the first match.
If there are ties, you'll get any one of them at random. If you want the first in alphabetical order, add an extra on (order by name) to sort ties alphabetically.
With zsh, for the biggest regular file:
ls -ld -- **/*(.DOL[1])
(of course you can replace ls -ld -- with any command. If using GNU ls or compatible see also the -h option for human readable sizes)
.: only regular files (not directories, symlinks, devices, fifos...)D: include hidden ones and descend into hidden dirsOL: reverse-ordered by size (Length).[1]: only the first match.
If there are ties, you'll get any one of them at random. If you want the first in alphabetical order, add an extra on (order by name) to sort ties alphabetically.
edited Nov 20 '17 at 16:34
answered Nov 20 '17 at 16:00
Stéphane Chazelas
282k53521854
282k53521854
I might do something wrong but it does not work
â Alex
Nov 20 '17 at 16:12
@JamesW, I suspect you missed the "Withzsh" part. What shell are you trying it in? In which way does it not work?
â Stéphane Chazelas
Nov 20 '17 at 16:16
I am running bash. So I have to put that in a script, right and execute with zsh. Can I do it straight from the command line?
â Alex
Nov 20 '17 at 16:29
Frombash, you can always dozsh -c 'ls -ld -- **/*(.DOL[1])'but if you're often finding yourself looking for the quickest way, you may want to consider switching your shell tozsh(also for safest way , best way and more efficient way).
â Stéphane Chazelas
Nov 20 '17 at 16:32
add a comment |Â
I might do something wrong but it does not work
â Alex
Nov 20 '17 at 16:12
@JamesW, I suspect you missed the "Withzsh" part. What shell are you trying it in? In which way does it not work?
â Stéphane Chazelas
Nov 20 '17 at 16:16
I am running bash. So I have to put that in a script, right and execute with zsh. Can I do it straight from the command line?
â Alex
Nov 20 '17 at 16:29
Frombash, you can always dozsh -c 'ls -ld -- **/*(.DOL[1])'but if you're often finding yourself looking for the quickest way, you may want to consider switching your shell tozsh(also for safest way , best way and more efficient way).
â Stéphane Chazelas
Nov 20 '17 at 16:32
I might do something wrong but it does not work
â Alex
Nov 20 '17 at 16:12
I might do something wrong but it does not work
â Alex
Nov 20 '17 at 16:12
@JamesW, I suspect you missed the "With
zsh" part. What shell are you trying it in? In which way does it not work?â Stéphane Chazelas
Nov 20 '17 at 16:16
@JamesW, I suspect you missed the "With
zsh" part. What shell are you trying it in? In which way does it not work?â Stéphane Chazelas
Nov 20 '17 at 16:16
I am running bash. So I have to put that in a script, right and execute with zsh. Can I do it straight from the command line?
â Alex
Nov 20 '17 at 16:29
I am running bash. So I have to put that in a script, right and execute with zsh. Can I do it straight from the command line?
â Alex
Nov 20 '17 at 16:29
From
bash, you can always do zsh -c 'ls -ld -- **/*(.DOL[1])' but if you're often finding yourself looking for the quickest way, you may want to consider switching your shell to zsh (also for safest way , best way and more efficient way).â Stéphane Chazelas
Nov 20 '17 at 16:32
From
bash, you can always do zsh -c 'ls -ld -- **/*(.DOL[1])' but if you're often finding yourself looking for the quickest way, you may want to consider switching your shell to zsh (also for safest way , best way and more efficient way).â Stéphane Chazelas
Nov 20 '17 at 16:32
add a comment |Â