I have a nested directory structure that looks like this:
top_dir
└── nested_1
└── nested_2
├── a_file.txt
├── b_file.txt
├── directory
├── other_directory
├── y_file.txt
└── z_file.txt
I want to delete the files inside nested_2
that don't start with A-M, and leave the directories alone. So I want to delete y_file.txt
and z_file.txt
.
I need to run the find + regex command in top_dir
.
I've tried multiple versions of this:
find nested_1/nested_2 -maxdepth 1 -mindepth 1 -type f -regex "nested_1\/nested_2\/.*^[a-m]" #-delete
It doesn't seem to matter what regex I use - the only one that produces any result at all is
find nested_1/nested_2 -maxdepth 1 -mindepth 1 -type f -regex ".*" #-delete
which just gives me a list of all the files in the directory with the leading nested directories (as expected).
Testing it out on regexr hasn't helped either.
What am I missing here?