文件夹结构如下 - home/ABCD/test1/example1/sample1/textfile.txt
如果我像这样执行查找命令
find /home/ABCD/ -type f -print
我得到以下输出
/home/ABCD/test1/example1/sample1/textfile.txt
注意:我正在从 ABCD 文件夹执行查找命令,在结果中我想排除/home/ABCD/文件夹我只想要 /test1/example1/sample1/testfile .txt 作为结果
我怎样才能做到这一点?
最佳答案
因为你正在从 /home/ABCD/
执行查找,所以做这样的事情:
find * -type f -print
或者,如果您要在 test1
中查找文件,请执行以下操作:
find test1 -type f -print
还可以使用 -maxdepth N
限制查找中的递归
如果您只想查找名为 textfile.txt
的文件,请执行
find test1 -type f -name 'textfile.txt' -print
如果你想打印前导斜线
find . -type f -printf '/%p\n'
有关更多信息,请查看 here
注意:如果变量中有上述字符串,你可以像这样修剪它:
string="/home/ABCD/test1/example1/sample1/textfile.txt"
echo "${string#/home/ABCD}"
更多字符串操作示例 here
关于linux - 如何在 FIND 命令结果中排除几个文件夹级别 - unix,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15105539/