0

I am trying to replace all text file symlink pointers to replace _F-ss with empty string as below but running into below error, any guidance on how to fix this?

find . -name "*.txt" -type l | xargs 'ln -nsf "$(readlink "%p" | sed s/_F-ss//)"'

Error:-

xargs: ln -nsf "$(readlink "%p" | sed s/_F-ss//)": No such file or directory
wisecrack
  • 315
  • 2
  • 12
  • `$(..)` is not expanded under single quotes, double quote it – Inian Aug 27 '20 at 18:46
  • @Inian - you mean like `find . -name "*.txt" -type l | xargs "ln -nsf "$(readlink "%p" | sed s/_F-ss//)""` – wisecrack Aug 27 '20 at 18:49
  • it throws the erorr `xargs: ln -nsf : No such file or directory` – wisecrack Aug 27 '20 at 18:54
  • You can drop the outer quotes and just do `find . -name "*.txt" -type l | xargs ln -nsf "$(readlink "%p" | sed s/_F-ss//)"` – Inian Aug 27 '20 at 18:58
  • No errors but that didnt update the symlinks – wisecrack Aug 27 '20 at 19:00
  • 1
    Can you try `find . -name "*.txt" -type l | xargs -I {} bash -c 'ln -nsf {} "$(readlink "%p" | sed s/_F-ss//)"' ` – Inian Aug 27 '20 at 19:05
  • that didn't help ,BTW I am running this on a mac – wisecrack Aug 27 '20 at 19:09
  • This should (hopefully) `find . -name "*.txt" -type l -exec ln -s '{}' "$(readlink "%p" | sed s/_F-ss//)" ';'` – Inian Aug 27 '20 at 19:10
  • I keep getting `ln: : No such file or directory` – wisecrack Aug 27 '20 at 19:12
  • Does `find . -name "*.txt" -type l` return any results at all? – Inian Aug 27 '20 at 19:13
  • yes,it shows all the symlink .txt files – wisecrack Aug 27 '20 at 19:14
  • What about `echo "$(readlink "%p" | sed s/_F-ss//)"` – Inian Aug 27 '20 at 19:15
  • I ran `find . -name "*.txt" -type l -exec echo "$(readlink "%p" | sed s/_F-ss//)" \;` ,it printed a bunch of empty lines – wisecrack Aug 27 '20 at 19:18
  • So the whole problem is your `"$(readlink "%p" | sed s/_F-ss//)"` is empty. – Inian Aug 27 '20 at 19:19
  • wondering why because `readlink P-maldives-X3_M-TPHN_V-u__m-3.3.txt` shows `P-maldives_M-TPHN_V-u_F-ss__m-3.3.txt` – wisecrack Aug 27 '20 at 19:27
  • Which directory are you running this from? Are you running with %p and it is working? – Inian Aug 27 '20 at 19:34
  • I ran a seperate command as `readlink P-maldives-X3_M-TPHN_V-u__m-3.3.txt | sed 's/_F-ss//g'` and it works,am running it from a directory which has all *.txt files – wisecrack Aug 27 '20 at 19:41
  • what does `%p` do here? – wisecrack Aug 27 '20 at 19:43
  • Get `readlink "%p" | sed s/_F-ss//` working first. Then get `ln -nsf "$(readlink "%p" | sed s/_F-ss//)"` working. THEN try it with `find | xargs` – Ed Morton Aug 27 '20 at 20:03
  • `readlink "%p"` seems to be one thats causing this,why is `%p` not taking the find output – wisecrack Aug 27 '20 at 20:18
  • I think the part in `$(..)` is executed before `find`. Can you try `find . -name "*.txt" -type l | xargs -L1 readlink | sed 's/_F-ss//' | xargs -L1 ln -nsf` – Walter A Aug 27 '20 at 21:18
  • @wisecrack `readlink` takes a file name as an argument. You aren't giving it a file name as an argument but you are giving it a string `"%p"` as an argument which may or may not be desirable. See [my earlier comment](https://stackoverflow.com/questions/63622366/how-to-batch-update-all-symlink-pointers-to-replace-f-ss-with-empty-string#comment112506627_63622366) for how to make progress. – Ed Morton Aug 28 '20 at 00:48

0 Answers0