Advertisement
metalx1000

Make Directory and move into it 'alias' for mkdir

Oct 29th, 2017
686
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.40 KB | None | 0 0
  1. #replace mkdir
  2. function mkdir() {command mkdir "$1"  &&  cd "$1";}
  3.  
  4. #check if folder exisits
  5. function mkdir() {
  6.   if [ ! -d "$1" ];
  7.   then
  8.     command mkdir "$1"  &&  cd "$1";
  9.   else
  10.     echo "$1 already exists.";
  11.    fi;
  12. }
  13.  
  14. #or in a one liner
  15. function mkdir() { [ ! -d "$1" ] && (command mkdir "$1"  &&  cd "$1")|| echo "$1 already exists."; }
  16.  
  17. #other options
  18. mcd() { mkdir "$1" && cd "$1"; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement