[LINUX] NO MORE “cd: foo: No such file or directory”

Never say “cd: foo: No such file or directory” again

I'll do it once.

Trying to enter a directory that does not exist


$ cd foo
bash: cd: foo: No such file or directory

And fuck while yelling fuck.

fuck To do


$ fuck
mkdir -p foo && cd foo [enter/↑/↓/ctrl+c]

When I saw the fuck given here, it turned out to be "this is it".

"This is it" is which

Should I do something like this? (The name of the directory you are trying to enter is ** foo **)

フローチャート

All you have to do is write this.

Trial writing


function cd() {
    if [ -d $1 ]; then
        command cd $1
    elif [ ! -e $1 ]; then
        mkdir -p $1 && command cd $1
    else
echo no more
    fi
}

But how about the error display ** no longer **?

Think a little more

Of course I get angry when I try to cd to a file.

$ touch hoge
$ cd hoge
bash: cd: hoge: Not a directory

Isn't this all right?

フローチャート

For the time being, the favorite


function cd() {
    if [ ! -e $1 ]; then
        mkdir -p $1 && command cd $1
    else
        command cd $1
    fi
}

in conclusion

Please let me know if there is a smarter way.

Recommended Posts

NO MORE “cd: foo: No such file or directory”
No such file or directory:'chromedriver': Resolve'chromedriver'
pip install --upgrade pip will result in No such file or directory
-bash: ./ {file name} .sh: /usr/bin/bash: bad interpreter: No such file or directory
Import Error: libffi.so.6: cannot open shared object file: No such file or directory
Cannot import cv2 (libgtk-x11-2.0.so.0: cannot open shared object file: No such file or directory)
Addressed "Python .h: No such file or directory" when installing uWSGI with Python 3.8
What to do when [Errno 2] No such file or directory appears in Python
What to do if ENOENT: no such file or directory appears during npm install
When I try to run the pip command after updating pip, I get "No such file or directory"
[Note] How to deal with unicode error and No such file or directory (output table to excel file with pandas)
When bus = smbus.SMBus (1) gets IOError: [Errno 2] No such file or directory when trying to start the GrovePi starter kit
EC2 / Amazon Linux2: What to do if you get an "unable to execute'gcc': No such file or directory" error with pip install