#!/bin/bash #Dieses script ist eine Modifikation des new_version-Scripts und erlaubt, alle Dateien eines Verzeichnisses (1.Parameter) in ein bereits existierendes anderes Verzeichnis (2.Parameter) zu hardlinken. Dateien, die den gleichen Namen wie eine bereits im Zielverzeichnis existierende Datei haben, werden hierbei übersprungen. echo "Warning: this script creates bugs, if there are any soft links in the directory it's working on. please check for them beforehand." target="$2" echo "setting target to $target" if ! [ -e $2 ]; then echo "$2 does not exist" echo "Creating directory \"$2\"" mkdir $2 elif ! [ -d $2 ]; then target="${2}.directory" echo "WARNING: there already exists a file with the name \"$2\". Created directory \"$target\" instead." mkdir $target else echo "linking files to existing directory $target" fi for file in "$1"/* do echo "Processing: $file" name=$(basename "$file") newlocation="${target}/${name}" echo "testing new location: $newlocation" if ! [[ -e $newlocation ]]; then echo "$file passed test: does not exist in target directory so far." process=true elif [[ -d "$file" ]]; then echo "$file passed test: is a directory" process=true else echo "$file skipped: file with the same name existing in target directory" process=false fi if $process; then echo "identifying $file" if [ -f "$file" ]; then echo "$file is a regular file. creating hard link." ln "$file" "$target" else if [ -d "$file" ]; then echo "$file is a directory: starting recursion." $0 "$file" "$target"/"$name" else echo "$file is neither regular nor directory. creating copy." cp -a "$file" "$target" fi fi fi done echo "Processed all files in $1"