gpt4 book ai didi

linux - 列出 linux 中所有包含 *.pdf 文件的目录并将结果通过管道传输到文件

转载 作者:太空狗 更新时间:2023-10-29 11:44:39 25 4
gpt4 key购买 nike

在 Linux 中有没有一种方法可以使用 grep 之类的东西列出所有包含 *.pdf 文件的目录并将所有结果传输到一个文件?

我想这样做的原因是我有一个基于 html 的大型静态网站,我想列出所有包含 pdf 的 url。

站点结构是具有许多级别和子级别的典型树结构,因为这是一个小的缩减示例:

public_html/
content/
help/
advice/
marketing/
campaign1/
pdfs/
campaign2/
pdfs/

shop/
templates/
nav/
guarantees/
includes/
etc...

我想搜索此结构并列出此处包含的所有 pdf,并将它们通过管道传输到文件。示例输出如下所示,每个新结果都在新行中:

public_html/content/marketing/campaign1/pdfs/example1.pdf
public_html/content/marketing/campaign1/pfds/example2.pdf
public_html/shop/templates/nav/guarantees/guarantee.pdf

我只想要 public_html 文件夹中的 pdf。我不想搜索硬盘驱动器上的 home、bin、tmp、var 等...文件夹。

最佳答案

你可以通过 find 命令做到这一点,

find /public_html -mindepth 1 -iname "*.pdf" -type f > output-file

解释:

/public_html     # Directory on which the find operation is going to takesplace.

-mindepth 1 # If mindepth is set to 1, it will search inside subdirectories also.

-iname "*.pdf" # Name must end with .pdf.

-type f # Only files.

关于linux - 列出 linux 中所有包含 *.pdf 文件的目录并将结果通过管道传输到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24290746/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com