Sometime last week I had this task job of removing multiple files from a list of multiple directories, without knowing if the files would be present in a said directory.
That task job led to a small bash script, and some further exploration of other commands (another post about those coming soon) that would help with the job.
Here’s the shell script (slightly edited for general use):
#!/bin/bash
for FOLDER in $(cat listodirectories.txt) ; do
cd /path/to/$FOLDER
rm -v $(</path/to/list-of-files-to-remove-from-each-dir.txt)
done
exit 0;
The above script can also be modified to copy or move a list of files into or to a list of directories.
Here’s the same bash script edited for copying a list of files into multiple directories (there’s a better option though), and it can be modified to move a list of files from various locations, into a single folder or directory.
As mentioned above, I stumbled upon a much faster, and easier way to do all of this, using some other commands (not find). By ‘all of this’ I mean move, copy, and remove multiple files from a single or multiple locations. I’ll be posting another script, and some info soon.