How could I move all .txt files from a folder and all included folders into a target directory .
And preferably rename them to the folder they where included in, although thats not that important. I’m not exactly familiar with bash.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To recursively move files, combine
findwithmv.Or if on a UNIX system without GNU’s version of
find, such as macOS, use:To rename the files when you move them it’s trickier. One way is to have a loop that uses
"${var//from/to}"to replace all occurrences offromwithtoin$var.This is ugly because
fromis a slash, which needs to be escaped as\/.See also:
IFS= read -r line