Linux bash 使用 xargs 将 fdirectory 文件输出到文本文件并添加新行
Linux bash output fdirectory files to a text file with xargs and add new line
我想生成一个包含文件夹中文件列表的文本文件
ls | xargs echo > text.txt
我想为每个文件添加 IP 地址,以便我可以 运行 并行 wget post : Parallel wget in Bash
所以我的 text.txt 文件内容将包含这些行:
123.123.123.123/file1
123.123.123.123/file2
123.123.123.123/file3
如何在 ls 提供 xargs 时附加字符串? (并在末尾添加换行符。)
谢谢
只需 printf
并通配以获取文件名:
printf '123.123.123.123/%s\n' * >file.txt
或更长的方法,在 globbing 的帮助下利用 for
构造:
for f in *; do echo "123.123.123.123/$f"; done >file.txt
假设不存在带换行符的文件名。
我想生成一个包含文件夹中文件列表的文本文件
ls | xargs echo > text.txt
我想为每个文件添加 IP 地址,以便我可以 运行 并行 wget post : Parallel wget in Bash
所以我的 text.txt 文件内容将包含这些行:
123.123.123.123/file1
123.123.123.123/file2
123.123.123.123/file3
如何在 ls 提供 xargs 时附加字符串? (并在末尾添加换行符。) 谢谢
只需 printf
并通配以获取文件名:
printf '123.123.123.123/%s\n' * >file.txt
或更长的方法,在 globbing 的帮助下利用 for
构造:
for f in *; do echo "123.123.123.123/$f"; done >file.txt
假设不存在带换行符的文件名。