# generate random 20 chars filename and password, you can edit that to whatever length you like: fold -w 20 FILENAME=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 20 | head -n 1) PSWRD=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 20 | head -n 1) currentdir="$(pwd)" # doing PWD's to avoid relative paths errors targetdir="$( mkdir "$1" 2>/dev/null && cd "$1" && pwd )" sourcedir=$(basename "$2") parentdir=$(dirname "$2") # write the filename/password to a file, so we don't lose it! echo Filename: $FILENAME > "$currentdir/$1.txt" echo Password: $PSWRD >> "$currentdir/$1.txt" echo Target Folder: $(basename "$1") >> "$currentdir/$1.txt" echo Source Folder: "$sourcedir" >> "$currentdir/$1.txt" # do the work from the parent dir of the source folder cd "$parentdir" # set same timestamps to files recursively, uncomment the next line if you want that #find $2 -exec touch {} \; # create a list of empty folders (if any) find "$sourcedir" -type d -empty | sed 's/.*/"&"/' | sort > "$currentdir/$1-filelist.txt" # append the filenames to the list find "$sourcedir" -type f | sed 's/.*/"&"/' | sort >> "$currentdir/$1-filelist.txt"