I'm under linux and use bash as my login shell . I need to make softlink to a bunch of files. Thoes files are listed in a text file , let's say file_list.txt . Every line in file_list.txt is just a full path of one target file need to be linked . Although I don't know exactly how to, I do believe there is way to combine "cat " "| " and "ln -s " together to make the job done whithin one shell command . So need your help .
If you want the names in the current directory (or any one directory), and if the names in the file are all absolute names, or are relative names correct relative to the target directory, then:
ln -s $(<file_list.txt) .
If you prefer to use 'cat', then:
ln -s $(cat file_list.txt) .
Clearly, I'm using the current directory as the target.
You don't say what you want to link to.
while loop without
cat. If there are spaces in the filenames this method will handle that.
while read -r line; do ln -s "$line" target; done < file_list.txt
You will have to supply the way to derive the name of the target since you didn't specify it in your question.
Consider something like (untested):
for targ in $(cat file_list); do tfile=$(basename $targ) ln -s $targ $tfile done
Note that the You can have base name strip any single given filename extension if you so desire (use the
basename will strip any file extention like naming (i.e. ".exe" or whatever). This can be fixed but it is a pain.
You can compress this into a single line like:
$ for targ in $(cat file_list); do tfile=$(basename $targ); ln -s $targ $tfile; done