You need a function, not an alias. Try:
newfolder() { mkdir -p "$1" && cd "$1"; }
Example:
$ pwd
/tmp
$ newfolder dir1/dir2
$ pwd
/tmp/dir1/dir2
Notes:
The
-p
option tomkdir
tells it to create missing parent directories if needed. In the above example,dir1
did not exist butmkdir -p dir1/dir2
created bothdir1
anddir2
.Because we use the shell operator
&&
, thecd
command will only be performed if themkdir
command succeeded.Aliases are useful in very simple cases where a fixed string can be substituted for a word. Aliases do not process arguments.
Because we are using a shell function in place of an alias, we can reference the arguments, such as, in this case,
$1
, as neededaccording to our needs.