-1

Mid-switch to Linux I realized I've a large personal and work archive that has over 1100 Windows Shortcuts(.lnk) of both files and folders and it is unusable without them and have been trying to figure out how to convert them to Linux Links and after familiarizing myself with the "ln" command I figured out how to get the NAME, TARGET and PATH for all of the shortcuts into a txt file using the program Shortcut Search and Replace. I then exported into Excel and formatted into something that looks like this, minus the categories on top:

NAME              TARGET PATH                                  PATH

0_Shortcut-name1  Library/Subject/Sub-folder_a/Sub-Sub-Folder  Library/Subject/Sub-folder_b  
0_Shortcut-name2  Library/Subject/Sub-folder_a/image.png       Library/Subject/Sub-folder_b
0_Shortcut-name3  Library/Subject/Sub-folder_a/notes.txt       Library/Subject/Sub-folder_b  
0_Shortcut-name4  Library/Subject/Sub-folder_a/document.docx   Library/Subject/Sub-folder_b  
0_Shortcut-name5  Library/Subject/Sub-folder_a/document.pdf    Library/Subject/Sub-folder_b

Note on the Excel formatting:

  • Since we already have the Name of the shortcut in the first column, we need to remove that in addition to the .lnk that the raw Copy and Paste from 'Shortcut Search and Replace' will give us. Assuming your export in Excel puts Name, Target, Path in Columns A, B, C you would want to use this formula in column D(and drag it down) to do said formatting: =SUBSTITUTE(SUBSTITUTE(C1,"","@",LEN(C1)-LEN(SUBSTITUTE(C1,"",""))),RIGHT(SUBSTITUTE(C1,"","@",LEN(C1)-LEN(SUBSTITUTE(C1,"",""))),(LEN(C1)-FIND("@",SUBSTITUTE(C1,"","@",LEN(C1)-LEN(SUBSTITUTE(C1,"",""))))+1)),"")

Then you can use Find and Replace to remove Drive names and change the "" to a "/" as per Linux standards

IMPORTANT: You'll need to open the text file with a text editor under Linux that gives you the option of saving with a different line ending and you must choose Linux/Unix otherwise the wonderful scripts provided in the comments will not work. (They're delimited by a single tab in the txt file.)

Unfortunately, this is where my expertise ends and I would be delighted if a bash wizard were to write a script that does something like this:
1. Choose what location mnt/ something to append to the start of the address (before Library)
(bonus: Symbolic link by default, but have the option of choosing a hard link)
2. Open the file and Read Line 1
3. Get Path, CD to its location
4. Execute the "ln" Command to make a Symbolic link using NAME & TARGET PATH, creating the Hard/Sym link.
5+ Move on to Line 2 & Repeat until exhaustion of the list.

Solved

Massive thanks to Renaud Pacalet for providing this elegant piece of bash that solved my issues.

prefix='/mnt/'
while IFS=$'\t' read -r name target path; do
  ln -s "$prefix$target" "$prefix$path/$name"
done < some/path/tab-separated-file

Posted by Renaud Pacalet
Retrieved 2025-11-06 License - CC BY-SA 4.0

P.S. There will inevitably be a few broken Links that you'll need to fix by hand, some due to the difference between Case Insensitive Windows and Case Sensitive Linux. In addition to that, names containing special symbols, break at some point in the formatting. I personally changed the code so as to make all of the shortcuts share the same Path, essentially make them all in the same folder so you can inspect which one is broken and why and then modify the text file to fix those issues and after everything is fixed I would run the code as intended.

3
  • you've provided 5 sample inputs; consider updating the question with the steps you'd perform to manually create the 5 associated (linux) links, making sure to demonstrate the various options you want to implement (eg, different mount points or parent directories, soft vs hard links) Commented Sep 19 at 23:02
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Commented Sep 20 at 1:57
  • fyi - this is off-topic, as the linux tag description explains. Also, you haven't shown any work of your own; you only posted some requirements and left everything to the Community. Commented Sep 21 at 14:02

2 Answers 2

2

Using a bash while loop, the read builtin, the IFS (Input Field Separator) variable, and the ln command:

prefix='/mnt/'
while IFS=$'\t' read -r name target path; do
  ln -s "$prefix$target" "$prefix$path/$name"
done < some/path/tab-separated-file

Use an absolute path for variable prefix, as it will allow you to run the script from anywhere. For hard links simply remove the -s option of ln.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for the answer, I will go through bash's syntax so I can fully understand what it does. On first glance I don't understand where and how the code uses the path to create the Link in the exact place where the Shortcut is. The "some/path/tab-separated-file" is basically a hardcoded location for the Name-Target-Path file, right? If it isn't too much to ask I would appreciate a more elaborate breakdown, but even so I'm very grateful, thank you.
The path is put in variable path by the read command, just like the target and the name in variables name and target. Explaining in details even such a small script would take too long (redirections, variables, exit statuses, control structures, etc.) and would probably contain inaccuracies. The best is probably to use the manual (type man ln in a terminal to see the manual of command ln) or help for bash built-ins (type help read for builtin read). And for everything else man bash is your friend.
I would like to thank you immensely for your help, I went over everything you suggested, learned about the Linux operators, Input / Output redirection, the In Field Separator etc. and fixed my misunderstanding of the ln command's syntax. (Though I have to say that I'm still a bit cloudy on how feeding the file to the read function inside the while loop makes it automatically go through it line by line instead of just getting stuck on the first one.) Which allowed me to recreate the discrete steps of the code to realize it wasn't working because my text file had the windows line-ending.
1

I think what you need is basically a shell script like this:

#!/bin/bash

# Usage:
#   ./shortcuts.sh shortcuts.txt /mnt/data symlink
#
# Args:
#   1: Input file (tab-delimited: NAME  TARGET  PATH)
#   2: Base path (prefix to add before Library/...)
#   3: Link type (symlink|hardlink) -> defaults to be symlink

INPUT_FILE="$1"
BASE_PATH="$2"
LINK_TYPE="${3:-symlink}"  # default is symlink

if [[ -z "$INPUT_FILE" || -z "$BASE_PATH" ]]; then
  echo "Usage: $0 <input.txt> <base-path> [symlink|hardlink]"
  exit 1
fi

if [[ ! -f "$INPUT_FILE" ]]; then
  echo "Error: input file '$INPUT_FILE' not found!"
  exit 1
fi

# Skip header and loop in lines
tail -n +2 "$INPUT_FILE" | while IFS=$'\t' read -r NAME TARGET DEST_PATH; do
  SRC="$BASE_PATH/$TARGET"
  DEST_DIR="$BASE_PATH/$DEST_PATH"
  DEST="$DEST_DIR/$NAME"

  # Creation of destination directory if not exists
  mkdir -p "$DEST_DIR"

  # Create link depending on type
  if [[ "$LINK_TYPE" == "hardlink" ]]; then
    ln "$SRC" "$DEST"
    echo "Created hardlink: $DEST → $SRC"
  else
    ln -s "$SRC" "$DEST"
    echo "Created symlink: $DEST → $SRC"
  fi
done

2 Comments

Thank you so much for the contribution, I'm just going to bed, but I will test it tomorrow and report back. One think that I missed, because some shortcuts are to files and not folders, is a 4th column for file extension. I just finished writing another Excel function to generate just that and my latest text file contains, and I've reordered them based on usage: Path, Target, Name, Extension, where if it's a folder there's nothing after the 3rd column. Again, much appreciated, will report back tomorrow.
Reporting back, it works almost perfectly and there's no need to specify the extension, judging by the symlinks that were created. However, there's the following issue: I created a "Shortcut-Conversion-Testing" folder (under Windows if it makes any difference) with 1 subfolder,1 sub-sub and 1 sub-sub-sub folder inside and a small amount of shortcuts within each. I then made a formatted text file for these shortcuts' Name, Target and Path. After running the script it created duplicate folders that contained the correct and 100% links. When I used dir it showed me Folder1 and under it Folder1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.