user@machine:~$ mkdir -p /dir/needed/to/cd/to/immediately
user@machine:~$ cd /dir/needed/to/cd/to/immediately
user@machine:~$ pwd
/home/user/dir/needed/to/cd/to/immediately
Quick functional solution: Open ~/.bashrc (or .bash_profile) and add the following line:
function mkdircd () { mkdir -p "$@" && eval cd "\"\$$#\""; }
NOTE: You can name this function whatever you like, mkdircd just makes sense to me...
Source ~/.bashrc and now let's do this the easy way:
user@machine:~$ mkdircd dir/needed/to/go/to/immediately
user@machine:~/dir/needed/to/go/to/immediately$ pwd
/home/user/dir/needed/to/go/to/immediately
~Fin
No comments:
Post a Comment