create-hardlink-dirs: move from dumpster repo
This commit is contained in:
parent
8024ecb278
commit
ac1654e0ef
40
create-hardlink-dirs.sh
Executable file
40
create-hardlink-dirs.sh
Executable file
@ -0,0 +1,40 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Check if the correct number of arguments are provided
|
||||||
|
if [ "$#" -ne 2 ]; then
|
||||||
|
echo "Usage: $0 <src_dir> <dst_dir>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
src_dir="$1"
|
||||||
|
dst_dir="$2"
|
||||||
|
|
||||||
|
# Check if source directory exists
|
||||||
|
if [ ! -d "$src_dir" ]; then
|
||||||
|
echo "Source directory '$src_dir' not found."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if destination directory exists, if not, create it
|
||||||
|
if [ ! -d "$dst_dir" ]; then
|
||||||
|
mkdir -p "$dst_dir"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Iterate over files in source directory
|
||||||
|
for file in "$src_dir"/*; do
|
||||||
|
# Check if the file is a regular file
|
||||||
|
if [ -f "$file" ]; then
|
||||||
|
# Check if destination file already exists
|
||||||
|
if [ -f "$dst_dir/$(basename "$file")" ]; then
|
||||||
|
echo "File $(basename "$file") already exists in destination directory."
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
# Extract file name without path
|
||||||
|
filename=$(basename "$file")
|
||||||
|
# Create hardlink in destination directory
|
||||||
|
ln "$file" "$dst_dir/$filename"
|
||||||
|
echo "Created hardlink for $filename"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Hardlink creation completed."
|
||||||
Loading…
Reference in New Issue
Block a user