This Bash script provides an interactive interface for performing bulk file operations (rename, copy, move, and delete) using fzf
for file selection. It allows users to efficiently manage multiple files or directories with a terminal-based fuzzy finder and preview capabilities.
- Interactive File Selection: Uses
fzf
to select multiple files or directories with a preview of file contents (viabat
) or directory listings (viaeza
). - Bulk Operations:
- Rename: Edit filenames in bulk using your preferred text editor.
- Copy: Copy selected files or directories to a specified destination.
- Move: Move selected files or directories to a specified destination.
- Delete: Move selected files or directories to the system trash.
- Recursive Mode: Supports recursive file selection for operations on nested directories.
- Safety Checks: Includes confirmation prompts and validation to prevent errors like overwriting files or mismatched rename entries.
- Colorized Output: Provides clear feedback with color-coded success, warning, and error messages.
The script requires the following tools to be installed:
fzf
: For interactive file selection.fd
: For fast file searching.eza
: For enhanced directory listings with icons and colors.bat
: For syntax-highlighted file previews.
Install these dependencies on a Debian-based system (e.g., Ubuntu) with:
sudo apt update
sudo apt install fzf fd-find eza bat
Install these dependencies on NixOS with:
nix-shell -p fzf fd eza bat
On other systems, refer to the respective package managers or official documentation for installation instructions.
- Save the script to a file, e.g.,
fzf-bulk.sh
. - Make it executable:
chmod +x fzf-bulk.sh
- Optionally, move it to a directory in your
$PATH
(e.g.,/usr/local/bin
) for global access:sudo mv fzf-bulk.sh /usr/local/bin/fzf-bulk
Run the script with one of the following subcommands:
fzf-bulk <command> [path]
r
orR
: Bulk rename selected entries. UseR
for recursive selection.c
orC <path>
: Copy selected entries to<path>
. UseC
for recursive selection.m
orM <path>
: Move selected entries to<path>
. UseM
for recursive selection.d
orD
: Move selected entries to the system trash (~/.local/share/Trash/files
). UseD
for recursive selection.
- Rename files in the current directory:
fzf-bulk r
- Recursively copy files to
/tmp/destination
:fzf-bulk C /tmp/destination
- Move files to
/home/user/archive
:fzf-bulk m /home/user/archive
- Delete files by moving them to trash:
fzf-bulk d
- Tab: Move down in the
fzf
selection list. - Shift+Tab: Move up in the
fzf
selection list. - Ctrl+N: Select an entry (supports multiple selections).
- Enter: Confirm selection and proceed.
The script includes the following customizable settings:
LIST_CMD
: Command for directory listing previews (default:eza -al --group-directories-first --icons --color=always
).TRASH_DIR
: Directory for deleted files (default:${HOME}/.local/share/Trash/files
).TEMPFILE
: Temporary file for renaming (default:/tmp/bulk_rename_$$
).EDITOR
: Text editor for renaming (defaults tonano
if not set).
You can modify these variables at the top of the script or set the EDITOR
environment variable before running the script:
export EDITOR=vim
fzf-bulk r
- Ensure the destination path exists for copy and move operations.
- The rename operation opens a temporary file in your editor with the selected filenames. Edit each name on its respective line, save, and exit to proceed.
- The script skips renaming if a target file already exists or if the new name is empty.
- Recursive mode (
R
,C
,D
) includes files in subdirectories up to a maximum depth of 999.
This script is provided under the MIT License. Feel free to modify and distribute it as needed.