Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

It's often that a long path is mistyped or you get a log file entry that a path does not exist. Is there a command or shell function that navigates the path hierarchy until it finds a matching path?

The command line exchange could go like this:

$ ls /var/lib/my/supper/complicated/path
File or directory not found
$ fixpath /var/lib/my/supper/complicated/path
Found /var/lib/my

As a bonus feature, a similarity detection would be great:

$ fixpath /var/lib/my/supper/complicated/path
Found /var/lib/my
Did you mean /var/lib/my/super/complicated/path
share|improve this question
What shell you use ? tcsh has auto correction available, otherwise just loop through the path, it's not hard to make a script – warl0ck Jun 26 '12 at 13:41
 $ fixpath /home/user/docus/collection/unix/djakl/jfkdsl/dfjksld/fsdkl
Found /home/user/docus/collection/unix
 $ type fixpath
fixpath is a function
fixpath ()
    while [ $E -eq 1 ]; do
        cd "$DIR" 2> /dev/null && {
            echo Found "$DIR"
        } || {
    cd "$CURDIR"

Similarity autocorrection most modern shells can do itself. At least bash and zsh do.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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