The mkdir command in linux USES elaboration

  • 2020-05-13 04:02:35
  • OfStack

The linux mkdir command is used to create a directory with the specified name, requiring that the user creating the directory have write permissions in the current directory and that the specified directory name cannot be an existing directory in the current directory.

1. Command format:
mkdir [options] directory...

2. Command functions:
The mkdir command enables you to create a folder or directory named DirName(the specified file name) at the specified location. The user to create a folder or directory must have write permissions to the parent folder of the folder that was created. Also, the folder (directory) created cannot have the same name as the file name in its parent directory (parent folder), that is, the same directory cannot have the same name (case sensitive).

3. Command parameters:
-m, --mode= mode, set permissions < model > (similar to chmod), not rwxrwxrwx minus umask
-p, --parents can be a path name. At this point, if some directories in the path do not exist, plus this option, the system will automatically set up those directories that do not exist, that is, one can set up more than one directory;
-v, --verbose displays information every time a new directory is created
--help displays this help and exits
--version outputs version information and exits

4. Command example:
Example 1: create an empty directory
Command:
mkdir test1
Output:


[root@localhost soft]# cd test
[root@localhost test]# mkdir test1
[root@localhost test]# ll
A total of 4drwxr-xr-x 2 root root 4096 10-25 17:42 test1
[root@localhost test]#

Example 2: recursively create multiple directories
Command:
mkdir -p test2/test22
Output:


[root@localhost test]# mkdir -p test2/test22
[root@localhost test]# ll
A total of 8drwxr-xr-x 2 root root 4096 10-25 17:42 test1
drwxr-xr-x 3 root root 4096 10-25 17:44 test2
[root@localhost test]# cd test2/
[root@localhost test2]# ll
A total of 4drwxr-xr-x 2 root root 4096 10-25 17:44 test22
[root@localhost test2]#

Example 3: create a directory with permissions 777
Command:
mkdir -m 777 test3
Output:


[root@localhost test]# mkdir -m 777 test3
[root@localhost test]# ll
A total of 12drwxr-xr-x 2 root root 4096 10-25 17:42 test1
drwxr-xr-x 3 root root 4096 10-25 17:44 test2
drwxrwxrwx 2 root root 4096 10-25 17:46 test3
[root@localhost test]#

Description:
The permission of test3 is rwxrwxrwx

Example 4: creating a new directory displays information
Command:
mkdir -v test4
Output:


[root@localhost test]# mkdir -v test4
mkdir: Created directory " test4 "
[root@localhost test]# mkdir -vp test5/test5-1
mkdir: Created directory " test5 "
mkdir: Created directory " test5/test5-1 "
[root@localhost test]#

Instance 5:1 creates the directory structure of the 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:


[root@localhost 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: Created directory " scf/bin "
mkdir: Created directory " scf/doc "
mkdir: Created directory " scf/doc/info "
mkdir: Created directory " scf/doc/product "
mkdir: Created directory " scf/logs "
mkdir: Created directory " scf/logs/info "
mkdir: Created directory " scf/logs/product "
mkdir: Created directory " scf/service "
mkdir: Created directory " scf/service/deploy "
mkdir: Created directory " scf/service/deploy/info "
mkdir: Created directory " scf/service/deploy/product "
[root@localhost test]# tree scf/
scf/
|-- bin
|-- doc
|   |-- info
|   `-- product
|-- lib
|-- logs
|   |-- info
|   `-- product
`-- service
      `-- deploy
         |-- info
          `-- product
12 directories, 0 files
[root@localhost test]#

That's all you need to know about the mkdir command


Related articles: