'How to exclude this / current / dot folder from find "type d"
find . -type d
can be used to find all directories below some start point. But it returns the current directory (.) too, which may be undesired. How can it be excluded?
Solution 1:[1]
Not only the recursion depth of find can be controlled by the -maxdepth parameter, the depth can also be limited from “top” using the corresponding -mindepth parameter. So what one actually needs is:
find . -mindepth 1 -type d
Solution 2:[2]
I use find ./* <...> when I don't mind ignoring first-level dotfiles (the * glob doesn't match these by default in bash - see the 'dotglob' option in the shopt builtin: https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html).
eclipse tmp # find . . ./screen ./screen/.testfile2 ./.X11-unix ./.ICE-unix ./tmux-0 ./tmux-0/default
eclipse tmp # find ./* ./screen ./screen/.testfile2 ./tmux-0 ./tmux-0/default
Solution 3:[3]
Well, a simple workaround as well (the solution was not working for me on windows git bash)
find * -type d
It might not be very performant, but gets the job done, and it's what we need sometimes.
[Edit] : As @AlexanderMills commented it will not show up hidden directories in the root location (eg ./.hidden), but it will show hidden subdirectories (eg. ./folder/.hiddenSub). [Tested with git bash on windows]
Solution 4:[4]
Pipe it to sed. Don't forget the -r that extend regular expression.
find . -type d | sed -r '/^\.$/d'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Matthias Ronge |
| Solution 2 | Milos Ivanovic |
| Solution 3 | |
| Solution 4 | Clement |
