如何对 find 的输出执行“for each”?

San*_*ing 5 linux bash grep find

我想找到所有mp41920x1080 的文件。

如果我做

find . -type f -name \*.mp4 -exec ffprobe '{}' \; 2>&1
Run Code Online (Sandbox Code Playgroud)

它将找到所有mp4文件并显示视频信息。例如,输出是否包含(在其他行中)

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from './5432223.mp4':
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080, 1744 kb/s, 29.97 fps, 29.97 tbr, 60k tbn, 59.94 tbc
Run Code Online (Sandbox Code Playgroud)

我目前的想法是

find . -type f -name \*.mp4 -print0|xargs -0 -n1 echo
for f in $(find . -type f -name \*.mp4); do ffprobe $f 2>&1 | grep 1920x1080;done
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚如何if grep -q 1920x1080在第一个和第二个空格中合并和 文件名中的输出弄乱了输出。

如果输出匹配,如何仅输出带路径的文件名1920x1080

Wil*_*ell 3

您可能想执行一个 shell。就像是:

find . -type f -name \*.mp4 -exec sh -c 'ffprobe "$0" 2>&1 |
    grep -q 1920x1080 && echo "$0"' {} \;
Run Code Online (Sandbox Code Playgroud)