2018-01-25 14:29:31 +00:00
---
title: About the filesystem Resource
2018-02-16 00:28:15 +00:00
platform: linux
2018-01-25 14:29:31 +00:00
---
# filesystem
2019-04-26 18:24:29 +00:00
Use the `filesystem` Chef InSpec resource to audit filesystem disk space usage.
2018-02-07 13:27:48 +00:00
2018-01-25 14:29:31 +00:00
<br>
2018-08-09 12:34:49 +00:00
## Availability
### Installation
2019-04-26 18:24:29 +00:00
This resource is distributed along with Chef InSpec itself. You can use it automatically.
2018-08-09 12:34:49 +00:00
### Version
This resource first became available in v1.51.0 of InSpec.
2019-02-01 05:46:18 +00:00
The `free_kb`, `size_kb`, and `type` properties became available in v3.6 of InSpec.
2019-02-01 05:39:52 +00:00
### Note
2019-04-26 18:24:29 +00:00
Versions of this resource in Chef InSpec prior to 3.5.x offered a property `size`, which returned a value in GB when on Windows and a value in KB on Linux, though it was documented to always return KB. All new code should use `size_kb` which is unit-stable. The property `size` will remain available in Chef InSpec v3 and 4, but will be deprecated in the future.
2019-02-01 05:39:52 +00:00
2018-01-25 14:29:31 +00:00
## Syntax
2018-03-20 12:43:30 +00:00
A `filesystem` resource block declares tests for disk space in a partition:
2018-01-25 14:29:31 +00:00
describe filesystem('/') do
2019-02-01 05:46:18 +00:00
its('size_kb') { should be >= 32 * 1024 * 1024}
its('free_kb') { should be >= 50 * 1024 }
2019-01-31 22:18:39 +00:00
its('percent_free') { should be >= 20 }
2019-01-29 21:23:05 +00:00
its('type') { should cmp 'ext4' }
2018-01-25 14:29:31 +00:00
end
where
2018-02-07 13:27:48 +00:00
* `filesystem('/')` states that the resource will look at the root (/) partition.
2019-02-01 05:39:52 +00:00
* `size_kb` is the total partition size and is measured in kilobytes (KB).
2019-02-01 05:46:18 +00:00
* `free_kb` is the available space on the partition and is measured in kilobytes (KB).
2019-01-31 22:18:39 +00:00
* `percent_free` is the percentage of available free space, and ranges from 0 to 100.
2018-01-25 14:29:31 +00:00
<br>
2018-02-07 13:27:48 +00:00
## Resource Property Examples
2018-01-25 14:29:31 +00:00
2019-04-26 18:24:29 +00:00
The following examples show how to use this Chef InSpec audit resource.
2018-01-25 14:29:31 +00:00
2018-05-03 13:16:07 +00:00
### Test if the root partition is greater than 32000 KB
2018-01-25 14:29:31 +00:00
describe filesystem('/') do
2019-02-01 05:39:52 +00:00
its('size_kb') { should be >= 32000 }
2018-01-25 14:29:31 +00:00
end
<br>
2019-01-29 21:23:05 +00:00
### Test that the root partition has more than 5GB free
describe filesystem('/') do
2019-02-01 05:46:18 +00:00
its('free_kb') { should be >= 5000000 }
2019-01-29 21:23:05 +00:00
end
<br>
### Test if the C:\ partition is NTFS
describe filesystem('c:\') do
its('type') { should cmp 'NTFS' }
end
<br>
2019-01-31 22:18:39 +00:00
### Test if the /var partition has sufficient free space
describe filesystem('/var') do
its('percent_free') { should be >= 20 }
end
2018-01-25 14:29:31 +00:00
## Matchers
2018-02-16 03:07:18 +00:00
For a full list of available matchers, please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).