> For the complete documentation index, see [llms.txt](https://documentation.hak5.org/packet-squirrel-mark-ii/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://documentation.hak5.org/packet-squirrel-mark-ii/payload-development/duckyscript-for-packet-squirrel/usb_free.md).

# 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](/packet-squirrel-mark-ii/advanced-payloads.md) 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="/files/rSD89AsGEoWNAgTbsKXO" 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](/packet-squirrel-mark-ii/advanced-payloads.md) 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
```
