#!/bin/bash # Check if the correct number of arguments are provided if [ "$#" -ne 2 ]; then echo "Usage: $0 " 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."