Do you need to memorize Linux commands?
Daily Linux Command: man
The mkdir(1) command is used to create directories, with its argument being the path name of the new directory.
✦•———-Basic Usage———-•✦
Simply follow the command with the path of the new directory. It can be either a relative path or an absolute path. If the command produces no output, it indicates that the creation was successful.
$ mkdir jqlg
$ ls -l
total 0
drwxr-xr-x. 2 dybai dybai 40 Oct 15 10:30 jqlg
<span>ls -l</span> command can be used to view file attributes, where if the type is <span>drwxr-xr-x.</span>, it indicates that it is a directory. For more information about file types, you can refer to the previous article (II) Detailed Explanation of Linux File Attributes — File Types | Computer’s First Lesson. Using the <span>ls</span> command with the <span>-d</span> option allows you to view the directory itself rather than expanding its contents.
$ ls -ld jqlg
drwxr-xr-x. 2 dybai dybai 40 Oct 15 10:30 jqlg
You can also use the <span>ls</span> command with the <span>-F</span> option to display a <span>/</span> symbol at the end of the directory name.
$ ls -lF
total 0
drwxr-xr-x. 2 dybai dybai 40 Oct 15 10:30 jqlg/
When specifying the path for the new directory, its parent path must exist; otherwise, an error will occur:
$ mkdir jqlg/linux/ChapterOne
mkdir: cannot create directory ‘jqlg/linux/ChapterOne’: No such file or directory
If you need to create the complete parent path while creating the directory, you should specify the <span>-p</span> option.
$ mkdir -p jqlg/linux/ChapterOne
$ tree
.
└── jqlg
└── linux
└── ChapterOne
4 directories, 0 files
✦•———-Advanced Usage Tips———-•✦
As introduced in our previous articles, you can use wildcards to create multiple directories at once.
$ mkdir Chapter{1..6}
$ ls -l
total 0
drwxr-xr-x. 2 dybai dybai 40 Oct 15 10:41 Chapter1
drwxr-xr-x. 2 dybai dybai 40 Oct 15 10:41 Chapter2
drwxr-xr-x. 2 dybai dybai 40 Oct 15 10:41 Chapter3
drwxr-xr-x. 2 dybai dybai 40 Oct 15 10:41 Chapter4
drwxr-xr-x. 2 dybai dybai 40 Oct 15 10:41 Chapter5
drwxr-xr-x. 2 dybai dybai 40 Oct 15 10:41 Chapter6
For other wildcard usages, please refer to our previous article on Daily Linux Command: rm. Since wildcards are provided by the shell, they can be used directly in many commands.
Congratulations, you have gained more useful knowledge! ✨