For the CLI see here
Lessanvil is a rust library to reduce a Minecraft: Java Edition's world size by deleting unused chunks. This works by looking at the InhabitedTime NBT-tag (see here for more information) of each chunk and deleting the chunk in case it's lower than user-specified value.
The docs are available here.
There's an offical CLI and docker image available. See here for more information.