Back
To recursively move files, combine find with mv.
find src/dir/ -name '*.txt' -exec mv {} target/dir/ \;
To rename your files when you move them it's trickier. One way is to have the loop that passes the file name through tr / _, which converts slashes into your underscores.
find src/dir/ -name '*.txt' | while read file; do mv "$file" "target/dir/$(tr / _ <<< "$file")"done
find src/dir/ -name '*.txt' | while read file; do
mv "$file" "target/dir/$(tr / _ <<< "$file")"
done
To know about Linux join the Linux training
31k questions
32.8k answers
501 comments
693 users