Disk free in raspberry pi

Good afternoon

In order to have the free disk left over control …

If I make df -h I get as return:

Filesystem Size Used Avail Use% Mounted on
/dev/root 15G 6.6G 7.0G 49% /
devtmpfs 460M 0 460M 0% /dev
tmpfs 464M 0 464M 0% /dev/shm
tmpfs 464M 47M 417M 11% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 464M 0 464M 0% /sys/fs/cgroup
/dev/sda1 30G 21G 9.4G 69% /mnt/usb
/dev/mmcblk0p1 42M 21M 21M 51% /boot
tmpfs 93M 0 93M 0% /run/user/1000

I know I can get a simple column as output as example runing:
pi@raspberrypi:~ $ df -h | awk ‘{print $4}’
Avail
7.0G
460M
464M
417M
5.0M
464M
9.4G
21M
93M

Now the question is, how can I access to have simply one position as return, in this case only interested info those 7.0G Avail on /dev/root???

Thanks in advance

What node are you using? what does a debug node attached show you?

In fact your is not a bad question, I was showing the result from a pi console however If i run the command on a exec node and pull the data into a debug, gives me the same, a string with this same info.

I think is not a good way to use a split and try to handle like this as will be difficult to track the position, I wonder if in the same way that I do $4 for the fourth column as example there is some way to indicate column and row to get just a specific one from the main list.

Regards

I would use a split feedng to a switch that checls for ‘/dev/root’ - that should get you one line that you can then parse to get what you want.

You could do

df -h|grep /dev/root|awk '{$4}'
2 Likes

Great!!!!!!!!! thats it, ty boss

Actually I meant, of course

df -h|grep /dev/root|awk '{print $4}'

I understood, thanks a lot

of course that might give you extra lines depending on the environment. On my Mac I need to change '/dev/root/' to '/dev/disk1s2' but since there are two lines that contain '/dev/disk2s1' I get two lines of output. The second line is because of TimeMachine.

So just be aware you could get extra data returned depending on your system.

With my pi is working perfectly as expected like this, returns me the total available disk
image

There are some options to the df command that will make parsing the information easier, I think. For instance, you can ask for only the output fields you need for one mount point by using the command line:
df -h --output=size,used,avail,pcent /dev/xvda1

This produces output on my system like this:

 Size  Used Avail Use%
  30G   12G   19G  39%

which should be able to be parsed by the csv node into a a payload like:

{
  "Size": "30G",
  "Used": "12G",
  "Avail": "19G",
  "Use%": "39%"
}

Here is my test flow…

[{"id":"2df68268.9aa99e","type":"inject","z":"58c8eb7a.5496c4","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":3000,"wires":[["3c76d35d.4ad61c"]]},{"id":"35d484b6.6e879c","type":"csv","z":"58c8eb7a.5496c4","name":"","sep":" ","hdrin":true,"hdrout":"","multi":"one","ret":"\\n","temp":"","skip":"0","x":470,"y":3040,"wires":[["bf4993f5.17586"]]},{"id":"bf4993f5.17586","type":"debug","z":"58c8eb7a.5496c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":630,"y":3000,"wires":[]},{"id":"d43b7157.d1a9c","type":"comment","z":"58c8eb7a.5496c4","name":"df -h output","info":"","x":170,"y":2960,"wires":[]},{"id":"3c76d35d.4ad61c","type":"template","z":"58c8eb7a.5496c4","name":"","field":"payload","fieldType":"msg","format":"text","syntax":"plain","template":" Size  Used Avail Use%\n  30G   12G   19G  39%\n","output":"str","x":320,"y":3000,"wires":[["35d484b6.6e879c","bf4993f5.17586"]]}]

Unfortunately, I just tried it, and get this confusing output as the result:
{"Use%":"12G"}

I suspect that the parser treats consecutive spaces as a delimiting empty fields – which is why the 12G “Used” value is being paired with the “Use%” column. But what has happened to the other three columns? Perhaps we need a new feature like the Excel “treat consecutive delimiters as one” option…