The Linux mkdir command is used to create a directory of the specified name, requiring the user who created the directory to have write permissions in the current directory, and the specified directory name cannot be a directory that is already in the current directory.
1. Command format:
mkdir [ options ] directory ...
2. Command function:
Passmkdircommand can be implemented at the specified location to create aDirName (the specified file name)the named folder or directory. The user who creates the folder or directory must have write permissions to the parent folder of the folder that is created. Also, the folders that are created(Catalogue)cannot be associated with its parent directory(that is, the parent folder)the name of the file in the same directory cannot have the same name(Case Sensitive).
3. Command parameters:
-M,--mode= mode, set permissions < mode > ( similar to chmod) instead of rwxrwxrwx minus umask
-P,--parents can be a path name. At this point, if some directories in the path do not already exist , and with this option , the system will automatically set up those directories that do not yet exist , that is, multiple directories can be established at one time ;
-V,--verbose displays information each time a new directory is created
--help Display this help message and exit
--version output version information and exit
4. Command instance:
Example 1: Create an empty directory
Command:
mkdir test1
Output:
[[Email protected] soft]# CD Test[[email protected] test]# mkdir Test1[[email protected] test]# ll total 4drwxr-xr-x 2 root ro OT 4096 10-25 17:42 test1[[email protected] test]#
Example 2: Creating multiple directories recursively
Command:
Mkdir-p test2/test22
Output:
[[email protected] test]# mkdir-p Test2/test22[[email protected] test]# ll total 8drwxr-xr-x 2 root root 4096 10-25 17:42 tes T1drwxr-xr-x 3 root root 4096 10-25 17:44 test2[[email protected] test]# CD Test2/[[email protected] test2]# ll Total 4drwxr-x R-x 2 root root 4096 10-25 17:44 Test22[[email protected] test2]#
Example 3: create a directory with permissions of 777
Command:
Mkdir-m 777 Test3
Output:
[[email protected] test]# mkdir-m 777 Test3[[email protected] test]# ll total 12drwxr-xr-x 2 root root 4096 10-25 17:42 test1 Drwxr-xr-x 3 root root 4096 10-25 17:44 test2drwxrwxrwx 2 root root 4096 10-25 17:46 Test3[[email protected] test]#
Description
TEST3 permissions are rwxrwxrwx
Example 4: Creating a new directory displays information
Command:
Mkdir-v test4
Output:
[Email protected] test]# mkdir-v test4mkdir: Created directory "Test4" [[email protected] test]# MKDIR-VP test5/test5-1mkdir: Directory Created "Test5" mkdir: Created directory "Test5/test5-1" [[email protected] test]#
Example five: a command to create a directory structure for a project
Reference: http://www.ibm.com/developerworks/cn/aix/library/au-badunixhabits.html
Command:
MKDIR-VP Scf/{lib/,bin/,doc/{info,product},logs/{info,product},service/deploy/{info,product}}
Output:
[Email protected] test]# MKDIR-VP Scf/{lib/,bin/,doc/{info,product},logs/{info,product},service/deploy/{info, Product}}mkdir: Created directory "SCF" mkdir: Created directory "Scf/lib" mkdir: Directory Created "Scf/bin" mkdir: Directory Created "Scf/doc" mkdir: Created directory "Scf/doc/info" mkdir: The directory "Scf/doc/product" mkdir: Created directory "Scf/logs" mkdir: Created directory "Scf/logs/info" mkdir: Created directory "Scf/logs/product" mkdir: Directory created "Scf/service" mkdir: Directory Created "Scf/service/deploy" mkdir: Directory Created "Scf/service/deploy/info" mkdir: Directory Created "scf/service/ Deploy/product "[[email protected] test]# tree scf/scf/|--bin|--doc| | --info| '--product|--lib|--logs| | --info| '--product '--service '--Deploy |--info '--product directories, 0 Files[[email protected] test]#
Linux Common Commands-mkdir