1

I have a file that contains a set of paths

~/somedir/pathfile.foo
--------------------------
/home/user/dir/file1.bar
/home/user/dir/file2.bar
/home/user/dir/file3.bar
/home/user/dir/file4.bar
...

I would to write a bash script (or command) that would create symbolic links to all these .bar files within the current directory (.). For clarification, if pathfile.foo contains N paths I would like to have N symlinks.

1 Answers1

3
while read line; do ln -s "$line" "${line##*/}" ; done <pathfile.foo

After the above has been executed, the following symlinks will appear in the current directory:

$ ls -l *bar
lrwxrwxrwx 1 me me 24 Oct  8 23:09 file1.bar -> /home/user/dir/file1.bar
lrwxrwxrwx 1 me me 24 Oct  8 23:09 file2.bar -> /home/user/dir/file2.bar
lrwxrwxrwx 1 me me 24 Oct  8 23:09 file3.bar -> /home/user/dir/file3.bar
lrwxrwxrwx 1 me me 24 Oct  8 23:09 file4.bar -> /home/user/dir/file4.bar
John1024
  • 109,961
  • 14
  • 137
  • 171