AND运算符如何在FIND命令中工作

AND运算符如何在FIND命令中工作

本文介绍了AND运算符如何在FIND命令中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的最后一个问题扩展,所以我们分别分析一下。



AND-operater,Intersection

b $ b

我将举一个例子:

  $ find。 | awk -F/'{print $ 2}'

.zcompdump
.zshrc
.zshrc_copy
.zshrc_somequy
.bashrc
.emacs

$ find〜/ bin / FilesDvorak /.* -maxdepth 0 | awk -F/'{print $ 6}'

.bashrc
.emacs
.gdbinit
.git
.profile

当我将输出保存到单独的列表中时,我无法理解为什么这个命令没有使用常见的东西:

  find -f all_files -and -f right_files。 

我只想要:

  .bashrc 
.emacs


解决方案

你似乎想要两个find命令的交集。找不做设置操作。查找向下(或向上取决于你如何看待它)一组路径,并将表达式应用到它遇到的每个项目。它所需的默认操作是打印它找到的项目的路径,根据表达式求值为true。 (我相信find的一些旧版本需要你明确地添加一个-print表达式。)它不会整理结果。对于相交分析,您可以使用像 diff,sdiff,comm 这样的工具。

我假设您正在尝试查找具有相同名称的项目两个单独的目录,不在子目录中。



假设bash可以做类似于

  comm -12   

我相信在find命令中几乎总是多余的。例如

  find。型f! -type d 



  find。型的f  - 和! -type d 

另外-f标志是一个可以添加到遍历路径的选项。我不相信这是一个表达。请'找人'澄清。


My last question expanded, so let's analyse things separately.

AND-operater, Intersection?

I will give an example:

$ find . | awk -F"/" '{ print $2 }'

.zcompdump
.zshrc
.zshrc_copy
.zshrc_somequy
.bashrc
.emacs

$ find ~/bin/FilesDvorak/.* -maxdepth 0 | awk -F"/" '{ print $6 }'

.bashrc
.emacs
.gdbinit
.git
.profile

When I save the outputs to separate lists, I cannot understand why the command does not take the common things:

find -f all_files -and -f right_files .

I want only:

.bashrc
.emacs
解决方案

To slightly expand on Dave's answer:

You appear to want the intersection of two find commands. Find doesn't do set manipulation. Find traverses down (or up depending on how you look at it) a set of paths and applies an expression to each item it encounters. The default action it takes is to print the path of the items it finds that evaluate to true against the expressions. (I believe some old versions of find required you to explicitly add a -print expression.) It doesn't collate the results. For intersection analysis you can use tools like diff, sdiff, comm.

I assume you are trying to find the items with the same name in two separate directories, not in sub directories.

Assuming bash you can do something like

comm -12 <(find .  -maxdepth 1 | sort) <(cd ~/bin/FilesDvorak/; find . -maxdepth 1 | sort)

I believe the -and in find commands is almost always superfluous. Ex.

find . -type f ! -type d

Is the same as

find . -type f -and ! -type d

Also the -f flag is an option to add to the paths to traverse. I don't believe it is an expression. Please 'man find' for clarification.

这篇关于AND运算符如何在FIND命令中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 10:13