小编wza*_*zab的帖子

如何搜索包含一组单词的多行文本文件(例如,AAA & (BBB | CCC) & ~DD)?

我需要找到满足相对复杂条件的文件。例如,我想找到满足以下所有条件的所有文件:

  • 确实包含单词 AAAA
  • 确实包含单词 BBB 或 CCCCC(可能同时包含它们)
  • 不包含单词 DDD

这些词可能以任何顺序出现,也可能出现在不同的行中。

我有一个解决方案,它结合了findegrep,但不是很清晰。

find . \( -type f -and -exec egrep -q 'BBB|CCCCC' {} \; \
   -and -exec egrep -q AAAA {} \; \
   -and -not -exec egrep -q DDD {} \; \) -print
Run Code Online (Sandbox Code Playgroud)

有没有更好的方法来解决这个问题?

grep find search text

9
推荐指数
1
解决办法
447
查看次数

为什么 Linux 中符号链接目录中的“..”引用了“不正确”的目录?

请尝试运行以下脚本:

#!/bin/bash
mkdir a
mkdir a/asub
mkdir b
ln -sfr a/asub b/bsub
touch a/this_file_is_in_a
touch b/this_file_is_in_b
cd b/bsub
echo "I'm in directory: $(pwd)"
echo This is the contents of the upper directory:
ls ..
Run Code Online (Sandbox Code Playgroud)

你希望得到什么?可能是目录的内容b。然而,事实并非如此。我已经在目录中运行了它/tmp/bb

下面是结果:

wzab@WZabHP:/tmp/bb$ ./ls_tester.sh
I'm in directory: /tmp/bb/b/bsub
This is the contents of the upper directory:
asub  this_file_is_in_a
Run Code Online (Sandbox Code Playgroud)

因此,尽管pwd返回的正确路径是b子目录,但“..”指的是a子目录。是我对符号链接的理解不正确,还是Linux中的一个错误?

bash symlink

8
推荐指数
1
解决办法
348
查看次数

标签 统计

bash ×1

find ×1

grep ×1

search ×1

symlink ×1

text ×1