Bash rsync
Review the proposed selection before synchronising directories.
How it works
rsync compares and transfers file trees with options that affect selection, metadata and deletion. A trailing slash on the source can change whether the directory itself or its contents are copied. Start with a dry run, inspect both resolved paths and avoid deletion flags until the ownership and retention policy is explicit. The reviewed Git Bash installation has no rsync utility.
Run the code
Reviewed with Git for Windows Bash 5.2.37. Open Git Bash, save the download with LF line endings in a separate learning folder, check it with bash -n lesson-name.sh, then run bash lesson-name.sh using the actual filename. Bash 4 or newer is required for the full course. Linux-only notes identify unavailable tools or POSIX behaviour. There is no Bash browser runner; Apache and MySQL are not required.
This Linux walkthrough was syntax-checked only: the required tool or POSIX behaviour was not available in the Windows review. Its expected section describes the intended result, not captured execution.
The complete source creates a fresh private temporary workspace and checks its physical path before cleanup. All file fixtures belong to that workspace; do not remove the guards or point it at existing documents.
Example
#!/usr/bin/env bash
set -u
set -o pipefail
export LC_ALL=C
# Own a new directory; verify physical paths before cleanup.
parent=$(cd -- "${TMPDIR:-/tmp}" && pwd -P) || exit 1
work=$(mktemp -d "$parent/bhylu-bash.XXXXXX") || exit 1
work=$(cd -- "$work" && pwd -P) || exit 1
case "$work" in "$parent"/bhylu-bash.??????) ;; *) exit 1 ;; esac
cleanup() {
cd -- "$parent" || return 1
[[ -d $work && ! -L $work ]] || return 1
[[ $(cd -- "$work" && pwd -P) == "$work" ]] || return 1
case "$work" in "$parent"/bhylu-bash.??????) rm -r -- "$work" ;; *) return 1 ;; esac
}
trap cleanup EXIT
cd -- "$work" || exit 1
mkdir -p -- source destination
printf "north\n" > source/map.txt
rsync -an -- source/ destination/
Focus on the lesson commands
This excerpt omits temporary-workspace setup and cleanup. Use the complete source above to run the example.
mkdir -p -- source destination
printf "north\n" > source/map.txt
rsync -an -- source/ destination/
Expected result
On a system with rsync, the dry run proposes copying source contents into destination without performing the transfer. Output varies by installed options/version. Syntax checked; rsync was not available or executed here.
Both directories are created inside the owned temporary workspace. The -n option requests a dry run and -a requests archive-style behaviour, whose metadata effects depend on privileges and filesystem support. This example intentionally contains no --delete. Recheck the real paths before removing -n in a separate learning experiment.
Primary technical reference: Bash documentation.