There are several ways to search for files on GNU/Linux systems. The two main ways are locate
and find
:
locate
uses a database of files known in the whole system to find documents. It is very useful but requires to keep this database up-to-date (with updatedb
), which can take a long time;
find
searches for files in a given directory. It is usually slower than locate
(it has no persistent database) but is more fine-tuned.
So, if you need to find all files on your system that match your criteria, you can use locate
:
$ locate --regex "avi|flv" | grep '\.\(avi\|flv\)$'
whereas if you're searching in a specific directory and want to make sure to have no cache delay effect, you can use find
:
$ find /path/to/your/directory -regex '.*\.\(avi\|flv\)'
Now, to copy these files to a specific folder:
$ locate --regex "avi|flv" | grep '\.\(avi\|flv\)$' | xargs cp /path/to/specific/folder
or
$ find /path/to/your/directory -regex '.*\.\(avi\|flv\)' -exec cp {} /path/to/specific/folder \;