Filter df -h to only show 'Mounted on' part - linux

this is the normal output of df -h:
df -h
Filesystem Size Used Avail Capacity iused ifree %iused Mounted on
/dev/disk1s2s1 932Gi 14Gi 823Gi 2% 500637 4293577168 0% /
devfs 193Ki 193Ki 0Bi 100% 673 0 100% /dev
/dev/disk1s5 932Gi 3.0Gi 823Gi 1% 3 8628536760 0% /System/Volumes/VM
/dev/disk1s3 932Gi 367Mi 823Gi 1% 1816 8628536760 0% /System/Volumes/Preboot
/dev/disk1s6 932Gi 4.0Mi 823Gi 1% 20 8628536760 0% /System/Volumes/Update
/dev/disk1s1 932Gi 90Gi 823Gi 10% 789694 8628536760 0% /System/Volumes/Data
map auto_home 0Bi 0Bi 0Bi 100% 0 0 100% /System/Volumes/Data/home
I need to filter it to have:
/
/dev
/System/Volumes/VM
/System/Volumes/Preboot
/System/Volumes/Update
/System/Volumes/Data
/System/Volumes/Data/home
So basically I need only the "mounted on" column of the command df -h.
Any idea?

df --output=target
If you need mount targets, you can also look at findmnt. It has tons of formatting options, the list you want can be done with
$ findmnt --real -O TARGET

Related

Errno 28 No space availble on '/var/tmp/...'

I would like to install algobox for my studies but it is impossible for me to install it or even to update my computer. I looked for it and I saw that it was probably a problem of space in my partition.
I made the command "df -h" to see what was in my score and it displayed this:
Sys. de fichiers Taille Utilisé Dispo Uti% Monté sur
devtmpfs 7,8G 0 7,8G 0% /dev
tmpfs 7,8G 15M 7,8G 1% /dev/shm
tmpfs 7,8G 2,1M 7,8G 1% /run
/dev/nvme0n1p7 69G 66G 0 100% /
tmpfs 7,8G 40K 7,8G 1% /tmp
/dev/loop2 224M 224M 0 100% /var/lib/snapd/snap/code/108
/dev/loop0 999M 999M 0 100% /var/lib/snapd/snap/android-studio/123
/dev/loop1 143M 143M 0 100% /var/lib/snapd/snap/chromium/2105
/dev/loop4 115M 115M 0 100% /var/lib/snapd/snap/core/13741
/dev/nvme0n1p4 976M 247M 663M 28% /boot
/dev/loop5 63M 63M 0 100% /var/lib/snapd/snap/deezer-unofficial-player/11
/dev/nvme0n1p2 96M 46M 51M 48% /boot/efi
/dev/nvme0n1p8 114G 40G 69G 37% /home
/dev/loop7 56M 56M 0 100% /var/lib/snapd/snap/core18/2566
/dev/loop8 64M 64M 0 100% /var/lib/snapd/snap/core20/1623
/dev/loop10 347M 347M 0 100% /var/lib/snapd/snap/gnome-3-38-2004/115
/dev/loop11 176M 176M 0 100% /var/lib/snapd/snap/postman/133
/dev/loop17 151M 151M 0 100% /var/lib/snapd/snap/remmina/5379
/dev/loop18 82M 82M 0 100% /var/lib/snapd/snap/discord/143
/dev/loop19 165M 165M 0 100% /var/lib/snapd/snap/gnome-3-28-1804/161
/dev/loop21 48M 48M 0 100% /var/lib/snapd/snap/snapd/16778
/dev/loop22 92M 92M 0 100% /var/lib/snapd/snap/gtk-common-themes/1535
/dev/loop23 71M 71M 0 100% /var/lib/snapd/snap/core22/275
/dev/loop24 128K 128K 0 100% /var/lib/snapd/snap/bare/5
/dev/loop27 219M 219M 0 100% /var/lib/snapd/snap/gnome-3-34-1804/77
/dev/loop28 415M 415M 0 100% /var/lib/snapd/snap/gnome-42-2204/29
tmpfs 1,6G 88K 1,6G 1% /run/user/1000
The /var/tmp does not seem to be mounted separate from / and it looks you still have 3G free
Sys. de fichiers Taille Utilisé Dispo Uti% Monté sur
/dev/nvme0n1p7 69G 66G 0 100% /
I would suggest running a "df -i" to see the inode utilization at the IUse% column(it must be under 100%) as if you have a lot of small files, each one will utilize one inode and if you are using 100% of inodes you will get the "No space left error".

linux - df command says disk 100% used, but it actually it's not

I have an EC2 instance running jenkins service and almost everyday it stops working saying the disk is full.
So I enter the instance to check and it really says 100% used
$ df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 987M 60K 987M 1% /dev
tmpfs 997M 0 997M 0% /dev/shm
/dev/xvda1 32G 32G 0 100% /
So I use NCDU to check what is occuping the space and it says only 8gb is used.
ncdu 1.10 ~ Use the arrow keys to navigate, press ? for help
--- / -------------------------------------------------------
3.7GiB [##########] /var
1.7GiB [#### ] /home
1.6GiB [#### ] /usr
1.0GiB [## ] swapfile
323.6MiB [ ] /opt
133.8MiB [ ] /lib
47.3MiB [ ] /boot
43.8MiB [ ] /root
23.1MiB [ ] /public
19.8MiB [ ] /lib64
12.3MiB [ ] /sbin
10.7MiB [ ] /etc
7.0MiB [ ] /bin
3.7MiB [ ] /tmp
60.0KiB [ ] /dev
e 16.0KiB [ ] /lost+found
16.0KiB [ ] /.gnupg
12.0KiB [ ] /run
e 4.0KiB [ ] /srv
e 4.0KiB [ ] /selinux
e 4.0KiB [ ] /mnt
e 4.0KiB [ ] /media
e 4.0KiB [ ] /local
e 4.0KiB [ ] /cgroup
. 0.0 B [ ] /proc
0.0 B [ ] /sys
0.0 B [ ] .autorelabel
0.0 B [ ] .autofsck
Total disk usage: 8.6GiB Apparent size: 8.6GiB Items: 379695
Then I reboot the instance and the free space comes back to only 28% used
$ df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 987M 60K 987M 1% /dev
tmpfs 997M 0 997M 0% /dev/shm
/dev/xvda1 32G 8.7G 23G 28% /
What can be causing this problem?
Additional data:
PSTREE
init─┬─acpid
├─agetty
├─amazon-ssm-agen───6*[{amazon-ssm-agen}]
├─atd
├─auditd───{auditd}
├─crond
├─dbus-daemon
├─2*[dhclient]
├─java─┬─sh───sudo───gulp --prod───9*[{gulp --prod}]
│ └─67*[{java}]
├─lvmetad
├─lvmpolld
├─6*[mingetty]
├─rngd
├─rpc.statd
├─rpcbind
├─rsyslogd───3*[{rsyslogd}]
├─2*[sendmail]
├─sshd───sshd───sshd───bash───pstree
├─supervisord───2*[php]
└─udevd───2*[udevd]
CRONTAB
* * * * * cd /home/ec2-user/laravel-prod && php artisan schedule:run >> /dev/null 2>&1
0 1 * * * rm /var/log/jenkins/jenkins.log

Remove Volume Group from a re-pourpsed disk

I have this SSD that was in another Ovirt cluster that I destroyed, and now I'm trying to re-purpose this disk but can't seem to clear it. I have tried wipefs and dd but it still shows up in fdisk -l. How can I clear all lvms from this disk?
sudo fdisk -l
Disk /dev/sda: 3.5 TiB, 3840755982336 bytes, 7501476528 sectors
Disk model: SAMSUNG MZ7LH3T8
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/mmcblk0: 58.25 GiB, 62537072640 bytes, 122142720 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 61C206C7-69A3-4C51-9215-1C0B45E32661
Device Start End Sectors Size Type
/dev/mmcblk0p1 2048 788479 786432 384M Linux filesystem
/dev/mmcblk0p2 788480 1048575 260096 127M EFI System
/dev/mmcblk0p3 1048576 1050623 2048 1M BIOS boot
/dev/mmcblk0p4 1050624 122142686 121092063 57.8G Linux filesystem
[core#h2-master-01 ~]$ sudo lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 3.5T 0 disk
ââgluster_vg_sdc-gluster_thinpool_gluster_vg_sdc_tmeta 253:0 0 15.8G 0 lvm
â ââgluster_vg_sdc-gluster_thinpool_gluster_vg_sdc-tpool 253:2 0 3.5T 0 lvm
â ââgluster_vg_sdc-gluster_thinpool_gluster_vg_sdc 253:3 0 3.5T 1 lvm
â ââgluster_vg_sdc-gluster_lv_data 253:4 0 3.4T 0 lvm
ââgluster_vg_sdc-gluster_thinpool_gluster_vg_sdc_tdata 253:1 0 3.5T 0 lvm
ââgluster_vg_sdc-gluster_thinpool_gluster_vg_sdc-tpool 253:2 0 3.5T 0 lvm
ââgluster_vg_sdc-gluster_thinpool_gluster_vg_sdc 253:3 0 3.5T 1 lvm
ââgluster_vg_sdc-gluster_lv_data 253:4 0 3.4T 0 lvm
mmcblk0 179:0 0 58.2G 0 disk
ââmmcblk0p1 179:1 0 384M 0 part /boot
ââmmcblk0p2 179:2 0 127M 0 part /boot/efi
ââmmcblk0p3 179:3 0 1M 0 part
ââmmcblk0p4 179:4 0 57.8G 0 part /sysroot
mmcblk0boot0 179:8 0 4M 1 disk
mmcblk0boot1 179:16 0 4M 1 disk
[core#h2-master-01 ~]$ sudo lvdisplay
[core#h2-master-01 ~]$ sudo vgdisplay
[core#h2-master-01 ~]$ sudo pvdisplay
wipefs -a /dev/sda with a reboot seemed looks to have cleared the disk. Thanks all!

CPU and HDD information

I searched but I found nothing for my problem.
I would like to have in Linux command line the information about the CPU usage and the local HDDs with formatting text like exactly as the examples below for my program.
These examples are command line outputs on MS-Windows.
I hope it is possible on Linux, too.
Thank you
wmic logicaldisk where drivetype=3 get caption,freespace,size
Caption FreeSpace Size
C: 135314194432 255953203200
D: 126288519168 128033222656
E: 336546639872 1000194015232
F: 162184503296 1000194015232
wmic cpu get loadpercentage
LoadPercentage
4
You won't find anything exactly like the output you provided.
The only option is to use for disk space df:
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/root 73216256 27988724 41485276 41% /
devtmpfs 8170164 0 8170164 0% /dev
tmpfs 8203680 544 8203136 1% /dev/shm
tmpfs 8203680 12004 8191676 1% /run
tmpfs 5120 4 5116 1% /run/lock
tmpfs 8203680 0 8203680 0% /sys/fs/cgroup
/dev/sdb1 482922 83939 374049 19% /boot
and for cpu you have many more options, e.g.
vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 0 11865304 149956 1474172 0 0 53 46 126 707 3 0 96 0 0
or top -b | head:
top - 21:48:43 up 54 min, 1 user, load average: 0.13, 0.17, 0.22
Tasks: 188 total, 1 running, 187 sleeping, 0 stopped, 0 zombie
%Cpu(s): 3.0 us, 0.4 sy, 0.1 ni, 96.5 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 16407364 total, 11848936 free, 2888844 used, 1669584 buff/cache
KiB Swap: 0 total, 0 free, 0 used. 13230972 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 20 0 40544 6440 3780 S 0.0 0.0 0:01.15 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/0
There is no command that gives you a load percentage of the cpu. It's actually impossible to get that with a system call (nor in linux neither in Windows). What you can get is the number of ticks currently executed (for each field, user, system, io,irq idle)..., then call it again a certain amount of time later and calculate it. That way is how work all the commands for reading the cpu percentage.
Here a script bash that gives you that: (just create a file named for example cpu.sh paste this code and execute to see the results)
_estado()
{
cat /proc/stat | grep "cpu " | sed -e 's/ */:/g' -e 's/^cpux//'
}
_ticksconcretos()
{
echo $1 | cut -d ':' -f $2
}
while true ; do
INICIAL=$(_estado)
sleep 1
FINAL=$(_estado)
UsuarioI=$(_ticksconcretos $INICIAL 1)
UsuarioF=$(_ticksconcretos $FINAL 1)
NiceI=$(_ticksconcretos $INICIAL 2)
NiceF=$(_ticksconcretos $FINAL 2)
SistemaI=$(_ticksconcretos $INICIAL 3)
SistemaF=$(_ticksconcretos $FINAL 3)
idleI=$(_ticksconcretos $INICIAL 4)
idleF=$(_ticksconcretos $FINAL 4)
IOI=$(_ticksconcretos $INICIAL 5)
IOF=$(_ticksconcretos $FINAL 5)
IRQI=$(_ticksconcretos $INICIAL 6)
IRQF=$(_ticksconcretos $FINAL 6)
SOFTIRQI=$(_ticksconcretos $INICIAL 7)
SOFTIRQF=$(_ticksconcretos $FINAL 7)
STEALI=$(_ticksconcretos $INICIAL 8)
STEALF=$(_ticksconcretos $FINAL 8)
InactivoF=$(( $idleF + $IOF ))
InactivoI=$(( $idleI + $IOI ))
ActivoI=$(( $UsuarioI + $NiceI + $SistemaI + $IRQI + $SOFTIRQI + $STEALI ))
ActivoF=$(( $UsuarioF + $NiceF + $SistemaF + $IRQF + $SOFTIRQF + $STEALF ))
TOTALI=$(( $ActivoI + $InactivoI ))
TOTALF=$(( $ActivoF + $InactivoF ))
PORC=$(( ( ( ( $TOTALF - $TOTALI ) - ( $InactivoF - $InactivoI ) ) * 100 / ( $TOTALF - $TOTALI ) ) ))
clear
echo "CPU: $PORC %"
done
For the free space You could use something like this:
df -h -x tmpfs -x devtmpfs | awk -F " " '{print $1 " " $4 " " $2}'
wich will give you this output:
Filesystem Free Size
/dev/sda1 16G 25G
/dev/sda5 46G 79G
/dev/sdb8 130G 423G
sda represents the first disk, sda1 the first partition, sda2, the second one etc. you can add (or change) $6 inside the print to get the mount points instead of the partitions, change the order or even more things.

Perl - get free disk space usage on linux

I'm wondering how I can get the value of the second row, 4th column from df ("/"). Here's the output from df:
Filesystem Size Used Avail Use% Mounted on
rootfs 208G 120G 78G 61% /
fakefs 208G 120G 78G 61% /root
fakefs 1.8T 1.3T 552G 70% /home4/user
fakefs 4.0G 1.3G 2.8G 31% /ramdisk/bin
fakefs 4.0G 1.3G 2.8G 31% /ramdisk/etc
fakefs 4.0G 1.3G 2.8G 31% /ramdisk/php
fakefs 208G 120G 78G 61% /var/lib
fakefs 208G 120G 78G 61% /var/lib/mysql
fakefs 208G 120G 78G 61% /var/log
fakefs 208G 120G 78G 61% /var/spool
fakefs 208G 120G 78G 61% /var/run
fakefs 4.0G 361M 3.7G 9% /var/tmp
fakefs 208G 120G 78G 61% /var/cache/man
I'm trying to get the available free space (78GB) using perl which I'm fairly new to. I'm able to get the value using the following linux command but I've heard it's not necessary to use awk in perl at all because perl can do what awk can natively.
df -h | tail -n +2 | sed -n '2p' | awk '{ print $4 }'
I'm stumped. I tried using the Filesys::df module but when I'd print out the available usage percent, it'd give me a different value than what running df from command line does. Help is appreciated.
A little more succinctly:
df -h | perl -wlane 'print $F[3] if $. == 2;'
-w enable warnings
-l add newline to output(and chomps newline from input line)
-a splits the fields on whitespace into the #F array, which you access using the syntax $F[n] (first column is at index position 0)
-n puts the code inside the following loop:
LINE:
while (<>) {
... # code goes here
}
# <> reads lines from STDIN if no filenames are given on the command line
-e execute the string
$. current line number in the file (For the first line, $. is 1)
If you wish to do this all in perl, then:
df -h | perl -e 'while (<stdin>) { if ($. == 2) { #x = split; print $x[3] }}'
This uses perl alone to read the output of df -h and, for the second record ($. == 2) splits the record into fields, based on whitespace, and outputs field 3 (counting from 0).
This seems to work ok too:
df -h | awk 'NR==2 {print $4}'
Get the second line and pint fourth field.

Resources