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

时光总嘲笑我的痴心妄想 提交于 2019-12-11 04:15:09

问题


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:


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


来源:https://stackoverflow.com/questions/26270797/bash-script-to-create-symlinks-from-a-file-contain-a-list-of-paths

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!