简体   繁体   中英

How to use find + regex to match files and return only unique directories containing said files?

This find command matches the files I'm searching for:

find / -type f -regextype sed -regex ".*/g\.[0-9]\{4\}.*"

How do I move to the next step of listing just the unique directory names that contain those files? (I don't need to display all the files.)

将输出传递给删除文件名的sed命令,然后使用uniq删除重复项:

find / -type f -regextype sed -regex ".*/g\.[0-9]\{4\}.*" | sed 's|/[^/]*$||' | uniq

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM