4

I run in Debian 8.1, GNU bash, version 4.3.30(1)-release (x86_64-pc-linux-gnu) and Lenovo G50-30 with 500 GB SSD and 8 GB flash memory:

shopt -s extglob
cp -r !(Backups.backupdb/) /home/masi/Documents/

but it will copy also everything from the directory Backups.backupdb/, confirmed at the end of copying.

Messages during the copying process

After 2h copying

cp: cannot stat ‘Backups.backupdb/masi\’s MacBook Air/2015-06-25-233115/Macintosh HD/System/Library/Image Capture/Automatic Tasks/MakePDF.app/Contents/Resources/ko.lproj/3x5로 자르기.mkpdf’: No such file or directory
cp: cannot stat ‘Backups.backupdb/masi\’s MacBook Air/2015-06-25-233115/Macintosh HD/System/Library/Image Capture/Automatic Tasks/MakePDF.app/Contents/Resources/ko.lproj/3x5에 맞추기.mkpdf’: No such file or directory
...
cp: cannot stat ‘Camera Uploads/2015-06-29 11.51.36.jpg’: Invalid argument
cp: cannot stat ‘Camera Uploads/2015-06-29 11.51.53.jpg’: Invalid argument
cp: cannot stat ‘Camera Uploads/Icon\r’: Invalid argument
cp: cannot stat ‘Cancer’: Invalid argument
cp: cannot stat ‘cardio bad/atria-en-ventrikels.swf’: Invalid argument
cp: cannot stat ‘cardio bad/extreme_90_180.swf’: Invalid argument
cp: cannot stat ‘Cardio databases tools’: Invalid argument
cp: cannot stat ‘Cardiology’: Invalid argument
...

where I keep unexpected browsing through the backup folder. The challenge here is that the Backups.backupdb is several TBs and seeing that it goes browsing it does not feel good.

No symbolic links

I run

ls -lR /media/masi/eb807ed8-7f45-35f8-a345-9da6692b228a/ |grep Backup

getting

ls: cannot access /media/masi/eb807ed8-7f45-35f8-a345-9da6692b228a/Cancer: Invalid argument
ls: cannot access /media/masi/eb807ed8-7f45-35f8-a345-9da6692b228a/Cardio databases tools: Invalid argument
ls: cannot access /media/masi/eb807ed8-7f45-35f8-a345-9da6692b228a/Cardiology: Invalid argument
drwxr-xr-x 1 root root          7 Jul  8 20:25 Backups.backupdb
ls: cannot open directory /media/masi/eb807ed8-7f45-35f8-a345-9da6692b228a/animations/Embryology/e17_files: Permission denied
^C

so the directory is not a symlink. Why is extglob except condition broken here by browsing the folder?

Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697
  • Time Machine may have run and purged the old backup while `cp` was running. – Barmar Jul 23 '15 at 20:02
  • 1
    I'm surprised this does anything at all. On my system, `!(dir/)` does not match anything (unlike `!(dir)`) – that other guy Jul 23 '15 at 20:03
  • @Masi: is `Backups.backupdb` a symlink? I am asking because `/` and the end of path to symlink matters. Still, as said above, `!(dir/)` does not work on my `Bash 4.2.37`. Your `Bash` is however very new, they might have added new bugs ;) – Arkadiusz Drabczyk Jul 23 '15 at 20:06
  • @Masi: ok, can you compile and run an older version of `Bash` and check it still behaves like this? It would be worth reading `Bash` changelog. – Arkadiusz Drabczyk Jul 23 '15 at 20:16
  • @Masi From your update, the `ls -lR` is returning errors even though no extglob is used. Since the problem exists even without extglob, it might help if you updated the question's title. – John1024 Jul 23 '15 at 20:28
  • @thatotherguy Curious. On my system, `!(dir/)` matches all files in the current directory _including_ directory `dir` while `!(dir)` matches all files in the current directory except directory `dir`. – John1024 Jul 23 '15 at 20:44
  • @Masi What is the issue you're seeing that you didn't expect? Is it that `Backups.backupdb` is included in the copy when you expected it not to, or is it that you get all these `Invalid argument` errors in various directories? – that other guy Jul 23 '15 at 20:57
  • @thatotherguy I keep unexpected the browsing through `Backups.backupdb` when I said except it. `Invalid argument` errors are the task of another thread, most probably because of filesystem difference between OSX and Linux. – Léo Léopold Hertz 준영 Jul 24 '15 at 04:59

1 Answers1

2

Try removing the backslash (I am adding echo for test purposes):

shopt -s extglob
echo cp -r !(Backups.backupdb) /home/masi/Documents/

It works in my environment (GNU bash, version 4.3.30, OS X)

Mario Zannone
  • 2,843
  • 12
  • 18