Haakonkas
Haakonkas

Reputation: 1041

Create symbolic links from list of files

I have a folder which contains multiple files and one file (file_list), which lists the files of interest. I want to create symbolic links to all files that match the file names in the list. Is there an easy way to do this in bash?

Example:

Upvotes: 0

Views: 2700

Answers (2)

Mark
Mark

Reputation: 2428

Something like this should work as cp -s makes symbolic links

cp -s $(cat file_list) /path/to/destination/dir/

Upvotes: 0

PesaThe
PesaThe

Reputation: 7499

Something like this should do:

#!/usr/bin/env bash 

while IFS= read -r file; do
    [[ -e /some/path/$file ]] && ln -s "/some/path/$file" /dest/path
done < file_list

Upvotes: 2

Related Questions