A handy fzf function for jumping into nested directories

August 8, 2026 5 answers
Asked by ~waterTable
I got tired of typing long, deeply nested paths with cd, so I put together this small Bash function: ```bash fcd() { local dir dir=$(find "${1:-.}" -type d 2>/dev/null | fzf) && cd "$dir" || return } ``` After adding it to .bashrc and starting a new shell, running fcd lists directories beneath the current location. You can type to filter the list, press Enter, and jump straight into the selected directory. Passing a path such as fcd ~/projects lets you search from a specific starting point instead. It works well for me, but I'm wondering whether there's a faster or cleaner approach for very large directory trees.

Answers

rubber-stamp-ink
Using fd instead of find can make this noticeably quicker and gives you simpler syntax: ```bash fd . -t d "${1:-.}" ``` You can pipe that into fzf in the same way.

~waterTable: Good suggestionโ€”Iโ€™ll try fd for larger directory trees.

Reply to this answer
waffle.317
One subtle Bash issue is declaring and assigning the variable in the same command, such as `local dir="$(...)"`. The exit status can become the status of local rather than the command substitution, which may cause the function to continue even when fzf is cancelled. Keeping the declaration separate, as in the original example, avoids that problem and lets the `&& cd` check work properly.
Reply to this answer
starlight.filter
For frequently visited locations, zoxide or another directory jumper can be faster than scanning the filesystem every time. These tools rank paths based on your history, so the directory you want is often near the top. An fzf picker is still useful when searching an unfamiliar subtree.

granite_counter: That trade-off makes sense: history-based jumpers are faster for common paths, while a filesystem scan is better when exploring somewhere new.

Reply to this answer
reverse-fold
With fzfโ€™s shell completion enabled, you may not need a function at all. In Bash, a pattern such as `cd **` can open an interactive directory search, after which you can type to narrow the results. The exact setup depends on where the fzf completion and key-binding scripts are installed.
Reply to this answer
theatre.prompt.book
Thereโ€™s already a similar directory picker included with fzf, usually available through the Alt-C key binding. It may be worth enabling the shell integration before maintaining a separate function.

~waterTable: Thanks, Iโ€™ll check out the built-in version.

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions