# Disk free in raspberry pi

**URL:** <https://discourse.nodered.org/t/disk-free-in-raspberry-pi/1156>\
**Category:** General\
**Created:** [28 June 2018 13:42 UTC](https://discourse.nodered.org/t/disk-free-in-raspberry-pi/1156 "2018-06-28T13:42:17Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidcgu](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@davidcgu](https://discourse.nodered.org/u/davidcgu)\
**Post date:** [28 June 2018 13:42 UTC](https://discourse.nodered.org/t/disk-free-in-raspberry-pi/1156/1 "2018-06-28T13:42:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [28 June 2018 14:07 UTC](https://discourse.nodered.org/t/disk-free-in-raspberry-pi/1156/2 "2018-06-28T14:07:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![davidcgu](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@davidcgu](https://discourse.nodered.org/u/davidcgu)\
**Post date:** [28 June 2018 14:20 UTC](https://discourse.nodered.org/t/disk-free-in-raspberry-pi/1156/3 "2018-06-28T14:20:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [28 June 2018 14:41 UTC](https://discourse.nodered.org/t/disk-free-in-raspberry-pi/1156/4 "2018-06-28T14:41:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [28 June 2018 14:50 UTC](https://discourse.nodered.org/t/disk-free-in-raspberry-pi/1156/5 "2018-06-28T14:50:49Z")

</div>

You could do

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

```

---

<div class="post-metadata">

**Author:** ![davidcgu](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@davidcgu](https://discourse.nodered.org/u/davidcgu)\
**Post date:** [28 June 2018 14:51 UTC](https://discourse.nodered.org/t/disk-free-in-raspberry-pi/1156/6 "2018-06-28T14:51:57Z")

</div>

> [@Colin](#):
>
> df -h|grep /dev/root|awk '{$4}'

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [28 June 2018 14:53 UTC](https://discourse.nodered.org/t/disk-free-in-raspberry-pi/1156/7 "2018-06-28T14:53:31Z")

</div>

Actually I meant, of course

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

```

---

<div class="post-metadata">

**Author:** ![davidcgu](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@davidcgu](https://discourse.nodered.org/u/davidcgu)\
**Post date:** [28 June 2018 14:54 UTC](https://discourse.nodered.org/t/disk-free-in-raspberry-pi/1156/8 "2018-06-28T14:54:55Z")

</div>

I understood, thanks a lot

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [28 June 2018 14:59 UTC](https://discourse.nodered.org/t/disk-free-in-raspberry-pi/1156/9 "2018-06-28T14:59:07Z")

</div>

> [@Colin](#):
>
> df -h|grep /dev/root|awk '{print $4}'

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.

---

<div class="post-metadata">

**Author:** ![davidcgu](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@davidcgu](https://discourse.nodered.org/u/davidcgu)\
**Post date:** [28 June 2018 15:00 UTC](https://discourse.nodered.org/t/disk-free-in-raspberry-pi/1156/10 "2018-06-28T15:00:53Z")

</div>

With my pi is working perfectly as expected like this, returns me the total available disk  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/05af833d60c0e7c81d00136a5e92e7a7a526a44b.png)

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [28 June 2018 16:11 UTC](https://discourse.nodered.org/t/disk-free-in-raspberry-pi/1156/11 "2018-06-28T16:11:12Z")

</div>

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:

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

```

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

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

```

Here is my test flow…

```auto
[{"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…
