Green Chemistry is a vital and crucial instrument in achieving pollution control, and it plays an important role in helping society reach the Sustainable Development Goals (SDGs). NIR (near-infrared spectroscopy) has been utilized as an alternate technique for molecular identification, making the process faster and less expensive. Near-infrared diffuse reflectance spectroscopy and Machine Learning (ML) algorithms were utilized in this study to construct identification and classification models of bacteria such as Escherichia coli, Salmonella enteritidis, Enterococcus faecalis and Listeria monocytogenes. Furthermore, divide these bacteria into Gram-negative and Gram-positive groups. The green and quick approach was created by combining NIR spectroscopy with a diffuse reflectance accessory. Using infrared spectral data and ML techniques such as principal component analysis (PCA), hierarchical cluster analysis (HCA) and K-Nearest Neighbor (KNN), It was feasible to accomplish the identification and classification of four bacteria and classify these bacteria into two groups: Gram-positive and Gram-negative, with 100% accuracy. We may conclude that our study has a high potential for bacterial identification and classification, as well as being consistent with global policies of sustainable development and green analytical chemistry.