2026-10-12 10:56:43 -06:00
2026-10-11 21:36:20 -06:00
2026-10-11 21:36:20 -06:00
2026-10-11 21:36:20 -06:00
2026-10-11 21:36:20 -06:00
2026-10-11 21:36:20 -06:00
2026-10-11 21:36:20 -06:00
2026-10-11 21:36:20 -06:00
2026-10-11 21:36:20 -06:00
2026-10-11 21:36:20 -06:00
2026-10-11 21:36:20 -06:00
2026-10-12 10:56:43 -06:00
2026-10-11 21:36:20 -06:00
2026-10-11 21:36:20 -06:00
2026-10-11 21:36:20 -06:00

storage-cleanup

A terminal UI for finding and cleaning up duplicate files. Run it from the directory you want to analyze: that directory is the data root.

Build and run

go build -o storage-cleanup .
cd /path/to/data && /path/to/storage-cleanup

Requires Go 1.25 or newer.

Command line options

Option Description
--min-size SIZE Minimum file size to index, e.g. 500KB, 1.5MB, 2GB or plain bytes. Overrides the config file. Default: 1MB.
--use-index Load the existing storage-cleanup-index.json instead of rescanning and rehashing. Entries whose file is gone or whose size changed are dropped. Fails if the index is missing or invalid. --min-size has no effect with this option.

Configuration

Optional storage-cleanup.json in the data root:

{ "min_size": "2MB" }

Precedence for the minimum size: --min-size > config file > default (1MB).

Files in the data root

File Purpose
storage-cleanup-index.json Index of all files at or above the minimum size.
storage-cleanup.log Append-only log of every move and delete.
storage-cleanup.json Optional configuration.
.storage-cleanup-trash/ Where "deleted" files go. Nothing is permanently removed.

The index, config, log and trash folder are excluded from scanning. Symlinks and non-regular files are skipped.

Index format

A JSON array of:

{ "file_path": "/full/path/file.bin", "file_name": "file.bin", "file_size": 3000000, "file_hash": "md5hex" }

Hashing

  • Files smaller than 20MB: MD5 of the whole file.
  • Files of 20MB or more: MD5 of a 1KB sample at every 10MB offset within the whole 20MB blocks, followed by the final chunk (the remainder after the last whole 20MB block; for an exact multiple of 20MB, the last 20MB block).

Because large-file hashes are sampled, matches on files over 20MB are probable rather than guaranteed.

Duplicates

Files are duplicates when their size and hash are both identical. Groups are ordered by wasted space, largest first.

The TUI

After indexing (or loading the index) you land in the directory view.

Directory view (default)

Lists only the next level of directories that contain duplicate files, with counts of duplicate files and groups.

  • .. appears at the top when you are below the data root.
  • <current directory> represents the directory you are in.
Key Action
↑/↓, j/k Move selection
enter Descend into the directory (on .., go up)
esc, h Go up one level
i Inspect: show duplicates with a copy under the selected directory. On <current directory> it uses the current directory; at the data root that is all duplicates
x Apply marked deletions
q Quit (asks for confirmation if files are marked)

Duplicate list and copies view

Inspect opens the list of duplicate groups, filtered to groups with at least one copy under the chosen directory. Each group still shows all of its copies, including ones outside that directory. enter opens a group to see the full path of every copy; esc goes back (to the directory view from the group list).

Key Action
↑/↓, j/k Move selection
enter Open the selected group
d Mark or unmark the file for deletion [D]
p Select or clear the preferred file [P]
c Cleanup by pattern (see below)
m Move the file: prompts for a directory, enter moves immediately, esc cancels
x Apply marked deletions (after confirmation)
esc Back
q Quit

Deleting

d only marks. x asks for confirmation (y/n) and then moves all marked files to .storage-cleanup-trash/, preserving their relative paths (a numeric suffix is added on name clashes). A group must always keep at least one copy, so marking the last unmarked copy is refused.

Moving

Relative destinations resolve against the data root; absolute paths and ~/ work too. Missing directories are created. An existing file is never overwritten. If the destination is on another filesystem the file is copied and then removed.

Cleanup by pattern

For applying the same decision across many groups:

  1. In a group, press p on the copy to keep and d on one or more copies to delete.
  2. Press c.

The tool takes the directory of the preferred file and the directories of the marked files. In every duplicate group that has a copy directly in the preferred directory, any copy directly in a marked directory with the exact same file name is scheduled for deletion. Only those exact directories are considered, never their subdirectories. Size and hash already match because the files are in the same group. Your marked files are always included.

A preview lists each DELETE <path> with the KEEP <path> copy that remains. enter continues (files are moved to the trash, logged, and the index is updated); esc returns to the duplicate view with no changes.

Log

Each change is appended to storage-cleanup.log:

2026-10-11T17:55:43-06:00 DELETE /data/old/a -> /data/.storage-cleanup-trash/old/a
2026-10-11T17:55:50-06:00 MOVE /data/x/b.bin -> /data/archive/b.bin

After any move or delete the index is rewritten and the duplicate groups are recomputed.

Development

go vet ./...
go test ./...
S
Description
TUI utility for finding duplicate files and cleaning up file trees
Readme
45 KiB
Languages
Go 100%