bash脚本在一棵树上自动创建符号链接到子目录 [英] Bash script to automatically create symlinks to subdirectories in a tree
问题描述
好吧,这是我第三次尝试张贴这一点,也许我问错了问题!
Ok, this is my third try posting this, maybe I'm asking the wrong question!!
这是一个几年,因为我已经做任何shell编程,所以我有点生疏...
It's been a few years since I've done any shell programming so I'm a bit rusty...
我试图创建一个查找所有子目录一定命名的子目录下的一棵树,并创建符号链接到这些目录(听起来更加混乱比它是)一个简单的shell脚本。我使用Windows XP上的cygwin的。
I'm trying to create a simple shell script that finds all subdirectories under a certain named subdirectory in a tree and creates symbolic links to those directories (sounds more confusing than it is). I'm using cygwin on Windows XP.
此查找/ grep命令找到在文件系统中的目录就像我希望它:
This find/grep command finds the directories in the filesystem like I want it to:
find -mindepth 3 -maxdepth 3 -type d | grep "New Parts"
现在最困难的部分......我只想把这个列表,它管道进入LN并创建一些符号链接。目录的列表中有一些空白,所以我试图用xargs的清理了一点东西:
Now for the hard part... I just want to take that list, pipe it into ln and create some symlinks. The list of directories has some whitespace, so I was trying to use xargs to clean things up a bit:
find -mindepth 3 -maxdepth 3 -type d | grep "New Parts" | xargs -0 ln -s -t /cygdrive/c/Views
不幸的是,LN吐出来串联在一起的所有目录的长列表(由\\ n分隔),并吐出一个文件名过长的错误。
Unfortunately, ln spits out a long list of all the directories concatenated together (seperated by \n) and spits out a "File name too long" error.
想法?
推荐答案
我觉得你可以将所有find命令中做到这一点。 OTTOMH:
I think you can do this all within your find command. OTTOMH:
find -mindepth 3 -maxdepth 3 -type d -name "*New Parts*" -exec ln -s -t /cygdrive/c/Views {} \;
希望我记得,语法正确。
Hope I remembered that syntax right.
这篇关于bash脚本在一棵树上自动创建符号链接到子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!