move-cli: Robust File & Directory Mover CLI
move-cli is a command-line interface (CLI) tool designed to move files and directories, acting as a robust alternative to `fs.rename` and mimicking the Unix `mv` utility. Its key differentiator is the ability to move items across different storage devices and to handle directories recursively, which standard `fs.rename` does not support natively. The package is built upon `andrewrk/node-mv` for its underlying moving logic. The current stable version is 2.0.0, released in late 2023, primarily focusing on dependency vulnerability fixes and CLI option parsing corrections. Its release cadence appears to be driven by maintenance and security updates rather than frequent feature additions, making it a stable choice for automated scripts and build processes.
Common errors
-
move-cli: command not found
cause The `move-cli` package is not installed globally or is not in your system's PATH, or a locally installed version is not being called via `npx` or a `package.json` script.fixIf intending global use: `npm install -g move-cli`. If local: `npx move-cli ...` or add to `package.json` scripts. -
Error: EEXIST: file already exists, '...' -> '...'
cause The destination file or directory already exists, and the `--noclobber` option was used, preventing an overwrite.fixEither rename the destination, remove the existing destination, or omit the `--noclobber` flag if overwriting is acceptable. -
Error: EACCES: permission denied, rename '...' -> '...'
cause The user running the `move-cli` command lacks the necessary read/write permissions for either the source or destination paths.fixEnsure the current user has appropriate file system permissions for both the source and destination directories. You may need to use `sudo` (on macOS/Linux) or run your terminal as an administrator (on Windows) as a last resort, though this is generally not recommended for regular use.
Warnings
- breaking Version 2.0.0 fixed an issue with command-line flag parsing, specifically regarding single-dash versus double-dash for long options. While `--mkdirp` was the intended usage, older scripts might have incorrectly used `-mkdirp`. Post v2.0.0, ensure correct double-dash syntax for long options.
- gotcha Prior versions (1.2.0 and earlier) had reported dependency vulnerabilities. Although v2.0.0 explicitly addresses these, it's crucial to ensure you are running the latest stable version for security patches.
- gotcha By default, `move-cli` will overwrite existing files at the destination. If you need to prevent overwriting, you must explicitly use the `--noclobber` or `-nc` option.
Install
-
npm install move-cli -
yarn add move-cli -
pnpm add move-cli
Imports
- move-cli (Global Install)
$ npm install -g move-cli $ move-cli source/path dest/path
- move-cli (Local Install via npx)
$ npm install move-cli $ npx move-cli source/path dest/path
- move-cli (package.json script)
{ "scripts": { "move-files": "move-cli 'src/**/*.js' dist/js" } }
Quickstart
npm install -g move-cli # Create some dummy files and directories mkdir -p source/folder1 source/folder2 touch source/folder1/file1.txt source/folder2/file2.js # Move a single file move-cli source/folder1/file1.txt destination/newfile.txt # Move a directory (and create destination parent if needed) move-cli source/folder2 destination/new_folder --mkdirp # Move multiple files using a glob pattern, preventing overwrite move-cli 'source/**/*.js' other_destination --noclobber