I have a directory with thousands of files, and I want to run a software multiple times in different directories with the same input files without copy the input in each directory, I have created a symbolic link to each file with the next code

ln -s /path/to/bayestraits/*_b.txt /path/to/bayestraits/dependiente_1

the directory structure is as follow


and I want to run the next code in each directory

for file in *_b.txt; do BayesTraitsV3 cyanomarkers_2.nex $file < Discrete_Dependent.txt ; done

the trouble is that when I run the code, the output file is redirected to bayestraits directory no to dependiente_1 directory

  • Is your current working directory one of the dependiente_? directories when you run your loop, or are you located in the bayestraits directory? Can you explicitly tell your program where to create its output files with an option?
    – Kusalananda
    Mar 26, 2020 at 9:43

1 Answer 1


Instead of symbolic links you could create hard links without the -s flag:

ln /path/to/bayestraits/*_b.txt /path/to/bayestraits/dependiente_1

To overwrite your existing symbolic links without removing them, use the -f (force) flag

ln -f /path/to/bayestraits/*_b.txt /path/to/bayestraits/dependiente_1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .