Bash 查找,排除父级?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11071442/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bash find, exclude parent?
提问by Steven Penny
I have a folder with some dotfiles I would like to make symlinks for. I cannot see an easy way to do this.
我有一个文件夹,里面有一些我想为其制作符号链接的点文件。我看不到一个简单的方法来做到这一点。
ls -a ~/dotfileswill include the dotfiles, but also .and ..
ls -a ~/dotfiles将包括点文件,但也.和..
find ~/dotfiles -maxdepth 1will include the dotfiles, but also ~/dotfiles
find ~/dotfiles -maxdepth 1将包括点文件,但也 ~/dotfiles
回答by Steven Penny
Based off MvanGeest'scomment this appears to work.
根据MvanGeest 的评论,这似乎有效。
find ~/dotfiles -maxdepth 1 -mindepth 1
This looks to do the job as well
这看起来也能完成这项工作
ls -A ~/dotfiles
回答by siggi
Looks like you're trying to find dot files, ie. Files that start with a "." and have a second character that is not a ".". This should do the job:
看起来您正在尝试查找点文件,即。以“.”开头的文件 并有第二个不是“.”的字符。这应该可以完成这项工作:
find . -name '.[^.]*'
to link all found files to /path/to/dir:
将所有找到的文件链接到 /path/to/dir:
find $PWD -name '.[^.]*' -exec ln -s '{}' /path/to/dir \;
Note that "$PWD" produces an absolute path, as symlinks to relative paths will most likely point into nirvana...
请注意,“$PWD”会生成一个绝对路径,因为相对路径的符号链接很可能会指向必杀技......

