Uim Cdm Alarm Disk Clear Drive Availabel Again
In this commodity I will share different commands and methods to check disk space in Linux. Most of these commands and methods should exist available on about Linux distros. You can too utilise these commands to create a script to monitor disk size usage and create alarms or transport mails (this would demand a mail server).
one. Check segmentation size using df command
df
is ane of the well-nigh used control to check space of available partitions on the Linux setup. You can apply df
wih -Th
to print the division type and the partition size in man readable format. This command will bear witness yous the full available, used and free space per partition.
You lot tin likewise utilize other arguments such as -i to impress the available, used and costless inode count per partitioning:
You tin can check the homo page of df command for other supported arguments to cheque disk infinite in dissimilar formats.
2. Check deejay space using fdisk utility
fdisk
is some other very handy utility for organisation administrators. fdisk is a user interactive program mostly used for cosmos and manipulation of division tables such as creating, deleting, modifying partitions. Only we can also use this utility to list the available disks continued to the Linux organization along with the respective disk size.
Here is a snippet of output from control "fdisk -l
"
Every bit yous can meet from the output, I have a disk /dev/sda
with a size of 15GB. The output also shows more details nearly this disks wherein it contains two partitions /dev/sda1
and /dev/sda2
.
The output of fdisk -l
tin can exist quiet long so if you simply wish to cheque the disk space then y'all can apply this command:
~]# fdisk -l | awk '$one=="Disk" && $2 ~ /^\/dev\/.*/ {print $2 $iii $4}' /dev/sda:15GiB, /dev/sdb:8GiB, /dev/mapper/rhel-root:14GiB, /dev/mapper/rhel-swap:512MiB,
Here I have combined fdisk
with awk
to just impress required sections. So I take two disks with 15GB and 8GB each, while I have two LVM partitions which are near probable part of these disks with a size of 14GB and 512MB.
3. Check disk space using parted utility
parted
is another culling to fdisk
and is also used for manipulating disk partitions. It is useful for creating space for new operating systems, reorganising disk usage, and copying information to new difficult disks.
Similar to fdisk
, we tin utilize parted -l
to list all the available disks along with their respective size:
If you compare the output of parted
with fdisk
, here we simply become the bachelor deejay and their size and the LVM details are missing which is a adept thing every bit we only wanted to check the disk space.
Nosotros tin also utilize awk
with parted to further just print required output:
~]# parted -l | awk '$ane=="Disk" && $2 ~ /^\/dev\/.*/ {impress $ii $3 $4}' /dev/sda:16.1GB /dev/sdb:8590MB
iv. Check file size using du command
du
is another wonderful utility to cheque the size of files recursively in Linux. It can besides summarize deejay usage of the set of files, recursively for directories. du
is a very versatile tool and supports multiple arguments which you can use based on your requirement. Some of the most used arguments are:
-a, --all write counts for all files, non just directories -c, --total produce a g total -d, --max-depth=N print the total for a directory (or file, with --all) only if information technology is N or fewer levels below the com‐ mand line argument; --max-depth=0 is the same as --summarize -h, --homo-readable print sizes in human readable format (eastward.g., 1K 234M 2G) -s, --summarize display merely a total for each argument -t, --threshold=SIZE exclude entries smaller than SIZE if positive, or entries greater than SIZE if negative
Here are some example demonstrating dissimilar scenarios to check file organisation size using du
command:
EG-1: Check size of all the files under a sectionalization recursively
I accept a carve up partition for /kick
:
~]# df -h /kicking/ Filesystem Size Used Avail Use% Mounted on /dev/sda1 488M 123M 330M 28% /kick
And so let's check the size of all the files under /kick
using du -h /kicking/*
EG-2: Print full summary of size of files in a segmentation or directory
We can utilise du -c
to print a full or summary of all the file size under provided directory or division.
~]# du -sch /etc/iscsi/* 4.0K /etc/iscsi/initiatorname.iscsi 16K /etc/iscsi/iscsid.conf 20K total
So the total file size nether /etc/iscsi
directory is 20K
. Yous can too utilize this control under root i.e. du -sch /*
to become a summary and total size of all the files nether /
EG-3: Sort the output based on file size
By default the du command volition impress the size of the file based on the commencement available directory or sub-directory. So the output is not sorted and it can be a dull task to get through the long list. We can combine du
with sort
command exercise sort the output based on the file size.
Here nosotros have used du
with sort -hr
where -h
is used to compare human readable numbers such as 2K, 1G, 4M etc while -r
is used to reverse the guild of search.
EG-4: Impress file size larger than specified size
By default du will impress the size of every file found nether a partition or directory. We can add a threshold to print files higher than a sure size.
For example hither we are printing the files with size college than 1MB under /var/log
~]# du -ach -t 1M /var/log/* | sort -hr 19M total viii.9M /var/log/anaconda 4.2M /var/log/anaconda/lvm.log 3.2M /var/log/anaconda/journal.log 1.9M /var/log/dnf.librepo.log ane.6M /var/log/audit/audit.log 1.6M /var/log/audit
For more listing of supported options check the homo page of du command.
5. Check disk size using lsblk control
lsblk
lists information about all available or the specified block devices. The lsblk
command reads the sysfs filesystem and udev db to gather information. If the udev db is not available or lsblk is compiled without udev support than it tries to read LABELs, UUIDs and filesystem types from the block device.
Nosotros tin can utilise lsblk
with -o Listing
or --output LIST
to get desired columns based on the value of Listing. Use lsblk --help
to get a list of all supported columns.
We will use name, fstype, size, mountpoint Listing for our instance. Although using only size and name was enough but to give more detailed output I am using additional listing options.
6. Impress disk size using blockdev
We can use blockdev
command to print a report for the specified device. It is possible to give multiple devices. If none is given, all devices which appear in /proc/partitions
are shown. Note that the partition StartSec
is in 512-byte sectors.
You can also employ following commands:
# returns size in bytes. # blockdev --getsize64 /dev/sda # returns size in 512-byte sectors. # blockdev --getsz /dev/sda
7. Bank check disk size and details using lshw control
lshw is a minor tool to extract detailed data on the hardware configuration of the machine. It can report exact retentivity configuration, firmware version, mainboard configuration, CPU version and speed, cache configuration, bus speed, etc. on DMI-capable x86 or IA-64 systems and on some PowerPC machines.
By default lshw will give you a huge output, we can limit that past but printing the information for a specified form such as "disk
". To get the list of attached disks and their details such every bit size we will utilize lshw -c disk
.
Here is an output snippet from my Linux node:
Nosotros can farther improve the output using lshw
with grep
:
~]# lshw -c disk | grep -E "logical name|size:" logical proper name: /dev/sda size: 15GiB (16GB) logical name: /dev/sdb size: 8GiB (8589MB)
viii. Checking disk size from the arrangement logs
Nosotros tin can besides use system logs such as boot logs using dmesg
or journalctl -b
and try to search for corresponding deejay to get more information. The take hold of is that you lot should know the disk name unlike other methods which we discussed where we were able to check size of all the available disks without prior knowledge of disk proper name.
For example, here I am searching for all instance of sda
disk in boot logs using dmesg
:
Similarly we tin search for any other disk, such as sdb
:
~]# dmesg | grep sdb [ 3.230296] sd iii:0:0:0: [sdb] 16777216 512-byte logical blocks: (8.59 GB/eight.00 GiB) [ 3.230304] sd 3:0:0:0: [sdb] Write Protect is off [ 3.230306] sd 3:0:0:0: [sdb] Mode Sense: 00 3a 00 00 [ 3.230316] sd 3:0:0:0: [sdb] Write cache: enabled, read enshroud: enabled, doesn't support DPO or FUA [ 3.238804] sdb: sdb1 [ 3.239698] sd 3:0:0:0: [sdb] Fastened SCSI disk
You may likewise try grepping blocks
in dmesg
output which can list the available disk with their size:
~]# dmesg | grep blocks [ three.228462] sd 2:0:0:0: [sda] 31457280 512-byte logical blocks: (16.i GB/15.0 GiB) [ 3.230296] sd iii:0:0:0: [sdb] 16777216 512-byte logical blocks: (8.59 GB/eight.00 GiB)
9. Check disk size using lsscsi command
lsscsi uses data in sysfs (Linux kernel serial 2.half dozen and later) to list SCSI devices (or hosts) currently attached to the arrangement. Many non-SCSI storage devices (but not all) used the SCSI subsystem in Linux. In lsscsi version 0.xxx support was added to listing NVMe devices.
We can use lsscsi --size
to list all the connected storage devices along with their size as shown below:
~]# lsscsi --size [0:0:0:0] cd/dvd VBOX CD-ROM one.0 /dev/sr0 - [i:0:0:0] cd/dvd VBOX CD-ROM 1.0 /dev/sr1 - [2:0:0:0] disk ATA VBOX HARDDISK 1.0 /dev/sda 16.1GB [3:0:0:0] disk ATA VBOX HARDDISK 1.0 /dev/sdb 8.58GB
10. Print deejay size using sfdisk
sfdisk
is over again an culling to fdisk
and parted
utility. Ane of the major difference between fdisk
and sfdisk
is that sfdisk
reads and writes partition tables, but is non interactive like fdisk
or cfdisk
(it reads input from a file or stdin). It's generally used for partitioning drives from scripts or for partition tabular array backup and recovery.
But it tin can also be used to check the disk size using sfdisk -l
, sample output:
Summary
In this article we explored different commands and methods which tin can be used to check deejay size (used/bachelor/total) in Linux. You can hands utilize most of these commands and methods into a script to regularly monitor the bachelor disk space and enhance alert when threshold is reached. At that place are some more commands such equally udisks, hwinfo which can be used to collect similar information but they are distro dependent and may not exist available with all the Linux distributions hence I have skipped them.
Source: https://www.golinuxcloud.com/linux-check-disk-space/
Post a Comment for "Uim Cdm Alarm Disk Clear Drive Availabel Again"