In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Linux how to use mkdir command to create a directory, many novices are not very clear about this, in order to help you solve this problem, the following small series will explain in detail for everyone, there are people who need this can learn, I hope you can gain something.
1. Command Format:
mkdir [options] directory...
2. Command function:
The mkdir command allows you to create a folder or directory named DirName at a specified location. The user who wants to create a folder or directory must have write permission to the parent folder of the folder being created. Moreover, the folder (directory) created cannot have the same name as the file name in its parent directory (i.e. parent folder), that is, there cannot be a file name with the same name under the same directory (case-sensitive).
3. Command Parameters:
-m, --mode= mode, set permissions (like chmod) instead of rwxrwxrwx minus umask
-p, --parents can be a path name. At this point if some directory path does not exist, plus this option, the system will automatically establish those do not exist directory, that is, a number of directories can be established;
-v, --verbose Displays information every time a new directory is created
--help Display this help message and exit
--version Output version information and exit
4. Command example:
Example 1: Creating an empty directory
Command:
mkdir test1
Output:
The code is as follows:
[root@localhost soft]# cd test
[root@localhost test]# mkdir test1
[root@localhost test]# ll
Total 4drwxr-xr-x 2 root root 4096 10-25 17:42 test1
[root@localhost test]#
Example 2: Recursive creation of multiple directories
Command:
mkdir -p test2/test22
Output:
The code is as follows:
[root@localhost test]# mkdir -p test2/test22
[root@localhost test]# ll
Total 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
Total 4drwxr-xr-x 2 root root 4096 10-25 17:44 test22
[root@localhost test2]#
Example 3: Creating a directory with permissions 777
Command:
mkdir -m 777 test3
Output:
The code is as follows:
[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]#
Description:
Test3 has permission rwxrwxrwx
Example 4: Creating a new directory displays information
Command:
mkdir -v test4
Output:
The code is as follows:
[root@localhost test]# mkdir -v test4
mkdir: directory "test4" created
[root@localhost test]# mkdir -vp test5/test5-1
mkdir: directory "test5" created
mkdir: Created directory "test5/test5 -1"
[root@localhost test]#
Example 5: A command creates a directory structure for a project
Reference: 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:
The code is as follows:
[root@localhost test]# mkdir -vp scf/{lib/,bin/,doc/{info,product},logs/{info,product},service/deploy/{info,product}}
mkdir: directory "scf" created
mkdir: directory "scf/lib" created
mkdir: directory "scf/bin" created
mkdir: directory "scf/doc" created
mkdir: directory created "scf/doc/info"
mkdir: directory "scf/doc/product" created
mkdir: directory "scf/logs" created
mkdir: directory "scf/logs/info" created
mkdir: directory "scf/logs/product" created
mkdir: directory "scf/service" created
mkdir: directory "scf/service/deploy" created
mkdir: directory created "scf/service/deploy/info"
mkdir: directory "scf/service/deploy/product" created
[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]#
The following is a supplement:
Description: This command creates a specified directory name, requiring that the user creating the directory has write permission in the current directory, and the specified directory name cannot be an existing directory in the current directory.
Syntax:
mkdir [-m] [-p] directory name
Option description:
-m: Set access permissions for new directories, or use chmod command to set them;
-p: can be a path name. At this point if some directory path does not exist, plus this option, the system will automatically establish those do not exist directory, that is, a number of directories can be established;
Example of implementation:
The code is as follows:
$ mkdir DIRA
$ ls
DIRA
$ mkdir -m 775 DIRB
$ ls -l
drwxr-xr-x 2 xxxx users 4096 Feb 19 22:29 DIRA
drwxrwxr-x 2 xxxx users 4096 Feb 19 22:30 DIRB
$ mkdir -p DIRC/hello
$ ls -l
drwxr-xr-x 2 xxxx users 4096 Feb 19 22:29 DIRA
drwxrwxr-x 2 xxxx users 4096 Feb 19 22:30 DIRB
drwxr-xr-x 3 xxxx users 4096 Feb 19 22:31 DIRC
$ ls DIRC
hello
On Linux, the mkdir command creates a new folder.
mkdir -p creates a new subdirectory in a new subdirectory.
Examples:
mkdir -p about/abc/def creates three new directories hierarchically.
If you want to see what mkdir does, you can add the option "-v" and continue with the example above:
The code is as follows:
mkdir -pv about/abc/def
mkdir: created directory 'about'
mkdir: created directory 'about/abc'
mkdir: created directory 'about/abc/def'
Did reading the above help you? If you still want to have further understanding of related knowledge or read more related articles, please pay attention to the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.