bash 脚本:如何在不同的行中显示输出

bash script: how to display output in different line

我正在尝试用一行代码解决一个问题

echo $(find . -maxdepth 1 -type f -newer   | sed 's,\.\/,,g')

这将打印出当前文件夹中比输入文件更新的所有文件。但它打印成一行:

file1 file2 file3 file4....

如何在一行中显示每个文件名,如:

file1
file2
file3
...

这似乎很简单,但我一直在寻找并没有解决方案。 提前谢谢你。

删除 echo$(...)

find . -maxdepth 1 -type f -newer "" | sed 's,\.\/,,g'

如果您有 GNU find,您可以将 sed 替换为 -printf 操作:

find . -maxdepth 1 -type f -newer "" -printf '%P\n'

通过管道传输到 tr:

... | tr " " "\n"