如何将基于seq的curl+xargs命令改为读取links.txt文件?
Modified Command for Your Use Case
Here's the adjusted command that replaces seq 1 10 with cat links.txt while keeping your parallel download behavior intact:
cat links.txt | xargs -n1 -I{} -P2 -- curl -O -s 'https://example.com/dir/{}.ts'
Key Adjustments Explained:
cat links.txt: Pulls your custom string list from the file instead of generating a numeric sequence.-n1: Ensures xargs processes one string at a time. This is crucial if your strings are space-separated (like your exampleaada1 adk29 amn22), as it stops xargs from treating the entire line as a single argument.-I{}: Still serves as the placeholder for each string, inserting it into the curl URL just like the numeric values in your original command.-P2: Maintains the parallel download count at 2, matching your original setup.- The rest of the curl command stays the same, appending
.tsto each string to form the full target URL.
Bonus Tip for Edge Cases:
If your links.txt has strings with spaces/special characters, or you want to strictly split entries by newlines (not spaces), add the -d'\n' flag to force line-based splitting:
cat links.txt | xargs -d'\n' -I{} -P2 -- curl -O -s 'https://example.com/dir/{}.ts'
内容的提问来源于stack exchange,提问作者JaneFarrow
相关产品推荐
相关产品推荐

