How nice it would be to have a command to make a directory any time you wish. You could then use this command to create directories and thereby organize your files in multiple directories in a way similar to organizing files in a filing cabinet. The mkdir command allows you to do just that - make a directory. This is an incredibly simple command. You specify the name of the directory to create. In the following example, we'll look at the contents of a directory with the ls command, use mkdir to make the directory named default.permissions , and then perform another ls to see the new directory: $ ls -l total 2 drwxr-xr-x 2 denise users 1024 Oct 31 11:27 krsort.dir.old $ mkdir default.permissions $ ls -l total 4 drwxr-xr-x 2 denise users 1024 Oct 31 11:27 krsort.dir.old drwxr-xr-x 2 denise users 24 Oct 31 11:32 default.permissions $ The new directory has been produced with default permissions for the user denise . group and other have both read and execute permissions for this directory. What if you wanted to create a directory with specific permissions on it instead of default permissions? You could use the -m option to mkdir and specify the mode or permissions you wanted. To give all users read permission on the krsort.dir.new directory, you issue the following: $ mkdir -m "a=r" read.permissions $ ls -l total 6 drwxr-xr-x 2 denise users 1024 Oct 31 11:27 krsort.dir.old drwxr-xr-x 2 denise users 24 Oct 31 11:32 default.permissions dr--r--r-- 2 denise users 24 Oct 31 11:33 read.permissions $ Remember the symbolic versus numeric mode of permissions? This mkdir command shows the symbolic mode, which although I do not like as much as the numeric mode that should be used because the numeric mode is becoming obsolete. You don't have to stop at creating a directory with only one level of depth. With the -p option, you can create a new directory with any number of subdirectories in it. Intermediate directories are created with the -p option. Let's now create a directory named level1 , with the directory level2 beneath it, and the directory level3 below level2 in the following example. The ls command with the -R option recursively lists the directories below level1 : $ mkdir -p level1/level2/level3 $ ls -R level1 level2 level1/level2: level3 level1/level2/level3: $ After creating the directory level1 and issuing the ls command, we can see that level2 is indeed beneath level1 , and level3 is beneath level2 . mkdir - Create specified directories.
|