Generally, I've to hit two commands:
$ mkdir dir_name
$ cd dir_name
to create directory and go to it.
Is there single command by using which we can achieve above?
To navigate up one directory level, use "cd .." To navigate to the previous directory (or back), use "cd -"
To remove a directory and all its contents, including any subdirectories and files, use the rm command with the recursive option, -r . Directories that are removed with the rmdir command cannot be recovered, nor can directories and their contents removed with the rm -r command.
The mkdir command in Linux/Unix allows users to create or make new directories. mkdir stands for “make directory.” With mkdir , you can also set permissions, create multiple directories (folders) at once, and much more.
Navigate directories. Open a window, double-click on a folder, and then double-click on a sub-folder. Use the Back button to backtrack. The cd (change directory) command moves you into a different directory.
You can add a function in your .bash_profile
:
function mkdircd () { mkdir -p "$@" && eval cd "\"\$$#\""; }
And use it like:
mkdircd test_folder
You can combine them both into a single command:
$ mkdir dir_name && cd dir_name
Note that the second half will run only if the first half succeeds. That is, if your directory already exists, it will not change directories.
If you want to change directory regardless, use a semicolon instead:
$ mkdir dir_name; cd dir_name
You can try like this:-
$ mkdir dir_name && cd dir_name
Yes you can do it like this
$ mkdir dir_name && cd dir_name
The shell will interpret &&
as a logical AND
. When using &&
the second command is executed only if the first one succeeds (returns a zero exit status).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With