Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert relative symbolic links to absolute symbolic links

Tags:

bash

How can I convert relative symbolic links to absolute symbolic links recursively in bash?

like image 278
Eric Avatar asked Nov 15 '10 17:11

Eric


People also ask

How do you convert an absolute path to a relative path?

The absolutePath function works by beginning at the starting folder and moving up one level for each "../" in the relative path. Then it concatenates the changed starting folder with the relative path to produce the equivalent absolute path.

Are Symlinks relative or absolute?

Symbolic links can either be absolute or relative links. Absolute links are links that specify each portion of the path name; relative links are determined relative to where relative–link specifiers are in a specified path.

Can you make a symbolic link of a symbolic link?

Yes. You can only stack so much symbolic links together before the kernel and/or application refuse to follow the chain.

How do you find the absolute path of a link?

To obtain the full path of a file, we use the readlink command. readlink prints the absolute path of a symbolic link, but as a side-effect, it also prints the absolute path for a relative path. In the case of the first command, readlink resolves the relative path of foo/ to the absolute path of /home/example/foo/.


1 Answers

ln -sf "$(readlink -f "$link")" "$link"
like image 175
thkala Avatar answered Sep 23 '22 07:09

thkala