---
source: https://iinventedlight.com/library/notes/rust-fs.md
title: "std::fs: cross-platform filesystem operations in Rust"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT OR Apache-2.0 (Rust Standard Library); MIT OR Apache-2.0 (Rust By Example); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Rust Standard Library, std::fs; Rust By Example, Filesystem Operations. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/rust/master/COPYRIGHT). Copyright the Rust Project Developers. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/rust-by-example/master/LICENSE-MIT). Copyright the Rust Project Developers."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-23
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-23
as_of: 2026-11-23
confidence: medium
untested: "Not reproduced (2026-11-23). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: rust-fs"
tags: [rust, fs, filesystem, files, std]
client: Librarian
sources:
  - id: S1
    title: "std::fs"
    publisher: Rust Standard Library
    url: https://doc.rust-lang.org/std/fs/index.html
    accessed: 2026-11-23
    license: "MIT OR Apache-2.0"
  - id: S2
    title: "Filesystem Operations"
    publisher: Rust By Example
    url: https://doc.rust-lang.org/rust-by-example/std_misc/fs.html
    accessed: 2026-11-23
    license: "MIT OR Apache-2.0"
---
# std::fs: cross-platform filesystem operations in Rust
**Answer:** The std::fs module contains basic methods to manipulate the contents of the local filesystem. Those methods represent cross-platform operations. Extra platform-specific functionality lives in extension traits. Many operations are subject to TOCTOU race conditions.

## What the module covers

Basic methods for changing the contents of the local filesystem live in this module.

All methods in this module represent cross-platform filesystem operations.

Platform-specific extras appear on extension traits for the module's types.

A TOCTOU race, short for Time of Check to Time of Use, can affect many of these operations.

## Everyday helpers in Rust By Example

Several functions in the module deal with the filesystem.

A simple implementation of cat, echo, or touch can use these functions on a path.

Recursively create a directory; the call returns io::Result.

## See also

- [rust-path](https://iinventedlight.com/library/notes/rust-path/)
- [rust-command](https://iinventedlight.com/library/notes/rust-command/)

## Claims

- id: C1
  claim: std::fs has basic methods to manipulate the local filesystem.
  source: S1
  evidence: "basic methods to manipulate the contents of the local"

- id: C2
  claim: Those methods represent cross-platform filesystem operations.
  source: S1
  evidence: "cross-platform filesystem operations"

- id: C3
  claim: Many operations are subject to TOCTOU race conditions.
  source: S1
  evidence: "Time of Check to Time of Use"

- id: C4
  claim: The module contains several functions that deal with the filesystem.
  source: S2
  evidence: "several functions that deal with the filesystem"

## Sources

- [S1] std::fs. Rust Standard Library. https://doc.rust-lang.org/std/fs/index.html . License: MIT OR Apache-2.0. Accessed 2026-11-23.

- [S2] Filesystem Operations. Rust By Example. https://doc.rust-lang.org/rust-by-example/std_misc/fs.html . License: MIT OR Apache-2.0. Accessed 2026-11-23.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Rust Standard Library, std::fs; Rust By Example, Filesystem Operations. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/rust/master/COPYRIGHT). Copyright the Rust Project Developers. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/rust-by-example/master/LICENSE-MIT). Copyright the Rust Project Developers. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
