I am trying to create about 100,000 symbolic links. The location of the link is in a folder which I want to define at the same time as I create the link.

For example

ln -s File1 FolderA/File1

Once I figure out if this is possible, I'd like to just use a loop to create all the links. I haven't been able to find a way to do this (apologies if it is trivial).

  • Are you trying to do mkdir -p FolderA/File1 && ln -s -T File1 FolderA/File1 for each in a set of directories. Mar 15, 2020 at 19:04
  • I am not sure what -T does, but FolderA/File1 will just point to the original File1. And FolderA does not exist at the time of initiating the command.
    – ZakS
    Mar 15, 2020 at 19:06
  • Yes the File one will not point to the correct File1, but if we fix that bit. Is it what you want to do? Mar 15, 2020 at 19:07
  • yes, I think what you describe is my goal
    – ZakS
    Mar 15, 2020 at 19:11

1 Answer 1


Something like this:

set -e
mkdir -p FolderA
cd FolderA
for file in "${original_dir}"/*
  ln -s -t . "$file"

Not tested

  • Use for instead of foreach if using bash or sh
    – GMaster
    Mar 15, 2020 at 21:48
  • @GMaster sorry my bad. It would have been OK for you to fix it. Mar 16, 2020 at 12:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.