{"id":2037,"date":"2016-10-09T10:22:00","date_gmt":"2016-10-09T18:22:00","guid":{"rendered":"http:\/\/systemsolver.com\/StatlerBlog\/?p=2037"},"modified":"2016-10-09T10:22:00","modified_gmt":"2016-10-09T18:22:00","slug":"linux-convert-windows-links-to-linux-symbolic-links","status":"publish","type":"post","link":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/2016\/10\/09\/linux-convert-windows-links-to-linux-symbolic-links\/","title":{"rendered":"Linux convert windows links to linux symbolic links"},"content":{"rendered":"<p><a href=\"http:\/\/www.linuxforums.org\/forum\/miscellaneous\/172805-convert-windows-shortcuts-into-linux-links-4.html\">http:\/\/www.linuxforums.org\/forum\/miscellaneous\/172805-convert-windows-shortcuts-into-linux-links-4.html<\/a><\/p>\n<p style=\"padding-left: 30px;\">\n<p style=\"padding-left: 30px;\">#!\/bin\/bash<\/p>\n<p style=\"padding-left: 30px;\">######################################################################<br \/>\n# #<br \/>\n# lnk2symlink by jesus.guerrero.botella at gmail dot com, #<br \/>\n# search for windows .lnk files on a given directory, and creates #<br \/>\n# symlinks according to the info contained on those files #<br \/>\n# #<br \/>\n# This script is provided without any kind of implicit or explicit #<br \/>\n# guarantee, and is licensed under the GNU General Public License v3 #<br \/>\n# or later if available. More about licenses on the following URL: #<br \/>\n# #<br \/>\n# http:\/\/www.gnu.org\/licenses\/licenses.html #<br \/>\n# #<br \/>\n######################################################################<\/p>\n<p style=\"padding-left: 30px;\">VERSION=20101220<br \/>\nPROGRAM_NAME=$(basename $0)<\/p>\n<p style=\"padding-left: 30px;\">die() {<br \/>\ncase $1 in<br \/>\nnon_linkable_fs)<br \/>\necho &#8220;The target filesystem doesn&#8217;t support symlinks.&#8221;<br \/>\nexit 11<br \/>\n;;<br \/>\nln_error)<br \/>\necho &#8220;Undefined error while symlinking.&#8221;<br \/>\nexit 10<br \/>\n;;<br \/>\nnumber_of_args)<br \/>\necho<br \/>\necho &#8220;[E] Incorrect number of arguments.&#8221;<br \/>\necho &#8220;Usage: $0 origin_dir destination_dir dos_drive_basedir&#8221;<br \/>\necho<br \/>\necho &#8221; origin_directory is the directory containing the .lnk&#8221;<br \/>\necho &#8221; files. It will be recursed.&#8221;<br \/>\necho<br \/>\necho &#8221; destination_directory is the directory where you want&#8221;<br \/>\necho &#8221; the symlinks to be created.&#8221;<br \/>\necho<br \/>\necho &#8221; dos_drive_basedir is the linux directory that will be&#8221;<br \/>\necho &#8221; used in place of \\&#8221;C:\\\\\\&#8221; (or whatever drive) when looking&#8221;<br \/>\necho &#8221; for the link destination.&#8221;<br \/>\necho<br \/>\necho &#8220;Typical usage case:&#8221;<br \/>\necho &#8221; &#8220;$(basename $0)&#8221; ~\/Desktop\/ ~\/bin\/ ~\/.wine\/drive_c\/&#8221;<br \/>\necho<br \/>\nexit 12<br \/>\n;;<br \/>\ncould_not_create_dest)<br \/>\necho &#8220;Couldn&#8217;t create destination directory.&#8221;<br \/>\nexit 13<br \/>\n;;<br \/>\norig_not_found)<br \/>\necho &#8220;Origin directory not found or not readable.&#8221;<br \/>\nexit 14<br \/>\n;;<br \/>\ncould_not_create_symlink)<br \/>\necho &#8220;Couldn&#8217;t create symlink.&#8221;<br \/>\nexit 15<br \/>\n;;<br \/>\n*)<br \/>\necho &#8220;Undefined error.&#8221;<br \/>\nexit 20<br \/>\n;;<br \/>\nesac<br \/>\n}<\/p>\n<p style=\"padding-left: 30px;\">case $# in<br \/>\n3)<br \/>\nORIG=&#8221;$1&#8243;<br \/>\nDEST=&#8221;$2&#8243;<br \/>\nDOS_DRIVE=&#8221;$3&#8243;<br \/>\n;;<br \/>\n*)<br \/>\ndie number_of_args<br \/>\n;;<br \/>\nesac<\/p>\n<p style=\"padding-left: 30px;\"># Test for the existence of the required directories<br \/>\n[ ! -d &#8220;$DEST&#8221; ] &amp;&amp; mkdir &#8220;$DEST&#8221;<br \/>\n[ ! -d &#8220;$DEST&#8221; ] &amp;&amp; die could_not_create_dest<br \/>\n[ ! -d &#8220;$ORIG&#8221; ] &amp;&amp; die orig_not_found<\/p>\n<p style=\"padding-left: 30px;\"># Test the symlinking tool, if it fails then probably<br \/>\n# your FS doesn&#8217;t support soft links.<br \/>\nTESTLN=&#8221;$DEST\/test-$RANDOM$RANDOM$RANDOM$RANDOM&#8221;<br \/>\nln -s &#8220;$HOME&#8221; &#8220;$TESTLN&#8221; &gt; \/dev\/null 2&gt;&amp;1 || die non_linkable_fs<br \/>\nrm -f &#8220;$TESTLN&#8221;<\/p>\n<p style=\"padding-left: 30px;\">echo<br \/>\necho &#8220;Where to look for .lnk files:&#8221;<br \/>\necho &#8221; \\&#8221;$ORIG\\&#8221;&#8221;<br \/>\necho &#8220;Where to look put symlinks:&#8221;<br \/>\necho &#8221; \\&#8221;$DEST\\&#8221;&#8221;<br \/>\necho &#8220;The DOS base drive is:&#8221;<br \/>\necho &#8221; \\&#8221;$DOS_DRIVE\\&#8221;&#8221;<br \/>\necho<br \/>\necho &#8220;Finding files, this may take a while&#8230;&#8221;<br \/>\necho<\/p>\n<p style=\"padding-left: 30px;\">find &#8220;$ORIG&#8221; -iname &#8216;*.lnk&#8217; | while read LNK_FILE<br \/>\ndo<br \/>\necho<br \/>\necho &#8220;[*] Found: \\&#8221;$LNK_FILE\\&#8221;&#8221;<\/p>\n<p style=\"padding-left: 30px;\">CANDIDATE_STRING=$(strings &#8220;$LNK_FILE&#8221; | grep &#8216;:\\\\&#8217;)<br \/>\nLINUX_PATH_TO_EXE_FILE=$(echo &#8220;$CANDIDATE_STRING&#8221; | \\<br \/>\ntail -n1 | \\<br \/>\nsed -e &#8216;s#.*[a-zA-Z]:\\\\#'&#8221;$DOS_DRIVE&#8221;&#8216;\/#&#8217; | \\<br \/>\nsed -e &#8216;s#\\\\#\/#g&#8217; | \\<br \/>\nsed -e &#8216;s#\/\/#\/#g&#8217; )<br \/>\nLINUX_PATH_TO_EXE_FILE=$(realpath &#8220;$LINUX_PATH_TO_EXE_FILE&#8221;)<br \/>\necho &#8220;[i] The candidate file string is:&#8221;<br \/>\necho &#8220;[i] \\&#8221;$LINUX_PATH_TO_EXE_FILE\\&#8221;&#8221;<\/p>\n<p style=\"padding-left: 30px;\">SYMLINK_NAME=&#8221;$DEST&#8221;\/$(basename &#8220;$LINUX_PATH_TO_EXE_FILE&#8221;)<br \/>\nif [ ! -L &#8220;$SYMLINK_NAME&#8221; ]; then<br \/>\nif [ -r &#8220;$SYMLINK_NAME&#8221; ]; then<br \/>\necho &#8220;[i] File with the same name detected, but it&#8217;s not a symlink.&#8221;<br \/>\necho &#8220;[i] I will add a RANDOM suffix to the symlink name.&#8221;<br \/>\nSYMLINK_NAME=&#8221;${SYMLINK_NAME}-${RANDOM}&#8221;<br \/>\nfi<br \/>\nfi<br \/>\nif [ -r &#8220;$LINUX_PATH_TO_EXE_FILE&#8221; ]; then<br \/>\necho &#8220;[i] Running: ln -nfs \\&#8221;$LINUX_PATH_TO_EXE_FILE\\&#8221; \\&#8221;$SYMLINK_NAME\\&#8221;&#8221;<br \/>\nln -nfs &#8220;$LINUX_PATH_TO_EXE_FILE&#8221; &#8220;$SYMLINK_NAME&#8221; || die could_not_symlink<br \/>\nelse<br \/>\necho &#8220;[E] This .lnk file points to a file that doesn&#8217;t exist.&#8221;<br \/>\necho &#8220;[E] Couldn&#8217;t create this symlink, sorry.&#8221;<br \/>\nfi<br \/>\ndone<\/p>\n<p style=\"padding-left: 30px;\">\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>http:\/\/www.linuxforums.org\/forum\/miscellaneous\/172805-convert-windows-shortcuts-into-linux-links-4.html #!\/bin\/bash ###################################################################### # # # lnk2symlink by jesus.guerrero.botella at gmail dot com, # # search for windows .lnk files on a given directory, and creates # # symlinks according to the info contained on those files # # # # This script is provided without any kind of implicit or explicit # # guarantee, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-2037","post","type-post","status-publish","format-standard","hentry","category-general"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/posts\/2037","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/comments?post=2037"}],"version-history":[{"count":0,"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/posts\/2037\/revisions"}],"wp:attachment":[{"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/media?parent=2037"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/categories?post=2037"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/tags?post=2037"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}