On 12/02/2020 21.50, Carlos E. R. wrote:
On 12/02/2020 21.38, Istvan Gabor wrote:
Hello:
I tried to summarize in the subject what I'd like to do:
I want to create symlinks for all the files within a folder recursively with the symlinks to be in one directory. For example:
I did the same thing with help from here :-)
But I'm unable to locate it now :-(
Found it. It was where I was looking, but the name was not what I remembered. You will have to edit. Let's see if I can open and copy paste from a remote computer... - yep, I could. Nice :-) Oops, the comments are in Spanish. And I think there is another version somewhere, I think using sed with the help from Andrei. Or my memory is playing me tricks. +++....................... #!/bin/bash #Duplica un arbol de directorios en otro, con soflinks. Usa recursividad. Adaptado de "duplicar" #Existen herramientas que lo hacen directamente, pero mi objectivo es borrar los enlaces muertos también. # El "~" no se expande. DESTINO="/home/cer/Fusion/Videos" ORIGENREL="3_MyBook_VideosTst/" ORIGENREL="3_MyBook_Videos/" ORIGEN="$DESTINO/$ORIGENREL" TMPFILE=$DESTINO/fusiondup.lst LOGDUP=$DESTINO/fusiondup_regfiles.lst # Creo que habrá que borrar el enlace "~/Fusion/Videos/3_MyBook_Videos", o se buscaría a sí mismo. function CreateSLink() { # target name # se crea enlace 1 -> 2 sólo si 2 no existe en forma alguna. #echo "-1->" "$1" | grep -i 06_completa #echo "-2->" "$2" | grep -i 06_completa if [ ! -e "$2" ]; then # Si es un enlace, lo borramos para volver a crearlo. Al menos mientras estamos de pruebas. if [ -L "$2" ]; then rm "$2" fi ln -s "$1" "$2" #> /dev/null #echo "$1" "-->" "$2" else # Añadir test que el destino no exista como fichero regular, y en ese caso reportarlo en un log. if [ -f "$2" -a ! -L "$2" ]; then echo "$2" >> $LOGDUP ls -l "$2" fi fi } function CreateDir() { if ! test -d "$1" ; then mkdir "$1" # > /dev/null #echo "Mk: ""$1" fi } function UnNivel() # Recursiva!! { local IFILE="$1" local OFILE="$2" local OOFILE=`echo "$OFILE" | cut -b 3-` local FILE_L1="A" local declare NAMEARRAY NIVEL=`expr $NIVEL + 1` PREFIJO="" for((i=1;i<$NIVEL;i++)) do PREFIJO="../$PREFIJO" done #echo IFILE: $IFILE #echo OFILE: $OFILE #echo OOFILE: $OOFILE find "$IFILE" -maxdepth 1 -printf "%f\n"> $TMPFILE readarray -t NAMEARRAY < $TMPFILE rm $TMPFILE #echo "Nivel $NIVEL - $PREFIJO - $IFILE" for FILE_L1 in "${NAMEARRAY[@]}" do #echo "$FILE_L1" | grep -i ARMA # Es un archivo if test -f "$IFILE"/"$FILE_L1" ; then # target name #Absolute CreateSLink "$IFILE/$FILE_L1" "$OFILE/$FILE_L1" # enlazar fichero #Relative #RELATIVE=`realpath --relative-to="$ORIGENREL" "$IFILE/$FILE_L1"` #echo "-->" "$IFILE/$FILE_L1" "-->" "$RELATIVE" #CreateSLink "$PREFIJO""$ORIGENREL""$OOFILE"/"$FILE_L1" "$OFILE"/"$FILE_L1" # enlazar fichero #CreateSLink "$ORIGENREL""$RELATIVE" "$OFILE"/"$FILE_L1" # enlazar fichero #../../3_MyBook_VideosTst/./Big Poof/Season 2/episode uno.mpeg --> ./Big Poof/Season 2/episode uno.mpeg # $OFILE empieza por './', a ver si se puede quitar. Pero sólo aquí. Hecho. #Problema. Las peliculas en raiz deben empezar por ./, no ../ # tambien pasa en Raiz de Big Bang. #Problema dos: se pierden los dobles espacios en los nombres. Corregido. Era en la creación de OOFILE, quizás otros. Todas las variables entre comillas individuales. # /Arma letal VOS / --> # /Arma letal VOS / fi # Es un directorio if test -d "$IFILE"/"$FILE_L1" ; then CreateDir "$OFILE"/"$FILE_L1" # crear directorio UnNivel "$IFILE"/"$FILE_L1" "$OFILE"/"$FILE_L1" # Recorrer el siguiente nivel fi done NIVEL=`expr $NIVEL - 1` }
$LOGDUP rm $LOGDUP
NIVEL=0 cd "$DESTINO" #UnNivel "$ORIGEN" "$DESTINO" UnNivel "$ORIGEN" "." echo "Done." if [ -f $LOGDUP ]; then echo "See $LOGDUP for list of non links found on target" fi .......................++- -- Cheers / Saludos, Carlos E. R. (from openSUSE 15.1 (Legolas))