How to link a selected set of files from one directory to another in Linux?


Say for example, in the source directory I have the following files:

  1. abc.r
  3. pqr.fam
  4. lmn.bim
  5. uvw.r

Now I need to link only the items 1,2 and 5 only (listed above). Most importantly I need to link all the 3 files together (i.e. link all the 3 files at the same time).

I know how to link 1 file at a time (ln -s sourceDirectory/fileName targetDirectory/), but not multiple files at once.
I found ways to do this when the file name prefixes has some pattern (for example, link all the files where the names start with letter "f"), but in my case, I do not have any such pattern. My file names are different.


Try this:


for file in a.txt b.txt c.txt
    ln -s /sourcedir/"${file}" /targetdir/

Since you only have a list, you have to iterate through the list.

Answered By – Nic3500

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published