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

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

问题描述

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

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-

我该怎么做有选择地在 LINUX 的另一个目录中创建指向特定文件的符号链接?

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

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.

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

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$/$$';做 echo ln -s $t ../folder2/$t; 完成

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.

推荐答案

更简单:

转到您要保存文件的文件夹并执行:

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 {} . ';'

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

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