linux - Move all folders except one -


i have 2 directories dir1 , dir2. need move content of folder dir1 dir2 except 1 folder dir1/src.

i tried

mv !(src) dir1/* dir2/ 

but dosn't work, still displays error

bash: !: event not found 

maybe looking this?

the answer question there states trying to achievable using extglob bash shell option. can turn on executing shopt -s extglob or adding command ~/.bashrc , relogin. afterwards can use function.


to use example of moving dir1 except dir1/src dir2, should work:

mv -vt dir2/ dir1/!(src) 

example output:

$ mkdir -pv dir1/{a,b,c,src} dir2 mkdir: created directory 'dir1' mkdir: created directory 'dir1/a' mkdir: created directory 'dir1/b' mkdir: created directory 'dir1/c' mkdir: created directory 'dir1/src' mkdir: created directory 'dir2' $ ls -l dir1/ total 16 drwxrwxr-x 2 dw dw 4096 apr  7 13:30 drwxrwxr-x 2 dw dw 4096 apr  7 13:30 b drwxrwxr-x 2 dw dw 4096 apr  7 13:30 c drwxrwxr-x 2 dw dw 4096 apr  7 13:30 src $ ls -l dir2/ total 0 $ shopt -s extglob $ mv -vt dir2/ dir1/!(src) 'dir1/a' -> 'dir2/a' 'dir1/b' -> 'dir2/b' 'dir1/c' -> 'dir2/c' $ ls -l dir1/ total 4 drwxrwxr-x 2 dw dw 4096 apr  7 13:30 src $ ls -l dir2/ total 12 drwxrwxr-x 2 dw dw 4096 apr  7 13:30 drwxrwxr-x 2 dw dw 4096 apr  7 13:30 b drwxrwxr-x 2 dw dw 4096 apr  7 13:30 c 

more information extglob can found here.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -