以下是我当前使用的代码:
xargs -n 1 curl -s -o /dev/null -w "%{http_code} - %{url_effective}\n" < 'file.txt'
这适用于卷曲
file.txt
中的所有URL,并获取状态代码和被卷曲的URL。但是,我需要对每个文件递归地执行此操作。我尝试过一些事情,像这样,但没有一件成功:
xargs -n 1 curl -s -o /dev/null -w "%{http_code} - %{url_effective}\n" < *
在多个目录中大约有3000个文件。有没有办法递归地这样做?
最佳答案
假设文件列表的名称在当前工作目录(包括子目录)下有如下规则:file.txt、file1.txt、file2.txt。
您可以使用cat **/file*.txt
命令合并这些文件中的所有链接,然后将其与xargs
合并:
cat **/file*.txt | xargs -n 1 curl -s -o /dev/null -w "%{http_code} - %{url_effective}\n"
祝你好运!