从查找创建符号链接 [英] Create symbolic link from find

查看:75
本文介绍了从查找创建符号链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据find命令的结果创建符号链接(软链接).我正在使用sed删除文件名之前的./.我这样做是为了将文件名粘贴到将保存链接的路径的末尾.我正在使用Ubuntu Server 8.04进行此工作.

我从这篇文章中学到了,这是解决我的问题的一种方法,但不是很完全

我如何选择性地创建指向LINUX另一个目录中特定文件的符号链接?

虽然生成的文件名不起作用,所以我开始尝试学习awk,然后决定使用sed.

我正在使用单行循环来完成此操作.问题在于循环的结构是分隔文件名,为文件名中的每个单词创建一个链接.文件很多,我希望每个链接都自动执行该过程,并采用链接到该文件的文件名.

我对基本的bash命令很满意,但是我远不是命令行专家.我从ls和awk开始,然后移动到find和sed.我的sed语法可能会更好,但是我已经在两天内学会了这一点,现在有点卡住了.

中找到t的

查找-type f -name"* txt *" |sed -e's/.//'-e's $/$$';做回声ln -s $ t ../folder2/$ t; 完成

任何帮助或提示将不胜感激.谢谢.

解决方案

更简单:

转到您要在其中存放文件的文件夹,然后执行以下操作:

 查找/path/with/files -type f -name"* txt *" -exec ln -s {}.';' 

I'm trying to create a symbolic link (soft link) from the results of a find command. I'm using sed to remove the ./ that precedes the file name. I'm doing this so I can paste the file name to the end of the path where the link will be saved. I'm working on this with Ubuntu Server 8.04.

I learned from this post, which is kind of the solution to my problem but not quite-

How do I selectively create symbolic links to specific files in another directory in LINUX?

The resulting file name didn't work, though, so I started trying to learn awk and then decided on sed.

I'm using a one-line loop to accomplish this. The problem is that the structure of the loop is separating the filename, creating a link for each word in the filename. There are quite a few files and I would like to automate the process with each link taking the filename of the file it's linked to.

I'm comfortable with basic bash commands but I'm far from being a command line expert. I started this with ls and awk and moved to find and sed. My sed syntax could probably be better but I've learned this in two days and I'm kind of stuck now.

for t in find -type f -name "*txt*" | sed -e 's/.//' -e 's$/$$'; do echo ln -s $t ../folder2/$t; done

Any help or tips would be greatly appreciated. Thanks.

解决方案

Easier:

Go to the folder where you want to have the files in and do:

find /path/with/files -type f -name "*txt*" -exec ln -s {} . ';'

这篇关于从查找创建符号链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆