1

How do I find all folders containing a . in the foldename? I've tried the following, but it listed all folders, not what I wanted; find . -maxdepth 2 -type d -ipath "."

I seem to have a lot of folders named somethign like this; Brain.Dead.1990.1080p.BluRay.x264-HD4U[rarbg] and thats just plain ugly for me. I'd like to list them and then edit their names to something more readable. Any clues?

  • Is your question about finding them (title) or renaming them (body)? – Jeff Schaller Sep 28 '18 at 11:32
  • Just finding them for now – b0red Sep 28 '18 at 11:58
  • The biggest issue is that you're matching path not name - every path will match . when the starting point of your search is . – steeldriver Sep 28 '18 at 12:55
1

Another find whitout regex

find . -maxdepth 2 -type d -name '*.*' ! -name '.*'
2
find . -maxdepth 2 -type d -name '*.*'

Reports any directory with . in their name including ., ./user/.config, ./.foo.d and ./.foo/bar.baz.

find . -maxdepth 2 -type d -name '?*.*'

Would look for . in the part after the first character, so it would match on .foo.d but not .config or ..

find . -maxdepth 2 -type d -name '[!.]*.*'

Would omit hidden dirs (the ones whose name starts with .) but would still find non-hidden dirs inside hidden dirs (would find ./.foo/foo.bar).

find . -maxdepth 2 -name '.?*' -prune -o -type d -name '?*.*' -print

Would not traverse nor report hidden directory.

The only non-standard part in there is the -maxdepth 2 which you're already using. The standard equivalent would be:

find . -name '.?*' -prune -o \
   \( ! -path './*/*' -o -prune \) \
   -type d -name '?*.*' -print
1

You can use a regular expression, if your version of find supports that:

find . -maxdepth 2 -type d -regex '.*/[^./][^/]*\.[^/]*'

This matches any directory (with a maximum depth of two) whose name starts with any character other than “.” and contains a “.” in any other position.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.