There are instances where you want to quickly locate and move specific file types from point A to Point B.
Example:
Move all PHP files from /home/$user/php-files/ to /home/$user/php-mv-files
Easiest way to do this is to use the Find command in terminal.
$ find ./ -name "*.php" ./php-files/file3.php ./php-files/file2.php ./php-files/file1.php
This lists all the PHP files in the /php-files directory.
To move the files, you run the following command:
$ find ./php-files/ -name "*.php" -exec mv {} ./php-mv-files/ \;
This will move all files from ./php-files to ./php-vmv-files. Running the original Find command will get you the following:
$ find ./ -name "*.php" ./php-mv-files/file3.php ./php-mv-files/file2.php ./php-mv-files/file1.php
In this instance, -exec mv {} says, run the MV command on the files selected from the original find, that’s what the {} implies. You then escape, and close the command using \;. This final piece is critical to stopping the command.
Sharing is caring!