File System to CLI (fs_cli)

File System to CLI exposes Drupal's file system API as a small set of Drush commands, so you can inspect and manipulate files from the command line and from automation.

Every command runs through Drupal's file_system service rather than touching the disk directly. That means operations honor Drupal stream wrappers: public://, private://, temporary://, and remote backends such as s3:// (via the S3 File System module). A script behaves the same whether the files live on local disk or in object storage.

Each command returns machine-readable JSON. This makes the module a good fit for deployment pipelines, CI jobs, and infrastructure tooling that needs to act on the result of a file operation without writing custom PHP.

Requirements

  • Drupal 10 or 11.
  • Drush 12 or newer.

Installation

Install with Composer, then enable the module:

composer require drupal/fs_cli
drush pm:enable fs_cli

No configuration is required.

Commands

Command Alias Description
fs:file-exists fs-fe Report whether a file exists.
fs:directory-exists fs-de Report whether a directory exists.
fs:copy [replace] Copy a file, creating the destination directory if needed.
fs:move [replace] Move a file, creating the destination directory if needed.
fs:mkdir Create a directory.
fs:scan-dir List the files in a directory that match a regular-expression mask.
fs:delete-dir Delete a directory and its contents recursively.

All commands accept a --format option (default json).

For fs:copy and fs:move, the optional replace argument controls what happens when the destination already exists:

  • 0 — rename: append an incrementing numeric suffix until the name is unique.
  • 1 — replace the existing file (default).
  • 2 — do nothing and return an error.

Examples

# Check whether a file exists on the public file system.
drush fs:file-exists public://logo.png

# Copy a file to S3-backed storage (with S3 File System configured).
drush fs:copy public://export.csv s3://backups/export.csv

# List every JPEG file under a directory.
drush fs:scan-dir public://images '/\.jpg$/'

# Create a working directory and remove it afterwards.
drush fs:mkdir temporary://build
drush fs:delete-dir temporary://build

Maintainers

  • Marco Primitivo (Bladedu)

Sponsored by SparkFabrik.

Supporting organizations: 

Project information

Releases