das*_*obu 60 linux bash symbolic-link
我想为某个目录中的ln -s所有文件(或一类文件,例如以 结尾.bar)创建符号链接 ( ) 。说我在 cwd 中,然后键入ls ../source/*.bar给我
foo.bar
baz.bar
Run Code Online (Sandbox Code Playgroud)
我如何将参数列表传递给ln -s它最终解析为
ln -s ../source/foo.bar
ln -s ../source/baz.bar
Run Code Online (Sandbox Code Playgroud)
当然,我知道我可以编写 bash 脚本,但是应该有一些更简单的内容,xargs因为它似乎是一项常见任务 - 至少对我而言。
mpy*_*mpy 102
ln 确实需要多个参数,但在这种情况下不要忘记提供目标目录。
所以,在你的例子中.是目标目录,所以它应该像
ln -s ../source/*.bar .
Run Code Online (Sandbox Code Playgroud)
来自man ln; 上面的命令使用第三种形式:
ln [OPTION]... [-T] TARGET LINK_NAME (1st form)
ln [OPTION]... TARGET (2nd form)
ln [OPTION]... TARGET... DIRECTORY (3rd form)
ln [OPTION]... -t DIRECTORY TARGET... (4th form)
Run Code Online (Sandbox Code Playgroud)
- 在第一个表单中,创建一个名为 LINK_NAME 的 TARGET 链接。
- 在第二种形式中,在当前目录中创建一个指向 TARGET 的链接。
- 在第 3 和第 4 种形式中,创建指向 DIRECTORY 中每个 TARGET 的链接。
您可以使用 globstar (bash/zsh set by:) 递归地尝试shopt -s globstar:
ls -vs ../**/*.bar .
Run Code Online (Sandbox Code Playgroud)
注意:-v为详细添加。
或者,如果列表太长,请使用find实用程序:
find .. -name \*.bar -exec ln -vs "{}" dest/ ';'
Run Code Online (Sandbox Code Playgroud)
这将在 中创建链接dest/,或将其更改.为当前文件夹。
用 find
certainDir="/path/to/dir"
find -name "*.bar" -exec ln -s {} "$certainDir" \;
Run Code Online (Sandbox Code Playgroud)
另外,请记住使用带有符号链接的完整路径(在可能的情况下)。
小智 5
cpwith-s选项可以创建软链接(或-l硬链接)。
从当前目录可以这样使用:
$ cp -s ../path/with/scripts/* .
Run Code Online (Sandbox Code Playgroud)
在你的情况下,它将是这样的:
$ cp -s ../source/*.bar .
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
80584 次 |
| 最近记录: |