What is the difference between following 2 commands?
cp -rp /dir1/*.* /dir2/ cp -rp /dir1/* /dir2/ *.* only matches filenames with a dot in the middle or at the end. For example:
abc.jpg def. * matches the filenames above, plus the names which don't have a dot at all. for example:
data *.* used to be the correct way to match all files on MS-DOS back in the day of 8+3 filenames. In MS-DOS, the dot is mandatory (albeit implicit on files which do not have an extension). *.* matches foo. but not .foo. That asymmetry is terrible. . (current directory) and .. (parent directory) entries which always exist in any directory (even empty dirs). Ritchie and Thompson later considered it to be a useful feature to hide (by default) all the .*rc config files and added an explicit -a option to ls to display all these (leading-dot) "hidden" entries. So this is not very surprising knowing Unix history. A leading dot in Unix has been special since "forever". Suppose your have following files in /dir1:
foobar foo.bar fo.ba foo1.bar2 foobar1 foobar2 cp -rp /dir1/*.* /dir2/ This command will copy only the following files:
foo.bar fo.ba foo1.bar2 cp -rp /dir1/* /dir2/ This will copy all the files in /dir1
The condition applies to the subdirectories in /dir1 as well..
.like.bashrc) are not copied with any of those commands. To copy those files you should explicitly indicate that with.*so, to copy all files (including hidden ones) the command would becp -rp /dir1/.* /dir1/* /dir2/*.*is the MS-DOS/Windows way of doing it, while*is the UNIX/Linux way. In Unix suffix (file-ending, the part after the.- like.txtor.jpg) is optional... In MS-DOS the.(dot) and suffix was required, so to match all files, one used*.*- while to match all text-files, one would use*.txt.FILENAMEor evenFILE.*.*in DOS still matches files namedFILENAMEorFILE, because the name is 'really'FILENAME.orFILE.(with an empty extension). In Unix, the name is 'really'FILENAMEorFILE, so*.*won't match.*would only matchFILE, and notFILE.TXT.