Unix “find” command usage

后端 未结 2 1745
梦如初夏
梦如初夏 2021-01-22 00:24

This is for a bash installation script. The script foo.sh takes \"DIRECTORY\" as an argument. Say, there is a dir <$HOME>/TEST/TEST_1A/TEST_2A/TEST_3 and anot

2条回答
  •  再見小時候
    2021-01-22 01:21

    Wouldn't this work as intended?

    find $HOME -type d -name $1 -exec echo {} ';'  -exec rm -rf {} ';'
    

    It will complain about deleting of processed directory, but toher than some stderr output it's ok...

    You can ofc change "-name" for "-regexp" as you suggested, but if you want something more complex, you can create special script to call from "-exec"

    EDIT: I probably understood you wrong first time (but won't delete anything, it may help somebody) - you want to delete only one of TEST_3 directories (how do you choose which one? first found by find? - it seems quite strange), still as I suggested in previous paragraph, you can provide skript to -exec which will take care of all decision making)

提交回复
热议问题