to dir
Find target of symbolic link (and maybe change it)
rev 24 oct 2022
Category: shell cli bash symlinks

» goal↓   chosen↓   change target↓   alternates↓   resources↓

.........................
✶ goal, use case:

  I use symbolic links a lot, and i also end up changing
  directory names a lot. Not a good combination  :D
  Need a way to find links that are pointing to old target,
  and ideally to batch change them to new target.

.........................
✶ the chosen method:

  $ ls -l `find . -type l` | grep <searchterm>

  This one is good enough for me, as i usually want
  to do it by hand, since other filenames etc may
  have changed as well, and i'd rather eyeball it
  and change manually.

  Script listed below in resources if i would want to change many at once.

.........................
✶ change the target:

  # without having to delete the symlink first
  # (which may cause problem is some program is using it or something).
  # use -f flag to ln -s:
  $ ln -sf /new/path symlinkname

  # https://www.unix.com/unix-for-dummies-questions-and-answers/53319-change-target-symbolic-link.html
  #  This page has links at bottom to other answers and info.

.........................
✶ alternate ways to do:

  $ ls -l `find . -type l` | grep <searchterm>

  $ readlink
     # shows the target, but doesn't show the source.
     #   not useful if i want to see which source link to change.
     # https://serverfault.com/questions/76042/find-out-symbolic-link-target-via-command-line

  $ find . -lname '*CPWP*'
     # again, shows the target, have to do extra stuff to catch the symlink name.
     # https://unix.stackexchange.com/questions/404992/how-do-i-find-symbolic-links-where-target-path-matches-a-pattern


.......................................................
➽  resources: 

  * man page for making symbolic links:
      $ man ls

  * How to see full absolute path of a symlink:
      https://stackoverflow.com/questions/16017500/how-to-see-full-absolute-path-of-a-symlink
      https://stackoverflow.com/questions/29789204/bash-how-to-get-real-path-of-a-symlink

  * Follow symbolic link chains:
      https://serverfault.com/questions/115856/how-to-list-symbolic-link-chains
      [pub 2010-2019, retr 24 oct 2022]

  * Bash script to get symlink target
      Will show source and target.
      # find and ls is good enough for me.
      #  Maybe this is more precises?
      https://linuxhint.com/bash-script-get-symlink-target/
      [pub 2021, retr 24 oct 2022]

  * Bash script to change multiple symbolic link targets:
     # uses readlink, sed, ln -s
     https://www.unix.com/shell-programming-and-scripting/212851-change-reference-symbolic-link.html

_______________________________________________________
begin 24 oct 2022
-- 0 --