Linux mkdir command - Create directories

Linux mkdir command: Create directories

Linux mkdir command Function Description

Directories can be created on a Linux system using the mkdir command.

The mkdir command is used to create directories. This command creates the directory named by dirname.

  • If the directory name is not preceded by any pathname, the directory specified by dirname will be created in the current directory;
  • if an existing path is given, a specified directory will be created in that directory. When creating a directory, you should make sure that the newly created directory does not overlap with the files in the directory it is in.

Note: When creating files, do not store all files in the main directory, you can create subdirectories and organize files more efficiently through them. It is best to use consistent naming to distinguish files from directories. For example, directory names can start with a capital letter so that the directory name appears first in the directory listing.

A subdirectory should contain files of similar type or similar purpose. For example, a subdirectory should be created that contains all database files, another subdirectory should contain spreadsheet files, another subdirectory should contain word processing documents, and so on. Directories are also files, they follow the same naming rules as regular files, and a directory can be uniquely specified using full paths.

Linux mkdir command Syntax

mkdir [Option] [Directory]

The meaning of each option in the command is shown in the table:

Option Description
-m<Permission Mode> Set permissions for newly created directories, the default permissions are 755 when there is no -m option
-v Display a message each time a new directory is created
-p It can be a path name. If some directories in the path do not exist yet, adding this option will automatically create those directories that do not exist yet, i.e. multiple directories can be created at once.

Linux mkdir command Example

Create directory newdir1 with default permissions of 755

[root@rhel ~]# mkdir newdir1

Create the directory newdir2 with 777 permissions

[root@rhel ~]# mkdir -m 777 newdir2

Multiple directories can be created at once

mkdir -p: A flag which enables the command to create parent directories as necessary. If the directories exist, no error is specified.

mkdir -p apidemos-aaa/bbb/ccc

Output:

Linux mkdir command

Like(1)

Related

Linux Login Logout Command
Linux login commandLinux logout commandLinux nologin commandLinux exit commandLinux sulogin commandLinux rlogin commandLinux poweroff commandLinux ctrlaltdel CommandLinux shutdown commandLinux halt commandLinux reboot commandLinux init commandLinux runlevel commandLinux telinit command
Linux File Management Command
Linux cat commandLinux tac commandLinux nl commandLinux more commandLinux less commandLinux head commandLinux tail commandLinux rev commandLinux fold commandLinux fmt commandLinux expand commandLinux pr commandLinux sort commandLinux uniq commandLinux cut commandLinux comm commandLinux diff commandLinux join commandLinux diff3 commandLinux cmp commandLinux colrm commandLinux paste commandLinux mkdir commandLinux tr commandLinux split commandLinux csplit commandLinux tee commandLinux unexpand commandLinux patch commandLinux awk commandLinux sed commandLinux od commandLinux pwd commandLinux cd commandLinux ls commandLinux dir commandLinux dirs commandLinux touch commandLinux rmdir commandLinux cp commandLinux mv commandLinux rm commandLinux install commandLinux tmpwatch commandLinux file commandLinux du commandLinux wc commandLinux tree commandLinux cksum commandLinux md5sum commandLinux sum commandLinux dirname commandLinux mkfifo Command
Cron Expressions
Cron Expression to Run Every Day at 12 PMUnderstanding Vue Cron ExpressionsUnderstanding JS Cron ExpressionsA Comprehensive Guide to Cron Expressions for Scheduled TasksUnderstanding Linux Cron ExpressionsUnderstanding Quartz Cron ExpressionsCron ExpressionCron Time ExpressionCron Expression ParsingCron Expression: Executing a Task Every SecondCron Expression for Every Minute ExecutionCron Expression to Execute Every 10 MinutesCron Expression: Executing Every HourCron Expression to Execute Once a YearCron Expression: How to Schedule a Task to Run Daily at Midnight?