Answer the question
In order to leave comments, you need to log in
How to loop through directories with spaces?
Hello, let's say I need to collect all the files with the .txt extension from anywhere on my computer.
I first installed the extremely handy locate
sudo apt-get install locate
and then the following script
#!/bin/bash
for book in $(locate .txt)
do
echo "cp ${book} /mnt/e/BOOK"
done
Answer the question
In order to leave comments, you need to log in
find . -regex ".*\.\(jpg\|jpeg\|gif\|png\|JPG\|JPEG\|GIF\|PNG\)" -print0 | xargs -0 cp --parents --target-directory ./tmp/backup
find . -regex ".*\.\(jpg\|jpeg\|gif\|png\|JPG\|JPEG\|GIF\|PNG\)" -print0 | xargs -0 cp ./tmp/backup
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question