With GNU
find:
find . -name foo.mp4 -printf '%h\n'
With other find
s, provided directory names don't contain newline characters:
find . -name foo.mp4 |
LC_ALL=C sed 's|/[^/]*$||'
Or:
find . -name foo.mp4 -exec dirname {} \;
though that means forking a process and running one dirname
command per file.
If you need to run a command on that path
, you can do (standard syntax):文章来源:https://www.toymoban.com/news/detail-846848.html
find . -name "featured.mp4" -exec sh -c '
for file do
dir=${file%/*}
ffmpeg -i "$file" -c:v libvpx -b:v 1M -c:a libvorbis "$dir" featured.webm
done' sh {} +
Though in this case, you may be able to use -execdir
(a BSD extension also available in GNU find
), which chdir()
s to the file's directory:文章来源地址https://www.toymoban.com/news/detail-846848.html
find . -name "featured.mp4" -execdir \
ffmpeg -i {} -c:v libvpx -b:v 1M -c:a libvorbis . featured.webm \;
到了这里,关于bash find: get directory of found file的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!