Print the directory where the 'find' linux command finds a match

前端 未结 2 1303
醉梦人生
醉梦人生 2021-01-27 04:06

I have a bunch of directories; some of them contain a \'.todo\' file.

/storage/BCC9F9D00663A8043F8D73369E920632/.todo
/storage/BAE9BBF30CCEF5210534E875FC80D37E/.         


        
2条回答
  •  执笔经年
    2021-01-27 04:38

    The quick and easy answer for stripping off a file name and showing only the directory it’s in is dirname:

    #!/bin/bash
    STORAGEFOLDER='/storage'
    find "$STORAGEFOLDER" -name .todo  -exec dirname {} \;
    

提交回复
热议问题