Linux file management mkdir

mkdir create directory

Original meaning of order

  • make directories

Command format

  • mkdir [options] [directory name]

Command function

  • Lists the creation directory.

Common parameters

  • -M -- mode = mode, set permission < mode > (similar to chmod), instead of rwxrwxrwx minus umask

    -P -- parents can be a path name. At this time, if some directories in the path do not exist, plus this option, the system will automatically create directories that do not exist, that is, multiple directories can be created at a time;

    -V -- verbose displays information every time a new directory is created

    -- help display this help message and exit

    -- version output version information and exit

Common examples

Example 1

Create directory parent/child

[~] mkdir parent/child
mkdir: cannot create directory 'parent/child': No such file or directory
[~] mkdir -p parent/child
[~] tree parent/
parent/
└── child

1 directory, 0 files

Example 2

Create a directory with permission 777

[root@localhost test]# mkdir -m 777 test3
[root@localhost 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 test2
drwxrwxrwx 2 root root 4096 10-25 17:46 test3
[root@localhost test]#

Example 3

Create new directory display information

[root@localhost test]# mkdir -v test4
mkdir: Directory created“ test4"
[root@localhost test]# mkdir -vp test5/test5-1
mkdir: Directory created“ test5"
mkdir: Directory created“ test5/test5-1"
[root@localhost test]#

Example 4

A command to create the directory structure of a project

[root@localhost test]# mkdir -vp scf/{lib/,bin/,doc/{info,product},logs/{info,product},service/deploy/{info,product}}

mkdir: Directory created“ scf"
mkdir: Directory created“ scf/lib"
mkdir: Directory created“ scf/bin"
mkdir: Directory created“ scf/doc"
mkdir: Directory created“ scf/doc/info"
mkdir: Directory created“ scf/doc/product"
mkdir: Directory created“ scf/logs"
mkdir: Directory created“ scf/logs/info"
mkdir: Directory created“ 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"

Posted on Tue, 05 May 2020 02:45:50 -0700 by frontlines