Or, find your files and extract the directory names in bulk: find –name level.dat –print | sed 's@/level.dat$@@'