There is also another way to do it which I think will suit your purpose perfectly. You can combine
find with a
while loop and not even need to use either of
xargs at all. If, for example you wanted to copy your
mp3s from your download folder to your music folder, you would use the following script, which I have used many times.
You can modify it how you want by changing the directories that
find searches and places the resulting files in; if no directory is stated,
find will search the entire home folder. You can also change
mv or other commands. It is pretty fast, as I have just tested it with 3945
.jpg files! Copy it into a text editor, save it and then make it executable by running
chmod +x myscript.
# a script to recursively find and copy files to a desired location
find ~/Downloads -type f -iname '*.mp3' -print0 |
while IFS= read -r -d '' f;
do cp -- "$f" ~/Music ;
At this noted Bash wiki it is shown how useful it is to combine the
while loop and
read commands to process the output of the
find command; and the way I have done it makes sure that the script will not break if it comes across file names with spaces or other unexpected or special characters.
For more general information on the
find command, enter in the terminal
man find or see the Ubuntu manpages online. For a great introduction to the use of find, see this article as well.