我需要找到满足相对复杂条件的文件。例如,我想找到满足以下所有条件的所有文件:
这些词可能以任何顺序出现,也可能出现在不同的行中。
我有一个解决方案,它结合了find
和egrep
,但不是很清晰。
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)
有没有更好的方法来解决这个问题?
请尝试运行以下脚本:
#!/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中的一个错误?