I have a folder called “week1”, and in that folder there are about ten other folders that all contain multiple files, including one called “submit.pdf”. I would like to be able to copy all of the “submit.pdf” files into one folder, ideally using Terminal to expedite the process. I’ve tried cp week1/*/submit.pdf week1/ as well as cp week1/*/*.pdf week1/, but it had only been ending up copying one file. I just realized that it has been writing over each file every time which is why I’m stuck with one…is there anyway I can prevent that from happening?
I have a folder called week1, and in that folder there are about ten
Share
You don’t indicate your OS, but if you’re using Gnu
cp, you can usecp week1/*/submit.pdf --backup=t week/to have it (arbitrarily) number files that already exist; but, that won’t give you any real way to identify which-is-which.You could, perhaps, do something like this:
… which will produce files named something like “week1-subdir-submit.pdf”
For what it’s worth, the
"${var/s/r}"notation means to take var, but before inserting its value, search for s (\/, meaning/, escaped because of the other special/in that expression), and replace it with r (-), to make the unique filenames.Edit: There’s actually one more
/in there, to make it match multiple times, making the syntax: