LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > CentOS
User Name
Password
CentOS This forum is for the discussion of CentOS Linux. Note: This forum does not have any official participation.

Notices


Reply
  Search this Thread
Old 10-29-2019, 03:43 AM   #1
Jokoenom
LQ Newbie
 
Registered: Oct 2019
Posts: 4

Rep: Reputation: Disabled
Question How to find disk usage more than 70% and find largest in there?


Dear friends

I have a problem, how to find disk usage more than 70%, can be found forwarded by finding the largest file in them, then displaying it?

Please help me with the shell script, thanks for the attention.
 
Old 10-29-2019, 03:47 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,309
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
Welcome.

That would be done using some combination of du and df plus either AWK or various bashisms.

See

Code:
man du
man df
What have you tried so far and where are you stuck?
 
Old 10-29-2019, 05:25 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,849

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
there was a similar thread here a few weeks ago, ncdu was suggested.
 
Old 10-29-2019, 06:34 AM   #4
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
I'm sure there have been many similar threads over the years.

Jokoenom,

Welcome to LQ. Please understand that all LQ members, yourself included are free volunteers, we're not paid support.

We're happy to help, but the way this forum works best is if you work along side and solve this problem, with our assistance. The few reasons for this, among many others, are that you'll learn and be capable of doing more and more over time, plus you'll also stand to gain a resolution of your problem or project along exactly the lines you need or would like. Because if someone emits out a copy of an old script that they used, it may have flaws, special cases/directories, or considerations that has nothing to do with your setup. Therefore something like that may cause more problems/confusion than it's worth.

So for starters, do you know anything about shell scripting? And what language would you consider to use, if not just bash?

Here are some BASH references, and in my signature, these references are in a blog, but also that blog covers some techniques for writing and working through shell scripts, which you may find useful, one of the most important statements says something like, "anything you can type into a command line, you can put into a bash script", please take the time to review and update us what you have in mind moving forwards:

Bash Beginners Guide
Advanced Bash Guide
My Bash Blog
 
Old 10-30-2019, 09:54 AM   #5
Jokoenom
LQ Newbie
 
Registered: Oct 2019
Posts: 4

Original Poster
Rep: Reputation: Disabled
I have tried this script, but I have not found exactly what I meant, what is needed is only to find the largest file from the filesystem which has 70% utilization.
Attached Thumbnails
Click image for larger version

Name:	SAVE_20191030_215216.jpeg
Views:	170
Size:	122.6 KB
ID:	31718  
 
Old 10-30-2019, 10:05 AM   #6
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,309
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
AWK is a scripting language. So the script has to be within quotes. Here it is within single quotes ' so that the field numbers do not need to be escaped.

Code:
df -Ph | \
awk '{sub("%","",$5);} $5+1>90 {printf("%02d%\t%s\n",$5,$6);f++} END{if(f){exit(1)}}' \
&& echo OK || echo OMGWTFBBQ
The sub() removes the % from the fifth field.

The $5+1 ensures that the field comparison will be as a number, not a string.

The f is a flag and causes the AWK script to later exit with a non-zero status.

Finding the largest file would be a second script.

Last edited by Turbocapitalist; 10-30-2019 at 10:07 AM.
 
Old 10-30-2019, 10:32 AM   #7
Jokoenom
LQ Newbie
 
Registered: Oct 2019
Posts: 4

Original Poster
Rep: Reputation: Disabled
How can I display the largest file in the same script?

Finding the largest file will be the second script.

Can it be combined into the first script sir? So if there is a fileusage of more than xx% then look for and display the largest file with the head -10? thank you very much, iam sorry for bothering you.

Attached Thumbnails
Click image for larger version

Name:	anseng.png
Views:	135
Size:	35.4 KB
ID:	31719  
 
Old 10-30-2019, 10:43 AM   #8
Jokoenom
LQ Newbie
 
Registered: Oct 2019
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Jokoenom View Post
Finding the largest file will be the second script.

Can it be combined into the first script sir? So if there is a fileusage of more than xx% then look for and display the largest file with the head -10? thank you very much, iam sorry for bothering you.

[root@localhost ~]# df -Ph | awk '{sub("%","",$5);} $5+1>10 {printf("%02d%\t%s\n",$5,$6);f++} END{if(f){exit(1)}}' && echo OK || echo OMGWTFBBQ
17% /
14% /boot
OMGWTFBBQ
[root@localhost ~]# df -Ph | awk '{sub("%","",$5);} $5+1>70 {printf("%02d%\t%s\n",$5,$6);f++} END{if(f){exit(1)}}' && echo OK || echo OMGWTFBBQ
OK
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Gab becomes the largest Mastadon node, bringing the largest user contribution to the fediverse LXer Syndicated Linux News 0 07-06-2019 03:20 PM
[SOLVED] How to select more than 1 line,copy those selected more than one line,and paste them. shabariv Linux - Newbie 1 02-02-2015 11:51 AM
"free" shows far more memory usage than summing up application usage kenneho Linux - Server 2 08-06-2010 07:56 AM
grep a file for any interger larger than X and assign largest value to a variable kmkocot Linux - Newbie 5 11-09-2009 05:26 PM
Can I've more than 6 virt consoles (and can I launch more than 2 GUIs simultaneosly)? kornerr Linux - General 6 02-24-2005 02:33 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > CentOS

All times are GMT -5. The time now is 08:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration