-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync_dirs.sh
executable file
·37 lines (29 loc) · 1.01 KB
/
sync_dirs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash
# Check if exactly two arguments are provided
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <source_directory> <destination_directory>"
exit 1
fi
SOURCE="$1"
DESTINATION="$2"
# Check if source directory exists
if [ ! -d "$SOURCE" ]; then
echo "Error: Source directory does not exist."
exit 1
fi
# Check if destination directory exists
if [ ! -d "$DESTINATION" ]; then
echo "Error: Destination directory does not exist."
exit 1
fi
# Confirm before deleting (optional, remove for silent execution)
read -p "Are you sure you want to delete all contents of '$DESTINATION' and replace them with '$SOURCE'? (y/N) " confirm
if [[ "$confirm" != [yY] ]]; then
echo "Operation cancelled."
exit 0
fi
# Delete contents of the destination directory
rm -rf "$DESTINATION"/* "$DESTINATION"/.[!.]* "$DESTINATION"/..?* 2>/dev/null
# Copy contents from source to destination
cp -R "$SOURCE"/* "$SOURCE"/.[!.]* "$SOURCE"/..?* "$DESTINATION" 2>/dev/null
echo "Sync complete: '$SOURCE' → '$DESTINATION'"