Reputation: 23
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.
Upvotes: 1
Views: 1844
Reputation: 113994
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
Upvotes: 3