I have a folder with a lot of files. I want to copy all files which begin with of these names (separated by space):
abc abd aer ab-x ate
to another folder. How can I do that?
If you'd rather not use brace expansion, you can use a for loop (here POSIX/Bourne style syntax):
If you have a very large amount of files, this might be slow due to the invocation of
A note about brace expansion vs globbing.
Brace expansion is not globbing (though the distinction is not as clear in csh/tcsh where it originated as in other shells). It is performed before globbing.
So, when you do:
It is first expanded to:
That means that the shell will have to expand two globs, that is get the full list of files twice and see which match the pattern twice.
That also means that if you have
That's different from the:
(above, the prefixes are treated as globs). That is join the elements of the arrays with
If the list is big, what you may find is that executing
Simply you can do
A solution to your extended problem can be