Search code examples
wildcardzshfilepathrm

zsh delete subdirectory with wildcard in path


For a directory structure of:

└── bar
    ├── first
    │   └── tmp
    └── second
        └── tmp

I want to delete all tmp directories. However,

rm -rf 'bar/*/tmp/'                                

does not delete the directory

ls bar/*/                                          

still retrurns both tmp directories:

bar/first/:
tmp

bar/second/:
tmp

Solution

  • your problem here is the single quotes

    rm -rf 'bar/*/tmp/'          
    

    if you remove them you'll be fine.

    rm -rf bar/*/tmp
    

    The reason for this is that single quotes in (most, if not all) shell languages indicates that the contained string of characters is to be treated entirely as a string, which ignores the globbing you are trying to do.