Skip to main content
fix code errors and integrate it into the surrounding text
Source Link
David Z
  • 6.8k
  • 3
  • 46
  • 51

This bash command should do it for you:

find /home/user/public_html/qa/ -type l -lname '/home/user/public_html/dev/*' -printf 'ln -nsf "$(readlink "%p" | sed s/dev/qa/)" "$(echo "%p" | sed s/dev/qa/)"\n' > script.sh

It uses find to identify all files in the qa directory that are symbolic links with a target that's in the dev directory, and for each one, it prints out a bash command that will replace the link with a link to the equivalent path in qa/. After you run this, just execute the generated script with

bash script.sh

You might want to examine it manually first to make sure it worked.

Here's a more verbose version of the above find command broken up on to multiple lines for easier viewingreading (though I wouldn't necessarily write it this way in practice):

SRC_DIR=SRC_DIR="/home/user/public_html/qa/qa"
OLD_TARGET=OLD_TARGET="/home/user/public_html/dev/dev"
SED_SCRIPT=sSUB="s/dev/qa/"

find $SRC_DIR -type l \
  -lname "$OLD_TARGET*""$OLD_TARGET/*" -printf \
  'ln -nsf "$(readlink "%p"|sed '$SED_SCRIPT'$SUB)" "$(echo "%p"|sed '$SED_SCRIPT'$SUB)"\n'\
 > script.sh

This bash command should do it for you:

find /home/user/public_html/qa/ -type l -lname '/home/user/public_html/dev/*' -printf 'ln -nsf "$(readlink "%p" | sed s/dev/qa/)" "$(echo "%p" | sed s/dev/qa/)"\n' > script.sh

It uses find to identify all files in the qa directory that are symbolic links with a target that's in the dev directory, and for each one, it prints out a bash command that will replace the link with a link to the equivalent path in qa/. After you run this, just execute the generated script with

bash script.sh

You might want to examine it manually first to make sure it worked.

Here's the find command broken up on to multiple lines for easier viewing:

SRC_DIR=/home/user/public_html/qa/
OLD_TARGET=/home/user/public_html/dev/
SED_SCRIPT=s/dev/qa

find $SRC_DIR -type l \
  -lname "$OLD_TARGET*" -printf \
  'ln -nsf "$(readlink "%p"|sed '$SED_SCRIPT')" "$(echo "%p"|sed '$SED_SCRIPT')"\n'\
 > script.sh

This bash command should do it for you:

find /home/user/public_html/qa/ -type l -lname '/home/user/public_html/dev/*' -printf 'ln -nsf "$(readlink "%p" | sed s/dev/qa/)" "$(echo "%p" | sed s/dev/qa/)"\n' > script.sh

It uses find to identify all files in the qa directory that are symbolic links with a target that's in the dev directory, and for each one, it prints out a bash command that will replace the link with a link to the equivalent path in qa/. After you run this, just execute the generated script with

bash script.sh

You might want to examine it manually first to make sure it worked.

Here's a more verbose version of the above find command for easier reading (though I wouldn't necessarily write it this way in practice):

SRC_DIR="/home/user/public_html/qa"
OLD_TARGET="/home/user/public_html/dev"
SUB="s/dev/qa/"

find $SRC_DIR -type l \
  -lname "$OLD_TARGET/*" -printf \
  'ln -nsf "$(readlink "%p"|sed $SUB)" "$(echo "%p"|sed $SUB)"\n'\
 > script.sh
broke out variables to further improve legibility from generic standpoint
Source Link

This bash command should do it for you:

find /home/user/public_html/qa/ -type l -lname '/home/user/public_html/dev/*' -printf 'ln -nsf "$(readlink "%p" | sed s/dev/qa/)" "$(echo "%p" | sed s/dev/qa/)"\n' > script.sh

It uses find to identify all files in the qa directory that are symbolic links with a target that's in the dev directory, and for each one, it prints out a bash command that will replace the link with a link to the equivalent path in qa/. After you run this, just execute the generated script with

bash script.sh

You might want to examine it manually first to make sure it worked.

Here's the find command broken up on to multiple lines for easier viewing:

find SRC_DIR=/home/user/public_html/qa/
OLD_TARGET=/home/user/public_html/dev/
SED_SCRIPT=s/dev/qa

find $SRC_DIR -type l \
  -lname '/home/user/public_html/dev/*'"$OLD_TARGET*" -printf \
  'ln -nsf "$(readlink "%p"|sed s/dev/qa/'$SED_SCRIPT')" "$(echo "%p"|sed s/dev/qa/'$SED_SCRIPT')"\n'\
 > script.sh

This bash command should do it for you:

find /home/user/public_html/qa/ -type l -lname '/home/user/public_html/dev/*' -printf 'ln -nsf "$(readlink "%p" | sed s/dev/qa/)" "$(echo "%p" | sed s/dev/qa/)"\n' > script.sh

It uses find to identify all files in the qa directory that are symbolic links with a target that's in the dev directory, and for each one, it prints out a bash command that will replace the link with a link to the equivalent path in qa/. After you run this, just execute the generated script with

bash script.sh

You might want to examine it manually first to make sure it worked.

Here's the find command broken up on to multiple lines for easier viewing:

find /home/user/public_html/qa/ -type l \
  -lname '/home/user/public_html/dev/*' -printf \
  'ln -nsf "$(readlink "%p"|sed s/dev/qa/)" "$(echo "%p"|sed s/dev/qa/)"\n'\
 > script.sh

This bash command should do it for you:

find /home/user/public_html/qa/ -type l -lname '/home/user/public_html/dev/*' -printf 'ln -nsf "$(readlink "%p" | sed s/dev/qa/)" "$(echo "%p" | sed s/dev/qa/)"\n' > script.sh

It uses find to identify all files in the qa directory that are symbolic links with a target that's in the dev directory, and for each one, it prints out a bash command that will replace the link with a link to the equivalent path in qa/. After you run this, just execute the generated script with

bash script.sh

You might want to examine it manually first to make sure it worked.

Here's the find command broken up on to multiple lines for easier viewing:

SRC_DIR=/home/user/public_html/qa/
OLD_TARGET=/home/user/public_html/dev/
SED_SCRIPT=s/dev/qa

find $SRC_DIR -type l \
  -lname "$OLD_TARGET*" -printf \
  'ln -nsf "$(readlink "%p"|sed '$SED_SCRIPT')" "$(echo "%p"|sed '$SED_SCRIPT')"\n'\
 > script.sh
fix quoting to allow using with filenames that include spaces
Source Link
David Z
  • 6.8k
  • 3
  • 46
  • 51

This bash command should do it for you:

find /home/user/public_html/qa/ -type l -lname '/home/user/public_html/dev/*' -printf 'ln -nsf $"$(readlink %p"%p" | sed s/dev/qa/)" $"$(echo %p"%p" | sed s/dev/qa/)\n'"\n' > script.sh

It uses find to identify all files in the qa directory that are symbolic links with a target that's in the dev directory, and for each one, it prints out a bash command that will replace the link with a link to the equivalent path in qa/. After you run this, just execute the generated script with

bash script.sh

You might want to examine it manually first to make sure it worked.

Here's the find command broken up on to multiple lines for easier viewing:

find /home/user/public_html/qa/ -type l \
  -lname '/home/user/public_html/dev/*' -printf \
  'ln -nsf $"$(readlink %p|sed"%p"|sed s/dev/qa/)" $"$(echo %p|sed"%p"|sed s/dev/qa/)\n'\"\n'\
 > script.sh

This bash command should do it for you:

find /home/user/public_html/qa/ -type l -lname '/home/user/public_html/dev/*' -printf 'ln -nsf $(readlink %p | sed s/dev/qa/) $(echo %p | sed s/dev/qa/)\n' > script.sh

It uses find to identify all files in the qa directory that are symbolic links with a target that's in the dev directory, and for each one, it prints out a bash command that will replace the link with a link to the equivalent path in qa/. After you run this, just execute the generated script with

bash script.sh

You might want to examine it manually first to make sure it worked.

Here's the find command broken up on to multiple lines for easier viewing:

find /home/user/public_html/qa/ -type l \
  -lname '/home/user/public_html/dev/*' -printf \
  'ln -nsf $(readlink %p|sed s/dev/qa/) $(echo %p|sed s/dev/qa/)\n'\
 > script.sh

This bash command should do it for you:

find /home/user/public_html/qa/ -type l -lname '/home/user/public_html/dev/*' -printf 'ln -nsf "$(readlink "%p" | sed s/dev/qa/)" "$(echo "%p" | sed s/dev/qa/)"\n' > script.sh

It uses find to identify all files in the qa directory that are symbolic links with a target that's in the dev directory, and for each one, it prints out a bash command that will replace the link with a link to the equivalent path in qa/. After you run this, just execute the generated script with

bash script.sh

You might want to examine it manually first to make sure it worked.

Here's the find command broken up on to multiple lines for easier viewing:

find /home/user/public_html/qa/ -type l \
  -lname '/home/user/public_html/dev/*' -printf \
  'ln -nsf "$(readlink "%p"|sed s/dev/qa/)" "$(echo "%p"|sed s/dev/qa/)"\n'\
 > script.sh
Source Link
David Z
  • 6.8k
  • 3
  • 46
  • 51
Loading