Cleaning up a directory
Continuing your work as a data scientist in a large organization, you were told today that a colleague has left for their dream job (lucky them!). Unfortunately, when their logins were terminated, all their files were dumped into a single folder.
The good news is that most of their useful code has been backed up. However, all their python files using the Random Forest algorithm are buried in the file dump.
The task has fallen to you to sift through the hundreds of files to determine if they are both Python files and contain a Random Forest model. This sounds like a perfect opportunity to use your Bash skills, rather than checking every single file manually.
Write a script that loops through each file in the robs_files/
directory to see if it is a Python file (ends in .py
) AND contains RandomForestClassifier
. If so, move it into the to_keep/
directory.
This exercise is part of the course
Introduction to Bash Scripting
Hands-on interactive exercise
Turn theory into action with one of our interactive exercises
