How to create symbolic links to all files (class of files) in a directory?

ln does take multiple arguments, but don't forget to give a target directory in that case.

So, in your example . is the target directory, so it should be as easy as

ln -s ../source/*.bar .

From man ln; the command above uses the 3rd form:

ln [OPTION]... [-T] TARGET LINK_NAME   (1st form)
ln [OPTION]... TARGET                  (2nd form)
ln [OPTION]... TARGET... DIRECTORY     (3rd form)
ln [OPTION]... -t DIRECTORY TARGET...  (4th form)
  • In the 1st form, create a link to TARGET with the name LINK_NAME.
  • In the 2nd form, create a link to TARGET in the current directory.
  • In the 3rd and 4th forms, create links to each TARGET in DIRECTORY.

You can try recursively either with using globstar (bash/zsh set by: shopt -s globstar):

ls -vs ../**/*.bar .

Note: Added -v for verbose.

Or if the list is too long, using find utility:

find .. -name \*.bar -exec ln -vs "{}" dest/ ';'

This will create links in dest/, or change it to . for current folder.


Use find

certainDir="/path/to/dir"
find -name "*.bar" -exec ln -s {} "$certainDir" \;

Also, remember to use full paths (where possible) with symlinks.