10.03.2019 17:40, Carlos E. R. пишет:
Given this tree:
/home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg /home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/notes /home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/Season 6/06x01.mpeg
I want to generate these relative symlinks in this replica tree:
Lore.mpeg --> 3_MyBook_Videos/Lore.mpeg or Lore.mpeg --> ./3_MyBook_Videos/Lore.mpeg
Big Bang/notes --> ../3_MyBook_Videos/Big Bang/notes
Big Bang/Season 6/06x01.mpeg --> ../../3_MyBook_Videos/Big Bang/Season 6/06x01.mpeg
I already have a script that generates the tree using "absolute" paths - not caring that "3_MyBook_Videos" is in fact another symlink. I then wanted to do it with relative symlinks. I did it with code of my own that failed in some of the cases, so I googled for some ready to paste solution, and hit upon "realpath". This also failed, I do not understand the man page, got a headache and a block, so I asked here.
Not that difficult to understand.
$ cat /tmp/foo /home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg /home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/notes /home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/Season 6/06x01.mpeg $ sed 's#/home/cer/FusionTst/Videos/3_MyBook_Videos/##;/.*\/.*/{h;s#[^/][^/]*/#../#g; s#\(.*/\).*$#\1#;x};s#^#3_MyBook_Videos/#;x;G;s#\n##' < /tmp/foo 3_MyBook_Videos/Lore.mpeg ../3_MyBook_Videos/Big Bang/notes ../../3_MyBook_Videos/Big Bang/Season 6/06x01.mpeg