Using regex in ls and mv

10,643

Try this from the parent directory:

mv {UK,US}/* .

The {A,B,...} syntax is similar to the (A|B|...) syntax used in regular expressions.

If you have dotfiles (hidden files) in those directories that aren't showing up in your listing, run

mv {UK,US}/{*,.*} .

The * glob will expand to all files and directories except for those starting with dots. The .* glob will expand to all of the dotfiles.

Share:
10,643

Related videos on Youtube

corsel
Author by

corsel

Updated on September 18, 2022

Comments

  • corsel
    corsel over 1 year

    I have a directory structure like this

    ├── UK
    │   ├── BuyBand_go_UK.png
    │   ├── BuyBand_go_UK.svg
    │   ├── BuyBand_K.png
    │   ├── BuyBand_K.svg
    │   ├── BuyBago_UK.png
    │   ├── BuyBago_UK.svg
    │   ├── BuyBand_ch_Logo_UK.png
    │   └── BuyBand_ch_Logo_UK.svg
    └── US
        ├── BuyBand_go_US.png
        ├── BuyBand_go_US.svg
        ├── BuyBand_S.png
        ├── BuyBand_S.svg
        ├── BuyBago_UK.png
        ├── BuyBago_UK.svg
        ├── BuyBand_ch_Logo_US.png
        └── BuyBand_ch_Logo_US.svg
    

    How can I move all files in both UK and US directory in parent directory in one command?

    This is what I've tried:

       mv (US|UK)/* .
    
  • tripleee
    tripleee almost 11 years
    Note that {a,b} is not POSIX. For a completely portable solution, mv UK/* US/* . or in this very specific case mv U[KS]/* . instead.