MKDIR command in Linux
MKDIR command in Linux
Linux/Unix mkdir or “make directory” command is used for creating directories/folders on the filesystem. This is a simple and frequently used Linux command.
Command 1 :- To Create a new Directory
Use mkdir followed by new directory name to create directory in current location.
$mkdir test
Command 2 :- To create multiple Directories
Creating multiple directories in current directory in single command. Below command will create three directories test1, test2, test3 in current directory.
$mkdir test1 test2 test3
Command 3 :- To create directory at specific location
Create directory to other location without changing current directory. Type full path of directory like below.
$ mkdir /var/www/folder1/public
Command 4 :- Create Directory with Intermediate Directory
The above command will failed with mesage “mkdir: cannot create directory `/var/www/folder1/public’: No such file or directory”, if any of intermediate directory does not exist. In that situation use -p option to tell mkdir to create intermediate directories if not exists.
$ mkdir -p /var/www/folder1/public
Command 5 :-Create A Directory with Specific Permission
During creation of directories, you can set specific permissions using -m option. This is similiar to use chmod command.
$ mkdir -m 644 test1
$ mkdir -m a=rwx test1
$ mkdir -m u=rw,g=r,o=r test1
Command 6 :- Create Multiple Directories at Specific Location
This is very lesser known option for creating multiple directories on different location with single command. This will create directories named one, two, three in test1 directory.
$ mkdir -p test1/{one|two|three}
0 comments
Please leave your comments...... Thanks