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.
Related videos on Youtube
Author by
corsel
Updated on September 18, 2022Comments
-
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
andUS
directory in parent directory in one command?This is what I've tried:
mv (US|UK)/* .
-
tripleee almost 11 yearsNote that
{a,b}
is not POSIX. For a completely portable solution,mv UK/* US/* .
or in this very specific casemv U[KS]/* .
instead.