A smart wrapper for mv that creates timestamped backups
whenever you overwrite existing files or directories.
Explore the docs »
Report Bug
·
Request Feature
- ✨ Features
- 🚀 Installation
- 🛠 Usage
- 📍 Where the Backup Does NOT Activate
- ⚙️ Customization
- ❓ FAQ
- 📄 License
- 👤 Author
- 🤝 Contributing
⚠️ Disclaimer
-
Timestamped Backups
Existing files or directories are renamed toname.ext.YYYY-MM-DD--HH-MM-SS.bakbefore being overwritten.
Example:report.docx.2026-04-27--15-30-22.bak -
Handles Both Files and Directories
Unlike many backup tools, this wrapper also protects entire directories from accidental overwrites. -
Safe by Default
Only activates inside your home directory ($HOME). Outside of it,mvbehaves normally – no unwanted side effects. -
Python Virtual Environment Friendly
Automatically disables backup when the destination resides inside an active virtual environment ($VIRTUAL_ENV). -
Preserves All Standard Options
-i(interactive),-f(force),-n(no-clobber),-v(verbose),--, etc. – all work as expected. -
Collision‑Proof Naming
If two moves happen within the same second, a counter (_1,_2, …) guarantees unique backup names. -
No Octal Interpretation Bug
Because timestamps are pure strings, you’ll never see “value too great for base” errors.
- Bash 4.0 or later (standard on modern Linux, macOS, and WSL)
coreutils(usually pre-installed)
git clone https://github.com/setuju/bash-mv-auto-backup.git
cd bash-mv-auto-backupcurl -o mv-auto-backup.sh https://raw.githubusercontent.com/setuju/bash-mv-auto-backup/main/mv-auto-backup.shAdd the following line to your ~/.bashrc, ~/.bash_profile, or ~/.zshrc:
source /path/to/mv-auto-backup.shReplace /path/to/ with the actual location of the script. Then reload your shell:
source ~/.bashrc…or simply open a new terminal window.
Once activated, the mv command works exactly as before, but with extra safety.
$ mkdir ~/archive
$ echo "First version" > ~/archive/doc.txt
$ echo "Second version" > doc.txt
$ mv doc.txt ~/archive/
$ ls ~/archive/
doc.txt
doc.txt.2026-04-27--09-15-30.bakThe old doc.txt was renamed to a timestamped backup before the new file was moved in.
$ mv my_project ~/archive/If ~/archive/my_project already exists, it becomes my_project.2026-04-27--23-59-59.bak, and the new my_project is placed in ~/archive/.
Every collision creates a unique backup, so your history is always preserved:
$ echo "Third version" > doc.txt
$ mv doc.txt ~/archive/
# → doc.txt.2026-04-27--09-15-45.bak$ mv -v file.txt ~/destination/ # verbose
$ mv -i important.txt ~/backup/ # prompt before overwrite
$ mv -f data.log ~/logs/ # force (backup still happens)- Outside
$HOME– e.g.,sudo mv /etc/config /etc/config.bakuses the originalmvbehavior. - Inside a Python virtual environment (when
$VIRTUAL_ENVis set) – moves insidemyenv/are not backed up. - When the destination is a regular file (not a directory) – the original
mvlogic applies.
You can easily modify or add exclusion rules by editing the _is_in_venv function or the allow_backup block. For example, to also exclude a specific folder:
if [[ "$target_dir_abs" ## "/path/to/exclude"* ]]; then
allow_backup#false
fiWhy not just use mv -b?
The standard mv -b creates a backup with a tilde suffix (e.g., file~), but it does not support timestamped backups for multiple collisions. This wrapper gives you clean, chronologically sortable backups and integrates seamlessly with your daily workflow.
What happens if I move a file/folder outside of $HOME?
Nothing special. Outside $HOME the original mv command is called directly, so your system behaves exactly as it did before.
Can I disable the backup temporarily?
Yes. Just call the original mv via command mv ... or \mv ....
This project is licensed under the MIT License – see the LICENSE file for details.
Jack – MainHack BrotherHood
- GitHub: @setuju
- Telegram: passwords.t.me
- dev.to: HARD IN
Contributions, issues, and feature requests are welcome!
Feel free to check the issues page.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This script overrides the default mv command. While it is designed to be safe, always keep backups of critical files. The author is not responsible for any data loss. Use at your own risk.