
The mkdir command enables the creation of directories in a file system. It's also known as make directory (mkdir) and allows you to create directories and sub-directories to organize the file system structure.
This article explains how to use the mkdir command in Linux to create and manage directories.
mkdir Command SyntaxBelow is the basic mkdir command syntax:
Within the above command, [options] includes optional flags that modify the command behavior, and directory_name... specifies the name of the directory to create. You can center multiple names separated by a comma , to create multiple directories simultaneously.
mkdir Command Optionsmkdir CommandCreate a new directory.
The above command creates a new directory my_directory in your active working directory.
Output:
Create multiple directories.
The above command creates three new directories dir1, dir2, and dir3 in the active working directory.
Output:
Create a new directory with specific permissions.
The above command creates a new directory dir4 with the 755 permissions level that enables read, write, execute privileges for the owner, and read, execute privileges for the group and other system users.
Output:
Create a parent directory.
The above command creates a new directory new_directory within the /path/to/parent/dir directory. If parent directory does not exist, it's created.
Output:
Create a new directory and output the command progress.
The above command creates a new directory my_directory and displays the operation's progress.
Output:
Create nested directories.
The above command creates a nested directory structure with the sub-directories src, docs, and tests using the brace expansion method.
Output:
Create a new directory with specific permissions recursively.
The above command creates a new directory new_directory in /path/to/parent/dir with the 755 permission level to create the necessary parent directories.
Output:
Create new directories with a sequential naming scheme.
The above command creates five directories dir1, dir2, dir3, dir4, and dir5 using the brace expansion method.
Output:
Create a new directory with spaces in its name.
The above command creates a new directory my directory with a space in its name.
Output:
Create new directories with a specific date or timestamp.
The above command creates a new directory with the current system date.
Output:
Create new directories using a loop.
The above command creates five directories dir_1, dir_2, dir_3, dir_4, and dir_5 using a loop function.
Output:
Create a new directory with specific permissions and ownership privileges.
The above command creates a new directory secure_data with the 770 permissions level with ownership privileges to user and group.
Output:
Create new directories and sub-directories with detailed messages.
The above command creates a complex directory structure with detailed messages for each new directory.
Output:
You have used the mkdir command to perform directory creation and management tasks. For more command options, run the man mkdir command to view the mkdir manual page.
0 Comments
Be the first to comment and share your perspective with the community.