user3646028
user3646028

Reputation: 23

bash script to create symlinks from a file contain a list of paths

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

Answers (1)

John1024
John1024

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

Related Questions