-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopy_files.sh
More file actions
39 lines (30 loc) · 908 Bytes
/
copy_files.sh
File metadata and controls
39 lines (30 loc) · 908 Bytes
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
38
39
#!/bin/bash
# Prompt the user for the first directory path
echo "Enter the path of the first directory:"
read dir1
# Prompt the user for the second directory path
echo "Enter the path of the second directory:"
read dir2
# Check if both directories exist
if [ ! -d "$dir1" ]; then
echo "The directory $dir1 does not exist."
exit 1
fi
if [ ! -d "$dir2" ]; then
echo "The directory $dir2 does not exist."
exit 1
fi
# Prompt the user for the new directory path
echo "Enter the path of the new directory where files will be copied:"
read new_dir
if [! -d $new_dir]; then
echo "The destination directory not fiund"
exit 1
fi
# Create the new directory if it does not exist
mkdir -p "$new_dir"
# Copy files from the first directory
cp -r "$dir1"/* "$new_dir/"
# Copy files from the second directory
cp -r "$dir2"/* "$new_dir/"
echo "All files from $dir1 and $dir2 have been copied to $new_dir"