# USB\_FREE

The `USB_FREE` command returns the available space on an attached USB external storage device.

Advanced payloads can use this to determine available space.

If there is no USB drive attached, `USB_FREE` will return `0`

## Return values

`USB_FREE` returns as output the amount of space free on an attached USB storage device, in bytes.

To learn how to write payloads which can handle responses, check the [Advanced Bash](https://olddocs.hak5.org/packet-squirrel-mark-ii/advanced-payloads) section!

## Experimenting

You can experiment using the `USB_FREE` command live, either in the Web Shell in the web UI, or via `ssh`!

<figure><img src="https://932701053-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F520JUF2JxB2RMXztRVAV%2Fuploads%2FduzlaRa06fpJTH7cdqex%2FScreenshot%20from%202023-02-21%2013-34-37.png?alt=media&#x26;token=97238e15-40bc-49be-8e9b-635eea5e1a74" alt=""><figcaption><p>Example of the USB_FREE command in the Web Shell</p></figcaption></figure>

## Examples

Payloads using the `USB_FREE` command must handle the output; for example the following payload sets the LED based on the free space.  For more information about writing advanced payloads, see the [Advanced Bash](https://olddocs.hak5.org/packet-squirrel-mark-ii/advanced-payloads) section!

```bash
#!/bin/bash

# Title: USBFREE demo
# 
# Description: Set the LED color based on the free space.

NETMODE NAT

SPACE=$(USB_FREE)

if [ $SPACE = 0 ]; then
        # No storage, blink red
        LED R SINGLE
elif [ $SPACE -lt $((1024*1024)) ]; then 
        # Less than a meg free, blink magenta
        LED M SINGLE
else
        # Blink green
        LED G SINGLE
fi
```
