Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux bash使用xargs将fdirectory文件输出到文本文件并添加新行_Linux_Bash_Wget_Xargs - Fatal编程技术网

Linux bash使用xargs将fdirectory文件输出到文本文件并添加新行

Linux bash使用xargs将fdirectory文件输出到文本文件并添加新行,linux,bash,wget,xargs,Linux,Bash,Wget,Xargs,我想生成一个包含文件夹中存在的文件列表的文本文件 ls | xargs echo > text.txt 我想在每个文件前加上IP地址,这样我就可以按照本文运行并行wget: 因此,我的text.txt文件内容将包含以下行: 123.123.123.123/file1 123.123.123.123/file2 123.123.123.123/file3 如何将字符串附加为ls提要xargs?(并在末尾添加换行符。) 谢谢只需printf和globbing即可获取文件名: printf

我想生成一个包含文件夹中存在的文件列表的文本文件

ls | xargs echo > text.txt
我想在每个文件前加上IP地址,这样我就可以按照本文运行并行wget:

因此,我的text.txt文件内容将包含以下行:

123.123.123.123/file1
123.123.123.123/file2
123.123.123.123/file3
如何将字符串附加为ls提要xargs?(并在末尾添加换行符。)
谢谢

只需
printf
和globbing即可获取文件名:

printf '123.123.123.123/%s\n' * >file.txt
或更长的方法,在globbing的帮助下,利用
进行构建:

for f in *; do echo "123.123.123.123/$f"; done >file.txt

假设不存在带换行符的文件名。

是否可以在一行中完成?