bashfzf

How to use fzf to search for directories only?


Here is a use case: I use fzf to search for a list of directories, which then used with the cd command:

cd $(fzf)

However, the fzf command only displays files, not directories. Is there a way to instruct fzf to select only directories?


Solution

  • Per my comment, you can generate a list of directories using find:

    cd $(find . -type d -print | fzf)
    

    You can adjust the find command to limit the depth of directories, or to only match directories with specific names, etc.

    Generally, you're expected to use fzf as a filter, taking input from some external command.