Gregg's MOTD

Tips & Tricks that I've Encountered Over the Years...

Alternative to Using cp

April 24, 2023 — Gregg Szumowski

To backup files from a source directory to a backup directory: $ mkdir /path/to/backup/directory $ cd $HOME/source/directory $ tar cf - . | (cd /path/to/backup/directory && tar xBvf -) Define the following alias:

tar cvf - . | ( cd \!* ; tar xvf - )

or as an alias:

alias cpbytar='tar cvf - . | ( cd \!* ; tar xvf - )' (The alias definition above is for Bash)

To do a recursive copy of a directory to another location, preserving the PERMISSIONS and OWNERSHIP of the files. "cd" to the source location and invoke the following alias:

cpbytar

Tags: cli, motd