Can I shorten this filter, that finds disk sizes over 100G?How can I monitor disk io?Grep command that finds/excludes all line where a separator character appears a certain number of times?How to get disk name that contains a specific partitionhow to find the MAX IO a physical disk can supportHow can I filter out strings that contain no numbers within them?How soon will linux notice that a disk has been detached ? And can it be quicker?Disk io stat “averaged” over a period of time
What does Bitcoin policy language offer the developer that Miniscript doesn't? What is the difference between Bitcoin policy language and Miniscript?
What is the meaning of 奥手 here?
Who is this famous person?
Trying to find a comic strip about "What your clothes say about you"
Which battle was the most lopsided result in terms of casualties?
A Star Trek book I read in the eighties, Kirk is shunned for destroying a civilization
Impact wrench on spark plugs?
How to implement the five star notation in Latex
How did Krennic locate the Erso's hideout?
Just bought HD650's with Scarlet 2i2 solo and it sounds too QUIET
Is it possible to get reverse life insurance?
A randomized encryption program
Does any country have free college & open admissions?
Sun dried tomatoes
Average Two Letters
Warranty on lock damaged during attempted theft
My mysterious "ruins" wander around and change on their own, what'd be a rational way for them to do that?
What DC should I use for someone trying to survive indefinitely solely with an alchemy jug as their only source of food and water? (survival campaign)
How to get best taste out of tomatoes?
Does the Antonov An-225 have an Auxiliary Power Unit (APU)?
How to communicate faster than the system clock
How is antioxidant activity of carotenoids determined?
Object Oriented Programming - how to avoid duplication in processes that differ slightly depending on a variable
At what point in time would humans notice a 21st century satellite observing them?
Can I shorten this filter, that finds disk sizes over 100G?
How can I monitor disk io?Grep command that finds/excludes all line where a separator character appears a certain number of times?How to get disk name that contains a specific partitionhow to find the MAX IO a physical disk can supportHow can I filter out strings that contain no numbers within them?How soon will linux notice that a disk has been detached ? And can it be quicker?Disk io stat “averaged” over a period of time
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;
My goal is to get the disks greater than 100G from lsblk.
I have it working, but it's awkward. I'm pretty sure it can be shortened. Either by using something totally different than lsblk, or maybe I can filter human readable numbers directly with awk.
Here's what I put together:
lsblk | grep disk | awk 'print$1,$4' | grep G | sed 's/.$//' | awk 'if($2>100)print$1'
It outputs only the sdx and nvmexxx part of the disks larger than 100G. Exactly what I need.
I am happy with it, but am eager to learn more from you Gurus 😉
awk grep disk lsblk
add a comment
|
My goal is to get the disks greater than 100G from lsblk.
I have it working, but it's awkward. I'm pretty sure it can be shortened. Either by using something totally different than lsblk, or maybe I can filter human readable numbers directly with awk.
Here's what I put together:
lsblk | grep disk | awk 'print$1,$4' | grep G | sed 's/.$//' | awk 'if($2>100)print$1'
It outputs only the sdx and nvmexxx part of the disks larger than 100G. Exactly what I need.
I am happy with it, but am eager to learn more from you Gurus 😉
awk grep disk lsblk
between 100-999GB and larger than 100T, but nothing between 1-99T, i presume? (terabytes~)
– hanshenrik
Aug 2 at 21:13
Yes that is one flaw that slipped my attention and was already discussed in the answers. I therefore accepted the answer to do the filter based on byte size instead of human readable. If you of another method I'll be happy to learn about that to.
– chalybeum
Aug 2 at 21:47
add a comment
|
My goal is to get the disks greater than 100G from lsblk.
I have it working, but it's awkward. I'm pretty sure it can be shortened. Either by using something totally different than lsblk, or maybe I can filter human readable numbers directly with awk.
Here's what I put together:
lsblk | grep disk | awk 'print$1,$4' | grep G | sed 's/.$//' | awk 'if($2>100)print$1'
It outputs only the sdx and nvmexxx part of the disks larger than 100G. Exactly what I need.
I am happy with it, but am eager to learn more from you Gurus 😉
awk grep disk lsblk
My goal is to get the disks greater than 100G from lsblk.
I have it working, but it's awkward. I'm pretty sure it can be shortened. Either by using something totally different than lsblk, or maybe I can filter human readable numbers directly with awk.
Here's what I put together:
lsblk | grep disk | awk 'print$1,$4' | grep G | sed 's/.$//' | awk 'if($2>100)print$1'
It outputs only the sdx and nvmexxx part of the disks larger than 100G. Exactly what I need.
I am happy with it, but am eager to learn more from you Gurus 😉
awk grep disk lsblk
awk grep disk lsblk
edited Aug 1 at 18:52
Jeff Schaller♦
51.5k11 gold badges76 silver badges171 bronze badges
51.5k11 gold badges76 silver badges171 bronze badges
asked Aug 1 at 10:08
chalybeumchalybeum
831 silver badge7 bronze badges
831 silver badge7 bronze badges
between 100-999GB and larger than 100T, but nothing between 1-99T, i presume? (terabytes~)
– hanshenrik
Aug 2 at 21:13
Yes that is one flaw that slipped my attention and was already discussed in the answers. I therefore accepted the answer to do the filter based on byte size instead of human readable. If you of another method I'll be happy to learn about that to.
– chalybeum
Aug 2 at 21:47
add a comment
|
between 100-999GB and larger than 100T, but nothing between 1-99T, i presume? (terabytes~)
– hanshenrik
Aug 2 at 21:13
Yes that is one flaw that slipped my attention and was already discussed in the answers. I therefore accepted the answer to do the filter based on byte size instead of human readable. If you of another method I'll be happy to learn about that to.
– chalybeum
Aug 2 at 21:47
between 100-999GB and larger than 100T, but nothing between 1-99T, i presume? (terabytes~)
– hanshenrik
Aug 2 at 21:13
between 100-999GB and larger than 100T, but nothing between 1-99T, i presume? (terabytes~)
– hanshenrik
Aug 2 at 21:13
Yes that is one flaw that slipped my attention and was already discussed in the answers. I therefore accepted the answer to do the filter based on byte size instead of human readable. If you of another method I'll be happy to learn about that to.
– chalybeum
Aug 2 at 21:47
Yes that is one flaw that slipped my attention and was already discussed in the answers. I therefore accepted the answer to do the filter based on byte size instead of human readable. If you of another method I'll be happy to learn about that to.
– chalybeum
Aug 2 at 21:47
add a comment
|
3 Answers
3
active
oldest
votes
You can specify the form of output you want from lsblk
:
% lsblk -nblo NAME,SIZE
mmcblk0 15931539456
mmcblk0p1 268435456
mmcblk0p2 15662038528
Options used:
-b, --bytes
Print the SIZE column in bytes rather than in human-readable format.
-l, --list
Use the list output format.
-n, --noheadings
Do not print a header line.
-o, --output list
Specify which output columns to print. Use --help to get a list of all supported
columns.
Then the filtering is easier:
% lsblk -nblo NAME,SIZE | awk '$2 > 4*2^30 print $1' # greater than 4 GiB
mmcblk0
mmcblk0p2
In your case, that'd be 100*2^30
for 100GiB or 100e9
/1e11
for 100GB.
Uhhh, that's clever! Weeding out what's not needed in the first place. One question: You're using x*2**30 just for consistency with the bytes? Would there be drawback to use s.th. like 10**3?
– chalybeum
Aug 1 at 10:44
@chalybeum yes, for bytes. No, you can use 10**9. The values don't differ all much.
– muru
Aug 1 at 10:50
Note that OP is filtering out partitions in the one-liner.
– UncleCarl
Aug 1 at 19:59
@UncleCarl noted
– muru
Aug 1 at 20:00
1
Note that in this particular case of 100G boundary awk could also be shortened toegrep 'd12,'
to remove lines with <12 digits in a sequence. Awk is of course more universal.
– Gnudiff
Aug 2 at 7:04
|
show 2 more comments
You can also tell lsblk
to output in JSON format and do the filtering with jq
:
$ lsblk -Jb | jq -r '..|select(.size? >= 1e11).name'
sda
sda2
Or:
$ lsblk -Jb | jq -r '..|select(.type? == "disk" and .size? >= 1e11).name'
sda
To limit to entries of type disk
.
(1e11
being 100 GB. Replace with 107374182400
(or 100*1024*1024*1024
) for 100 GiB. Because of rounding, lsblk
itself without -b
reports 100G for sizes ranging from about 99.9278 to 100.0488 GiB (for some reason))
With lsblk -OJb
, lsblk
reports all available information which lets you do a more fined-grained selection or output more or more relevant information.
You could also get the information directly from /sys
. With zsh
:
$ printf '%sn' /sys/class/block/*(e'[(($(<$REPLY/size) * 512 >= 1e11))]':t)
sda
sda2
This is a true answer from a Guru, no one will be able to read it. :D
– Archemar
Aug 1 at 14:50
I take this as a nice to know. But at this stage of my journey in bash I don't want to introduce further complexity by using yet another tool.
– chalybeum
Aug 2 at 6:13
That's a nice application ofjq
(which I learned about only some months ago).
– Dubu
Aug 2 at 9:47
add a comment
|
try
lsblk| awk '$4 ~ /G$/ && $4+0 > 100 print $1'
this will grep and filter at same time.
$4 ~ /G$/
get filed with size in G$4+0 > 100
get size over 100Gprint $1
print NAME
as a rule you should never need to use grep
and awk
in same pipe.
to get only disk (and no partition) : awk filtering
lsblk| awk '$4 ~ /G$/ && $4+0 > 100 && $6 == "disk" print $1'
where
$6 == "disk"
select only column with disk
to get only disk (and no partition) : lsblk filtering
lsblk --nodeps| awk '$4 ~ /G$/ && $4+0 > 100 print $1'
where
--nodeps
: -d, --nodeps don't print slaves or holders
Almost there. It still prints partitions. But I think I can get behind that when I have a bit free time.
– chalybeum
Aug 1 at 10:34
1
@chalybeum I fixed that, same filtering trick can be applied to muru's answer.
– Archemar
Aug 1 at 12:36
(Though I'd probably use the--no-deps
option, in keeping with the general style of that answer)
– muru
Aug 1 at 13:00
2
I'm afraid this will fail to catch disks whose size is shown in terabytes (or bigger units).
– fra-san
Aug 1 at 15:11
@fra-san fair point and is also true for my original solution. So I'm taking the disk filter bit from here and put it in the byte conversion.
– chalybeum
Aug 2 at 6:10
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/4.0/"u003ecc by-sa 4.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%2f533331%2fcan-i-shorten-this-filter-that-finds-disk-sizes-over-100g%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can specify the form of output you want from lsblk
:
% lsblk -nblo NAME,SIZE
mmcblk0 15931539456
mmcblk0p1 268435456
mmcblk0p2 15662038528
Options used:
-b, --bytes
Print the SIZE column in bytes rather than in human-readable format.
-l, --list
Use the list output format.
-n, --noheadings
Do not print a header line.
-o, --output list
Specify which output columns to print. Use --help to get a list of all supported
columns.
Then the filtering is easier:
% lsblk -nblo NAME,SIZE | awk '$2 > 4*2^30 print $1' # greater than 4 GiB
mmcblk0
mmcblk0p2
In your case, that'd be 100*2^30
for 100GiB or 100e9
/1e11
for 100GB.
Uhhh, that's clever! Weeding out what's not needed in the first place. One question: You're using x*2**30 just for consistency with the bytes? Would there be drawback to use s.th. like 10**3?
– chalybeum
Aug 1 at 10:44
@chalybeum yes, for bytes. No, you can use 10**9. The values don't differ all much.
– muru
Aug 1 at 10:50
Note that OP is filtering out partitions in the one-liner.
– UncleCarl
Aug 1 at 19:59
@UncleCarl noted
– muru
Aug 1 at 20:00
1
Note that in this particular case of 100G boundary awk could also be shortened toegrep 'd12,'
to remove lines with <12 digits in a sequence. Awk is of course more universal.
– Gnudiff
Aug 2 at 7:04
|
show 2 more comments
You can specify the form of output you want from lsblk
:
% lsblk -nblo NAME,SIZE
mmcblk0 15931539456
mmcblk0p1 268435456
mmcblk0p2 15662038528
Options used:
-b, --bytes
Print the SIZE column in bytes rather than in human-readable format.
-l, --list
Use the list output format.
-n, --noheadings
Do not print a header line.
-o, --output list
Specify which output columns to print. Use --help to get a list of all supported
columns.
Then the filtering is easier:
% lsblk -nblo NAME,SIZE | awk '$2 > 4*2^30 print $1' # greater than 4 GiB
mmcblk0
mmcblk0p2
In your case, that'd be 100*2^30
for 100GiB or 100e9
/1e11
for 100GB.
Uhhh, that's clever! Weeding out what's not needed in the first place. One question: You're using x*2**30 just for consistency with the bytes? Would there be drawback to use s.th. like 10**3?
– chalybeum
Aug 1 at 10:44
@chalybeum yes, for bytes. No, you can use 10**9. The values don't differ all much.
– muru
Aug 1 at 10:50
Note that OP is filtering out partitions in the one-liner.
– UncleCarl
Aug 1 at 19:59
@UncleCarl noted
– muru
Aug 1 at 20:00
1
Note that in this particular case of 100G boundary awk could also be shortened toegrep 'd12,'
to remove lines with <12 digits in a sequence. Awk is of course more universal.
– Gnudiff
Aug 2 at 7:04
|
show 2 more comments
You can specify the form of output you want from lsblk
:
% lsblk -nblo NAME,SIZE
mmcblk0 15931539456
mmcblk0p1 268435456
mmcblk0p2 15662038528
Options used:
-b, --bytes
Print the SIZE column in bytes rather than in human-readable format.
-l, --list
Use the list output format.
-n, --noheadings
Do not print a header line.
-o, --output list
Specify which output columns to print. Use --help to get a list of all supported
columns.
Then the filtering is easier:
% lsblk -nblo NAME,SIZE | awk '$2 > 4*2^30 print $1' # greater than 4 GiB
mmcblk0
mmcblk0p2
In your case, that'd be 100*2^30
for 100GiB or 100e9
/1e11
for 100GB.
You can specify the form of output you want from lsblk
:
% lsblk -nblo NAME,SIZE
mmcblk0 15931539456
mmcblk0p1 268435456
mmcblk0p2 15662038528
Options used:
-b, --bytes
Print the SIZE column in bytes rather than in human-readable format.
-l, --list
Use the list output format.
-n, --noheadings
Do not print a header line.
-o, --output list
Specify which output columns to print. Use --help to get a list of all supported
columns.
Then the filtering is easier:
% lsblk -nblo NAME,SIZE | awk '$2 > 4*2^30 print $1' # greater than 4 GiB
mmcblk0
mmcblk0p2
In your case, that'd be 100*2^30
for 100GiB or 100e9
/1e11
for 100GB.
edited Aug 1 at 16:06
Stéphane Chazelas
341k59 gold badges671 silver badges1049 bronze badges
341k59 gold badges671 silver badges1049 bronze badges
answered Aug 1 at 10:28
murumuru
46.2k5 gold badges115 silver badges191 bronze badges
46.2k5 gold badges115 silver badges191 bronze badges
Uhhh, that's clever! Weeding out what's not needed in the first place. One question: You're using x*2**30 just for consistency with the bytes? Would there be drawback to use s.th. like 10**3?
– chalybeum
Aug 1 at 10:44
@chalybeum yes, for bytes. No, you can use 10**9. The values don't differ all much.
– muru
Aug 1 at 10:50
Note that OP is filtering out partitions in the one-liner.
– UncleCarl
Aug 1 at 19:59
@UncleCarl noted
– muru
Aug 1 at 20:00
1
Note that in this particular case of 100G boundary awk could also be shortened toegrep 'd12,'
to remove lines with <12 digits in a sequence. Awk is of course more universal.
– Gnudiff
Aug 2 at 7:04
|
show 2 more comments
Uhhh, that's clever! Weeding out what's not needed in the first place. One question: You're using x*2**30 just for consistency with the bytes? Would there be drawback to use s.th. like 10**3?
– chalybeum
Aug 1 at 10:44
@chalybeum yes, for bytes. No, you can use 10**9. The values don't differ all much.
– muru
Aug 1 at 10:50
Note that OP is filtering out partitions in the one-liner.
– UncleCarl
Aug 1 at 19:59
@UncleCarl noted
– muru
Aug 1 at 20:00
1
Note that in this particular case of 100G boundary awk could also be shortened toegrep 'd12,'
to remove lines with <12 digits in a sequence. Awk is of course more universal.
– Gnudiff
Aug 2 at 7:04
Uhhh, that's clever! Weeding out what's not needed in the first place. One question: You're using x*2**30 just for consistency with the bytes? Would there be drawback to use s.th. like 10**3?
– chalybeum
Aug 1 at 10:44
Uhhh, that's clever! Weeding out what's not needed in the first place. One question: You're using x*2**30 just for consistency with the bytes? Would there be drawback to use s.th. like 10**3?
– chalybeum
Aug 1 at 10:44
@chalybeum yes, for bytes. No, you can use 10**9. The values don't differ all much.
– muru
Aug 1 at 10:50
@chalybeum yes, for bytes. No, you can use 10**9. The values don't differ all much.
– muru
Aug 1 at 10:50
Note that OP is filtering out partitions in the one-liner.
– UncleCarl
Aug 1 at 19:59
Note that OP is filtering out partitions in the one-liner.
– UncleCarl
Aug 1 at 19:59
@UncleCarl noted
– muru
Aug 1 at 20:00
@UncleCarl noted
– muru
Aug 1 at 20:00
1
1
Note that in this particular case of 100G boundary awk could also be shortened to
egrep 'd12,'
to remove lines with <12 digits in a sequence. Awk is of course more universal.– Gnudiff
Aug 2 at 7:04
Note that in this particular case of 100G boundary awk could also be shortened to
egrep 'd12,'
to remove lines with <12 digits in a sequence. Awk is of course more universal.– Gnudiff
Aug 2 at 7:04
|
show 2 more comments
You can also tell lsblk
to output in JSON format and do the filtering with jq
:
$ lsblk -Jb | jq -r '..|select(.size? >= 1e11).name'
sda
sda2
Or:
$ lsblk -Jb | jq -r '..|select(.type? == "disk" and .size? >= 1e11).name'
sda
To limit to entries of type disk
.
(1e11
being 100 GB. Replace with 107374182400
(or 100*1024*1024*1024
) for 100 GiB. Because of rounding, lsblk
itself without -b
reports 100G for sizes ranging from about 99.9278 to 100.0488 GiB (for some reason))
With lsblk -OJb
, lsblk
reports all available information which lets you do a more fined-grained selection or output more or more relevant information.
You could also get the information directly from /sys
. With zsh
:
$ printf '%sn' /sys/class/block/*(e'[(($(<$REPLY/size) * 512 >= 1e11))]':t)
sda
sda2
This is a true answer from a Guru, no one will be able to read it. :D
– Archemar
Aug 1 at 14:50
I take this as a nice to know. But at this stage of my journey in bash I don't want to introduce further complexity by using yet another tool.
– chalybeum
Aug 2 at 6:13
That's a nice application ofjq
(which I learned about only some months ago).
– Dubu
Aug 2 at 9:47
add a comment
|
You can also tell lsblk
to output in JSON format and do the filtering with jq
:
$ lsblk -Jb | jq -r '..|select(.size? >= 1e11).name'
sda
sda2
Or:
$ lsblk -Jb | jq -r '..|select(.type? == "disk" and .size? >= 1e11).name'
sda
To limit to entries of type disk
.
(1e11
being 100 GB. Replace with 107374182400
(or 100*1024*1024*1024
) for 100 GiB. Because of rounding, lsblk
itself without -b
reports 100G for sizes ranging from about 99.9278 to 100.0488 GiB (for some reason))
With lsblk -OJb
, lsblk
reports all available information which lets you do a more fined-grained selection or output more or more relevant information.
You could also get the information directly from /sys
. With zsh
:
$ printf '%sn' /sys/class/block/*(e'[(($(<$REPLY/size) * 512 >= 1e11))]':t)
sda
sda2
This is a true answer from a Guru, no one will be able to read it. :D
– Archemar
Aug 1 at 14:50
I take this as a nice to know. But at this stage of my journey in bash I don't want to introduce further complexity by using yet another tool.
– chalybeum
Aug 2 at 6:13
That's a nice application ofjq
(which I learned about only some months ago).
– Dubu
Aug 2 at 9:47
add a comment
|
You can also tell lsblk
to output in JSON format and do the filtering with jq
:
$ lsblk -Jb | jq -r '..|select(.size? >= 1e11).name'
sda
sda2
Or:
$ lsblk -Jb | jq -r '..|select(.type? == "disk" and .size? >= 1e11).name'
sda
To limit to entries of type disk
.
(1e11
being 100 GB. Replace with 107374182400
(or 100*1024*1024*1024
) for 100 GiB. Because of rounding, lsblk
itself without -b
reports 100G for sizes ranging from about 99.9278 to 100.0488 GiB (for some reason))
With lsblk -OJb
, lsblk
reports all available information which lets you do a more fined-grained selection or output more or more relevant information.
You could also get the information directly from /sys
. With zsh
:
$ printf '%sn' /sys/class/block/*(e'[(($(<$REPLY/size) * 512 >= 1e11))]':t)
sda
sda2
You can also tell lsblk
to output in JSON format and do the filtering with jq
:
$ lsblk -Jb | jq -r '..|select(.size? >= 1e11).name'
sda
sda2
Or:
$ lsblk -Jb | jq -r '..|select(.type? == "disk" and .size? >= 1e11).name'
sda
To limit to entries of type disk
.
(1e11
being 100 GB. Replace with 107374182400
(or 100*1024*1024*1024
) for 100 GiB. Because of rounding, lsblk
itself without -b
reports 100G for sizes ranging from about 99.9278 to 100.0488 GiB (for some reason))
With lsblk -OJb
, lsblk
reports all available information which lets you do a more fined-grained selection or output more or more relevant information.
You could also get the information directly from /sys
. With zsh
:
$ printf '%sn' /sys/class/block/*(e'[(($(<$REPLY/size) * 512 >= 1e11))]':t)
sda
sda2
edited Aug 2 at 20:52
answered Aug 1 at 14:32
Stéphane ChazelasStéphane Chazelas
341k59 gold badges671 silver badges1049 bronze badges
341k59 gold badges671 silver badges1049 bronze badges
This is a true answer from a Guru, no one will be able to read it. :D
– Archemar
Aug 1 at 14:50
I take this as a nice to know. But at this stage of my journey in bash I don't want to introduce further complexity by using yet another tool.
– chalybeum
Aug 2 at 6:13
That's a nice application ofjq
(which I learned about only some months ago).
– Dubu
Aug 2 at 9:47
add a comment
|
This is a true answer from a Guru, no one will be able to read it. :D
– Archemar
Aug 1 at 14:50
I take this as a nice to know. But at this stage of my journey in bash I don't want to introduce further complexity by using yet another tool.
– chalybeum
Aug 2 at 6:13
That's a nice application ofjq
(which I learned about only some months ago).
– Dubu
Aug 2 at 9:47
This is a true answer from a Guru, no one will be able to read it. :D
– Archemar
Aug 1 at 14:50
This is a true answer from a Guru, no one will be able to read it. :D
– Archemar
Aug 1 at 14:50
I take this as a nice to know. But at this stage of my journey in bash I don't want to introduce further complexity by using yet another tool.
– chalybeum
Aug 2 at 6:13
I take this as a nice to know. But at this stage of my journey in bash I don't want to introduce further complexity by using yet another tool.
– chalybeum
Aug 2 at 6:13
That's a nice application of
jq
(which I learned about only some months ago).– Dubu
Aug 2 at 9:47
That's a nice application of
jq
(which I learned about only some months ago).– Dubu
Aug 2 at 9:47
add a comment
|
try
lsblk| awk '$4 ~ /G$/ && $4+0 > 100 print $1'
this will grep and filter at same time.
$4 ~ /G$/
get filed with size in G$4+0 > 100
get size over 100Gprint $1
print NAME
as a rule you should never need to use grep
and awk
in same pipe.
to get only disk (and no partition) : awk filtering
lsblk| awk '$4 ~ /G$/ && $4+0 > 100 && $6 == "disk" print $1'
where
$6 == "disk"
select only column with disk
to get only disk (and no partition) : lsblk filtering
lsblk --nodeps| awk '$4 ~ /G$/ && $4+0 > 100 print $1'
where
--nodeps
: -d, --nodeps don't print slaves or holders
Almost there. It still prints partitions. But I think I can get behind that when I have a bit free time.
– chalybeum
Aug 1 at 10:34
1
@chalybeum I fixed that, same filtering trick can be applied to muru's answer.
– Archemar
Aug 1 at 12:36
(Though I'd probably use the--no-deps
option, in keeping with the general style of that answer)
– muru
Aug 1 at 13:00
2
I'm afraid this will fail to catch disks whose size is shown in terabytes (or bigger units).
– fra-san
Aug 1 at 15:11
@fra-san fair point and is also true for my original solution. So I'm taking the disk filter bit from here and put it in the byte conversion.
– chalybeum
Aug 2 at 6:10
add a comment
|
try
lsblk| awk '$4 ~ /G$/ && $4+0 > 100 print $1'
this will grep and filter at same time.
$4 ~ /G$/
get filed with size in G$4+0 > 100
get size over 100Gprint $1
print NAME
as a rule you should never need to use grep
and awk
in same pipe.
to get only disk (and no partition) : awk filtering
lsblk| awk '$4 ~ /G$/ && $4+0 > 100 && $6 == "disk" print $1'
where
$6 == "disk"
select only column with disk
to get only disk (and no partition) : lsblk filtering
lsblk --nodeps| awk '$4 ~ /G$/ && $4+0 > 100 print $1'
where
--nodeps
: -d, --nodeps don't print slaves or holders
Almost there. It still prints partitions. But I think I can get behind that when I have a bit free time.
– chalybeum
Aug 1 at 10:34
1
@chalybeum I fixed that, same filtering trick can be applied to muru's answer.
– Archemar
Aug 1 at 12:36
(Though I'd probably use the--no-deps
option, in keeping with the general style of that answer)
– muru
Aug 1 at 13:00
2
I'm afraid this will fail to catch disks whose size is shown in terabytes (or bigger units).
– fra-san
Aug 1 at 15:11
@fra-san fair point and is also true for my original solution. So I'm taking the disk filter bit from here and put it in the byte conversion.
– chalybeum
Aug 2 at 6:10
add a comment
|
try
lsblk| awk '$4 ~ /G$/ && $4+0 > 100 print $1'
this will grep and filter at same time.
$4 ~ /G$/
get filed with size in G$4+0 > 100
get size over 100Gprint $1
print NAME
as a rule you should never need to use grep
and awk
in same pipe.
to get only disk (and no partition) : awk filtering
lsblk| awk '$4 ~ /G$/ && $4+0 > 100 && $6 == "disk" print $1'
where
$6 == "disk"
select only column with disk
to get only disk (and no partition) : lsblk filtering
lsblk --nodeps| awk '$4 ~ /G$/ && $4+0 > 100 print $1'
where
--nodeps
: -d, --nodeps don't print slaves or holders
try
lsblk| awk '$4 ~ /G$/ && $4+0 > 100 print $1'
this will grep and filter at same time.
$4 ~ /G$/
get filed with size in G$4+0 > 100
get size over 100Gprint $1
print NAME
as a rule you should never need to use grep
and awk
in same pipe.
to get only disk (and no partition) : awk filtering
lsblk| awk '$4 ~ /G$/ && $4+0 > 100 && $6 == "disk" print $1'
where
$6 == "disk"
select only column with disk
to get only disk (and no partition) : lsblk filtering
lsblk --nodeps| awk '$4 ~ /G$/ && $4+0 > 100 print $1'
where
--nodeps
: -d, --nodeps don't print slaves or holders
edited Aug 1 at 13:15
answered Aug 1 at 10:19
ArchemarArchemar
21.8k9 gold badges42 silver badges78 bronze badges
21.8k9 gold badges42 silver badges78 bronze badges
Almost there. It still prints partitions. But I think I can get behind that when I have a bit free time.
– chalybeum
Aug 1 at 10:34
1
@chalybeum I fixed that, same filtering trick can be applied to muru's answer.
– Archemar
Aug 1 at 12:36
(Though I'd probably use the--no-deps
option, in keeping with the general style of that answer)
– muru
Aug 1 at 13:00
2
I'm afraid this will fail to catch disks whose size is shown in terabytes (or bigger units).
– fra-san
Aug 1 at 15:11
@fra-san fair point and is also true for my original solution. So I'm taking the disk filter bit from here and put it in the byte conversion.
– chalybeum
Aug 2 at 6:10
add a comment
|
Almost there. It still prints partitions. But I think I can get behind that when I have a bit free time.
– chalybeum
Aug 1 at 10:34
1
@chalybeum I fixed that, same filtering trick can be applied to muru's answer.
– Archemar
Aug 1 at 12:36
(Though I'd probably use the--no-deps
option, in keeping with the general style of that answer)
– muru
Aug 1 at 13:00
2
I'm afraid this will fail to catch disks whose size is shown in terabytes (or bigger units).
– fra-san
Aug 1 at 15:11
@fra-san fair point and is also true for my original solution. So I'm taking the disk filter bit from here and put it in the byte conversion.
– chalybeum
Aug 2 at 6:10
Almost there. It still prints partitions. But I think I can get behind that when I have a bit free time.
– chalybeum
Aug 1 at 10:34
Almost there. It still prints partitions. But I think I can get behind that when I have a bit free time.
– chalybeum
Aug 1 at 10:34
1
1
@chalybeum I fixed that, same filtering trick can be applied to muru's answer.
– Archemar
Aug 1 at 12:36
@chalybeum I fixed that, same filtering trick can be applied to muru's answer.
– Archemar
Aug 1 at 12:36
(Though I'd probably use the
--no-deps
option, in keeping with the general style of that answer)– muru
Aug 1 at 13:00
(Though I'd probably use the
--no-deps
option, in keeping with the general style of that answer)– muru
Aug 1 at 13:00
2
2
I'm afraid this will fail to catch disks whose size is shown in terabytes (or bigger units).
– fra-san
Aug 1 at 15:11
I'm afraid this will fail to catch disks whose size is shown in terabytes (or bigger units).
– fra-san
Aug 1 at 15:11
@fra-san fair point and is also true for my original solution. So I'm taking the disk filter bit from here and put it in the byte conversion.
– chalybeum
Aug 2 at 6:10
@fra-san fair point and is also true for my original solution. So I'm taking the disk filter bit from here and put it in the byte conversion.
– chalybeum
Aug 2 at 6:10
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%2f533331%2fcan-i-shorten-this-filter-that-finds-disk-sizes-over-100g%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
between 100-999GB and larger than 100T, but nothing between 1-99T, i presume? (terabytes~)
– hanshenrik
Aug 2 at 21:13
Yes that is one flaw that slipped my attention and was already discussed in the answers. I therefore accepted the answer to do the filter based on byte size instead of human readable. If you of another method I'll be happy to learn about that to.
– chalybeum
Aug 2 at 21:47