I have two arrays which has file numbers and I need to read those two arrays and delete those files. I need to read pri
array and delete files inside /primary
directory. Similarly I need to read snd
array and delete files inside /secondary
directory. These two directories have lot of other files and other subdirectories as well so I need to be very careful. I just need to delete files which are mentioned in those two arrays only.
All file names are like this:
abc_monthly_5_log.data
abc_monthly_25_log.data
abc_monthly_78_log.data
Below is my script and I can iterate them and delete those files one by one. Is there any other better way by which I can do that?
# it will lot of file numbers not just four or five files
pri=(0 5 7 100)
snd=(9 8 187 90 156)
# iterate pri array and delete files inside
for pm in "${pri[@]}"; do
rm /primary/abc_monthly_"$pm"_log.data
done
# iterate snd array and delete files inside
for sm in "${snd[@]}"; do
rm /secondary/abc_monthly_"$sm"_log.data
done