我有一些用生成的uuid1字符串命名的图像.例如81397018-b84a-11e0-9d2a-001b77dc0bed.jpg.我想使用"查找"命令查找所有这些图像:

find . -regex "[a-f0-9\-]\{36\}\.jpg".

但它不起作用.正则表达式有问题吗?有人能帮我吗?

推荐答案

find . -regextype sed -regex ".*/[a-f0-9\-]\{36\}\.jpg"

请注意,您需要在开头指定.*/,因为find匹配整个路径.

例子:

susam@nifty:~/so$ find . -name "*.jpg"
./foo-111.jpg
./test/81397018-b84a-11e0-9d2a-001b77dc0bed.jpg
./81397018-b84a-11e0-9d2a-001b77dc0bed.jpg
susam@nifty:~/so$ 
susam@nifty:~/so$ find . -regextype sed -regex ".*/[a-f0-9\-]\{36\}\.jpg"
./test/81397018-b84a-11e0-9d2a-001b77dc0bed.jpg
./81397018-b84a-11e0-9d2a-001b77dc0bed.jpg

我的find版本:

$ find --version
find (GNU findutils) 4.4.2
Copyright (C) 2007 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Eric B. Decker, James Youngman, and Kevin Dalley.
Built using GNU gnulib version e5573b1bad88bfabcda181b9e0125fb0c52b7d3b
Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION FTS() CBO(level=0) 
susam@nifty:~/so$ 
susam@nifty:~/so$ find . -regextype foo -regex ".*/[a-f0-9\-]\{36\}\.jpg"
find: Unknown regular expression type `foo'; valid types are `findutils-default', `awk', `egrep', `ed', `emacs', `gnu-awk', `grep', `posix-awk', `posix-basic', `posix-egrep', `posix-extended', `posix-minimal-basic', `sed'.

Linux相关问答推荐

将UTC字符串日期时间转换为毫秒UTC时间戳

将参数#0更改为shell脚本不工作

Linux x86_64上PIE ELF可执行文件的.Text段的基本虚拟地址

如何将参数传递给Bash函数

通过 ssh 在远程计算机上按索引访问数组元素

提交SLURM作业(job)时出现nohup问题

如何从linux调度程序中屏蔽一个cpu(防止它调度线程到那个cpu上)?

sig_atomic_t 实际上是如何工作的?

ftell 在文件描述符上?

并行制作:将 -j8 设置为默认选项

Linux 和 I/O 完成端口?

低功耗蓝牙:在 linux 中监听通知/指示

如何在没有 IDE 的情况下构建和部署三星 SmartTV 应用程序(例如:在 Linux 上)

从Linux中的行尾删除空格

我可以在 Ubuntu 上使用 Homebrew 吗?

如何从任意 pthread_t 获取线程 ID?

用于数据库备份的 Linux shell 脚本

判断环境变量是否已经设置

Linux:用户名不在 sudoers 文件中

更改 /etc/profile 后,我需要做什么来重置我的 shell?