Combined make/remove and change directory


/ Published in: Bash
Save to your folder(s)

Has saved me no end of typing over the years.


Copy this code and paste it in your HTML
  1. # mkdir and cd into new Dir (accepts -p option of mkdir or creation of multiple dirs):
  2. function mkcd() { mkdir "$@" && cd "${!#}"; }
  3.  
  4. # usage:
  5. mkcd newdir
  6. # or:
  7. mkcd -p path/to/newdir
  8.  
  9. # cd .. and remove directory:
  10. function rmcd() { cd .. && rmdir "${OLDPWD##*/}"; }
  11.  
  12. # usage, from empty directory you want to remove:
  13. rmcd

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.