|Previous||Table of Contents||Next|
The external mkdir command makes a new directory. You can pass multiple arguments to mkdir . Each argument is used by mkdir as the name of a new directory to create.
Following is the general format of the mkdir command.
mkdir [ -m mode ] [ -p ] directory_list
The following options and their arguments may be used to control how mkdir functions.
|-m mode||Mode to use for new directories. This allows you to specify what mode all of the new directories will have when they are created. The default is 777 minus your umask number or the system s default umask number.|
|-p||Parent directory creator. If you specify a pathname to create a new directory and the parent directories do not exist, mkdir will create them as needed.|
|The BSD version does not support any options.|
The following arguments may be passed to the mkdir command.
|directory_list||The list of names to be created as directories. The directory names may be pathnames or single filenames.|
Each new directory created will have two entries placed in it by mkdir . The first entry is . (dot) which represents the directory itself (current directory). The second entry, .. (dot dot), represents the parent directory of the new directory.
You must have write permission for the directory where you are creating the new directories. If you do not have write permission, you will not be allowed to create the new directories.
When you create a new directory the system builds a new inode (information node) for the directory. This allows access to the data stored in the directory file and informs the system that the file is a directory type file. The directory file is a preformatted file, containing the filename and its related inode number.
The permissions given to a new directory are set to your current mode. When you initially begin to log in, your mode is set to 777 (-rwxrwxrwx). If the system s profile or your .profile performs an umask , your modes may be different. Use the umask command to check your current modes. Type umask and press Return to display your current umask value. Refer to the module on chmod for an explanation of the modes.
The user-ID and group -ID of the new directories are the same as the real user -ID and group-ID of the creating process. If you create a directory, then it will be owned by you and have your group-ID.
DIAGNOSTICS AND BUGS
If an error occurs while creating a directory, mkdir writes a diagnostic message to the standard error and returns a nonzero exit status upon exiting.
Refer to the rm , rmdir , ksh , and umask command described in modules 114, 115, 71, and 147, respectively.
You use the mkdir command to create new directories, thus building a hierarchy of directories to maintain your files in an orderly fashion.
It may be useful for you to consider setting a standard naming convention or structure for your directory hierarchy. Try to plan ahead when creating directories. The most common mistake made by inexperienced UNIX users is the lack of subdirectories. It is much easier to locate a file if you have your files categorized in subdirectories.
The rule of thumb for the number of files in a directory is 50 to 100. These numbers are based on performance, not on limits. The more files in a directory the longer it takes to retrieve the information from disk. Therefore, it is advisable to only have 50 files per directory. If you have hundreds of files to store, you probably want to create subdirectories with the same basic name and an incremental extension. This allows you to place 50 to 100 files in each of the directories, while maintaining a consistent name for the directories.
The ls -l and ls -F command can be used to show if an entry in a directory is a subdirectory.
In this activity you use the mkdir command to create a new subdirectory. Begin at the shell prompt.
cj> ls -Ral misc total 6 drwxrr 3 mylogin ts 512 Feb 4 08:33 . drwxrr 13 mylogin ts 512 Jan 24 06:43 .. drwxrr 2 mylogin ts 24 Feb 4 08:33 misc misc/misc: total 4 drwxrr 2 mylogin ts 24 Feb 4 08:33 . drwxrr 3 mylogin ts 512 Feb 4 08:33 ..
|Previous||Table of Contents||Next|