bash find: get directory of found file

这篇具有很好参考价值的文章主要介绍了bash find: get directory of found file。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

With GNU find:

find . -name foo.mp4 -printf '%h\n'

With other finds, 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):

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模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Linux报错:-bash: 路径xx: No such file or directory解决方法

    事情起因:当我在用OpenFOAM的时候,提示内存不足,然后我将OpenFOAM移动到了我新挂载的文件上,于是出现了图中的错误   于是在询问了朋友和前辈之后,发现是配置文件的问题,于是我进入到配置文件中,将我新的路径复制了进去 第一步:输入命令   vim ~/.bashrc  进入bashr

    2024年02月17日
    浏览(40)
  • 解决 /bin/bash^M: bad interpreter: No such file or directory

    linux 系统中知行*.sh 文件报/bin/bash^M: bad interpreter: No such file or directory 原因: .sh文件是在windows系统编写的,在linux执行就有问题 转化下格式执行如下命令 # dos2unix app.sh  结果bash: dos2unix: command not found 需要安装下dos2unix 接着执行:# yum install -y dos2unix 接着再执行:# dos2unix app.

    2024年02月08日
    浏览(35)
  • Linux中执行bash脚本报错/bin/bash^M: bad interpreter: No such file or directory

    运行bash脚本会出现两个文件, 1037.err 和 1037.out 。 1037.err的文件内容如下: /data/home/user12/.lsbatch/1694577957.1037: /data/home/user12/.lsbatch/1694577957.1037.shell: /bin/sh^M: bad interpreter: No such file or directory 第一步 执行命令行:cat -A xxx.sh 第二步 使用下述命令直接替换结尾符为unix格式 命令行

    2024年02月07日
    浏览(31)
  • chroot: failed to run command ‘/bin/bash’: No such file or directory

    在busybox的环境下,执行 报错如下: 根据报错应该rootfs文件系统中缺少/bin/bash,进入查看确实默认是sh,换成 依然报错 通过查阅资料发现,/bin/sh链接/bin/busybox,busybox为动态执行文件,直接进入缺少动态链接库,如下: 需要拷贝相应的动态到rootfs文件系统,如下: 然后再执

    2024年01月24日
    浏览(36)
  • 运行命令出现错误 /bin/bash^M: bad interpreter: No such file or directory

    在系统上运行一个 Linux 的命令的时候出现下面的错误信息: -bash: ./build.sh: /bin/bash^M: bad interpreter: No such file or directory 这个是在 Windows 作为 WSL 的时候出的错误。 出现问题的原因在于脚本在 Windows 中使用的回车换行和 Linux 使用的回车换行不一样。 如果你的代码是在 Windows 下被

    2024年02月11日
    浏览(34)
  • 如何解决go.mod file not found in current directory or any parent directory?

    环境变量配置: 假如安装路径: /usr/local/go 那么这样配置环境变量: vi ~/.bash_profile 然后保存,执行source ~/.bash_profile 报错go.mod file not found in current directory or any parent directory? 解决: go env -w GO111MODULE=auto OK,问题解决

    2024年02月12日
    浏览(42)
  • mac安装docker报错bash: /usr/local/bin/docker: No such file or directory

    按照网上查的命令用brew安装(安装命令如下:) #brew install --cask  docker 安装结果也显示安装成功: 然后按照各种贴子的说明去检查docker版本时(docker --version)会报错  bash: /usr/local/bin/docker: No such file or directory ,这一下让我很懵,不是都是说brew安装后就可以了吗,我怎么报错了,

    2024年02月02日
    浏览(34)
  • [Go 报错] go: go.mod file not found in current directory or any parent directory

    Build Error: go build -o c:Users13283Desktopgodemo__debug_bin3410376605.exe -gcflags all=-N -l . go: go.mod file not found in current directory or any parent directory; see \\\'go help modules\\\' (exit status 1) go 的环境配置问题。与 golang 的包管理有关 如果你是 Windows 系统,快捷键 “Win+R”,输入cmd,打开终端。输入: 解

    2024年02月09日
    浏览(36)
  • linux 通过docker进行build编译nginx时现./configure报-bash: ./configure: No such file or directory

    我们前端程序是通过nginx代理的,我们前后端都是通过docker来管理的 今天要将前端包和 nginx实例话的,在我的dockerFile文件里面有一个命令,就是将一个nginx.tar.gz包复制到/usr/local目录下然后解压,这个nginx.tar.gz里面包含了这个。/configure文件,结果在执行一个编译命令的时候报

    2024年02月07日
    浏览(27)
  • python 外星人入侵FileNotFoundError: No file ‘player.gif‘ found in working directory

    将相对路径改为绝对路径即可 例如 D:/AlienInvasion/ship/player.gif/

    2024年02月13日
    浏览(40)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包