Clean away old stack build artifacts
|LTS Haskell 20.15:||0.4.6|
|Stackage Nightly 2023-03-20:||0.4.6|
|Latest on Hackage:||0.4.6|
Module documentation for 0.4.6
There are no documented modules for this package.
A small tool to clean away older Haskell stack snapshot builds and ghc versions to recover diskspace.
stack-clean-old [size|list|remove|keep-minor|purge-older|delete-work] [(-P|--project)|(-G|--global)] [(-s|--subdirs)|(-r|--recursive)] [-d|--delete] [GHCVER]
In a project directory it acts on
.stack-work/install/ by default,
prints the total size of
size does not take a GHCVER argument).
shows the total size and number of snapshots per ghc version
(the GHCVER argument is optional).
removes for the specified ghc version (the GHCVER argument is required).
removes the builds/installs for older minor releases of ghc major versions.
If GHCVER is given then only minor versions older than it
(or than the latest installed minor version) are removed.
If no GHCVER is given it applies to each installed ghc major version.
removes snapshot builds with older timestamps
.stack-work directories completely
Since version 0.4 dry-run mode is now the default and one needs to use
-d) for actual deletion of files,
after checking the dry-run output first.
If you should remove any needed snapshot builds, then they will get rebuilt again by stack next time you build any projects using them, so removals should be done carefully but can recover a lot of diskspace.
Further the commands can use
--recursive to run over
the projects in subdirs under the current directory or
.stack-work dirs from the current directory and below
List a project’s builds:
$ stack-clean-old list 154M 8.2.2 (5 dirs) 154M 8.4.4 (5 dirs) 163M 8.6.5 (5 dirs)
Remove project’s 8.2.2 builds:
$ stack-clean-old remove --delete --project 8.2.2 :
(–project is optional in a project dir).
Remove stack ghc-8.4 snapshot builds and minor compilers before 8.4.4:
$ stack-clean-old list --global 8.4 421M 8.4.1 (7 dirs) 368M 8.4.2 (6 dirs) 489M 8.4.3 (8 dirs) 799M 8.4.4 (24 dirs) $ stack-clean-old keep-minor -d -g 8.4.4 ghc-tinfo6-8.4.3 removed 7 dirs removed for 8.4.1 6 dirs removed for 8.4.2 8 dirs removed for 8.4.3
(–global is optional outside a project dir).
Purging older stack project builds
This command removes older stack builds from
By default it keeps 5 newest builds per ghc version.
The preservation/deletion is calculated and done per ghc version.
NB: If you regularly build your project for several branches/tags against the same LTS or ghc version then it is safer to avoid using
stack-clean-old delete-work --recursive can be used to remove recursively
.stack-work/ dirs within (or outside) a project directory to save
space (seems same as
stack clean --full inside a project).
(Note you can also run this tool via
To get help you can run
stack-clean-old --help or just:
$ stack-clean-old Stack clean up tool Usage: stack-clean-old [--version] COMMAND Cleans away old stack-work builds (and pending: stack snapshots) to recover diskspace. Use the --delete option to perform actual removals. https://github.com/juhp/stack-clean-old#readme Available options: -h,--help Show this help text --version Show version Available commands: size Total size list List sizes per ghc version remove Remove for a ghc version keep-minor Remove for previous ghc minor versions purge-older Purge older builds in .stack-work/install delete-work Remove project's .stack-work/ (optionally recursively)
stack install or
This tool complements stack-all which builds projects across LTS major versions and hence generates a lot of stack builds.
cabal-clean is a similar tool for cleaning old cached cabal build files.
Use at your own risk: the author takes no responsibility for any loss or damaged caused by using this tool.
Bug reports, suggestions, and improvements are welcome.
Release history for stack-clean-old
- fix –recursive and –subdirs to work again
- show –recursive dir paths
- ignore non-ghc dirs in ~/.stack/programs/
- fix multiple reminders about using –delete
- handle .stack-work/ consistently for –subdir and –recursive
- remind user to use ‘–delete’ for removal
- purge-older: output is now sorted by ghc versions
- ‘delete-work’ now prints “.stack-work” would be deleted
- prompts now print what would be deleted
- ‘–recursive’ now prints dirs with ‘/’ appended
- add optional –os-system to fix #7
- list/size snapshots before compilers for –global
- –help now mentions –delete and a link to README
- dryrun is now default: use –delete for actual removal (suggested by @andreasabel #6)
- new –subdirs and –recursive options
- various output improvements
- purge-older now also says “would be removed” when dryrun
- ‘delete-work’: use find -prune and ignore inaccessible files (@petrem, #4)
- drop subsubcommands to simplify UI
- default to project if there is a .stack-work/ dir, otherwise global ~/.stack
- rename commands:
- remove-version -> remove
- remove-earlier-minor -> keep-minor
- remove-older -> purge-older
- remove-work -> delete-work
- fix handling of partially installed ghc compiler temp dirs (#2)
- rename –dryrun to –dry-run (#1)
- drop –dir option
- delete-work: use –all to run from a non-project dir
- add ‘project remove-work’ to recursively remove .stack-work from projects
- remove-earlier-minor can now take a major version
- major internal refactors with VersionSnapshots type
- split code into modules
- add –dryrun to all remove commands
- remove-earlier-minor subcommands to purge for previous ghc minor versions
- allow major ghc X.Y versions (prompts for removal)
- ‘ghc list’ is now sorted
- initial release with project and snapshots subcommands