Linux: Find Tricks

I used this to find files whose names match a regular expression, that also aren’t empty. Then I cut the filenames by underscores and kept the 2nd field. I dumped that list into a file.

find -name "o*" -size +0 | cut -d "_" -f 2 > successful_model
ls results_copy > filenames
ls results_copy | cut -d "_" -f 2 | grep -nFx -f successful_models > file_nums
cat file_nums | cut -d ":" -f 1 > file_indices
sed -nf <(sed 's/.*/&p/' file_indices) filenames > files_to_keep

Leave a Reply

Your email address will not be published. Required fields are marked *