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

齐天大*_*天大圣 3 bash shell

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

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

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

file1 file2 file3 file4....
Run Code Online (Sandbox Code Playgroud)

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

file1
file2
file3
...
Run Code Online (Sandbox Code Playgroud)

这似乎很简单,但我一直在寻找,没有解决方案.先感谢您.

Joh*_*ica 6

摆脱echo$(...).

find . -maxdepth 1 -type f -newer "$1" | sed 's,\.\/,,g'
Run Code Online (Sandbox Code Playgroud)

如果你有GNU查找,你可以sed用一个-printf动作替换:

find . -maxdepth 1 -type f -newer "$1" -printf '%P\n'
Run Code Online (Sandbox Code Playgroud)