rcopy is a versatile and powerful Bash function designed for efficient and customizable copying of files and directories, both locally and between remote systems. Leveraging the capabilities of rsync, scp, and additional features like compression, file exclusion, and bandwidth control, rcopy aims to simplify and enhance the process of data transfer.
Due to its comprehensive functionality, rcopy is best sourced from outside your .bashrc file to keep your shell configuration clean and fast. You can source the script whenever needed or in specific scripts that require its functionality.
- Clone the repository or download the
rcopy.shscript to your preferred location.
git clone https://github.com/mrAibo/rcopy.git- Use it either way — no build step:
source /path/to/rcopy.sh # defines the rcopy function for this shell
# or run it directly, no sourcing required:
/path/to/rcopy.sh src dest- Dual Protocol Support: Choose between
rsync(default) orscp - Compression: Optional GZIP compression for slow networks
- Sync Mode: Server-to-server synchronization with date filtering
- Bandwidth Control: Limit transfer speed (rsync only)
- Exclusion Patterns: Support for both inline patterns and exclude files
- SSH Integration: Custom ports, keys, and SSH config compatibility
- Autocomplete: Intelligent path completion for local/remote files
- Verbose Mode: Detailed transfer progress visualization
rcopy [OPTIONS] source destination-h,--help: Show help message.-z,--compress: Compress data during transfer.-m,--move: Move files instead of copying (delete source after transfer).-u,--user: Specify remote username.-p,--port: Specify SSH port number.-i,--identity: Specify SSH identity file (private key).-l,--limit: Limit bandwidth (KB/s, rsync only).-e,--exclude: Exclude files matching pattern or use exclude file.-s,--use-scp: Force using SCP instead of rsync.-v,--verbose: Show detailed progress information.-S,--sync: Enable sync mode between remote servers.--source-host: Source server hostname/IP.--target-host: Target server hostname/IP.--days: Sync files modified in last DAYS days.
Basic Examples
- Copy a local directory:
rcopy ~/documents/project /backup/- Copy to a remote server:
rcopy ~/documents user@server:/backup/- Copy from a remote server:
rcopy user@server:/remote/data ~/local/Advanced Examples
- Compress and move with verbose output:
rcopy -z -m -v ~/large-project server:/backup/- Exclude log files and use custom SSH port:
rcopy -e "*.log" -p 2222 ~/project user@server:/backup/- Enable direct server-to-server transfers with -S/--sync:
rcopy -S --source-host HOST1 --target-host HOST2 /src /dest
Sync Options:
--days N: Only sync files modified in last N days
Combine with -m to move files after syncYou rarely need -u/-i. rcopy delegates all key handling to SSH, so set
it up once in ~/.ssh/config and drop the flags:
Host myserver
HostName 192.0.2.10
User bob
IdentityFile ~/.ssh/bob_key
IdentitiesOnly yes
Then rcopy myserver:/data /backup/ just works — user and key are picked up
automatically. For passwordless operation, load the key once with
ssh-add ~/.ssh/bob_key (ssh-agent) instead of passing -i every run.
- Use compression (-z) for: Text files and small documents, High-latency connections, Transfers with many small files
- Prefer rsync for: Large directories, Partial transfers, Network-efficient updates
- Use SCP (-s) for: Single large files, Simple transfers without advanced features
A minimal regression suite lives in test_rcopy.sh (no external deps — plain
bash). It covers the fixes below and guards against regressions:
bash test_rcopy.sh-u/--useris now applied to remote source/destination specs (previously parsed but ignored —rcopy -u bob host:/x /yran as the current user).-m/--moveno longer deletes a remote source. Move-mode cleanup now runs only for local sources; a remote→local move previously deleted the file on the server (silent data loss).-r/--resumeis corrected. Uses--partialonly; the old--append-verifycould corrupt a full copy when sizes already matched.NO_COLORworks. Color variables are no longerreadonly, so the no-color branch can actually clear them.-L/--logno longer swallows errors. Logging redirection starts only after argument validation, so "Missing source or destination" stays on the terminal.- Dry-run preview is accurate. SSH port/identity are combined into a single
-e 'ssh -p … -i …'instead of two conflicting-eflags. - trap EXIT cleanup no longer emits
unbound variablenoise underset -u.
rcopy is licensed under the GNU General Public License v3.0.
Contributions are welcome! If you find any bugs, have feature requests, or would like to contribute, please open an issue or submit a pull request.
rcopy utilizes the power of existing tools like rsync, scp, ssh, tar, and gzip to deliver a seamless data transfer experience.
Note: The detailed explanation and usage examples are provided within the rcopy.sh script. Refer to the script for in-depth documentation and advanced usage scenarios.
Happy copying! 🚀