Learn about mkdir command in Linux

Learn about kmod command in Linux.

The mkdir command in Linux is used to create directories (folders) in a file system. It stands for “make directory.” The command allows you to specify the name of the directory you want to create, and you can also provide various options and arguments to customize the behavior of the command.

Here’s a detailed explanation of how the mkdir command works in Linux:

Syntax:

mkdir [options] directory_name

Basic Usage:
To create a new directory, you would typically use the mkdir command followed by the name of the directory you want to create. For example:

mkdir my_directory

This will create a new directory named my_directory in the current working directory.

Options:

-p or --parents: This option allows you to create parent directories as needed. If you want to create a directory along with its parent directories (if they don’t exist), you can use this option. For example:

mkdir -p path/to/my_directory

This will create the directory my_directory along with any necessary parent directories (path and to) if they don’t exist.

-m or --mode: This option allows you to specify the permissions (mode) for the newly created directory using octal notation. For example:

mkdir -m 755 my_directory

This will create the directory my_directory with permissions set to 755.

--help: Displays the help message for the mkdir command, showing its usage and available options.

--version: Displays the version information for the mkdir command.

Examples:

Creating a directory with specific permissions:

mkdir -m 700 private_data

This will create a directory named private_data with permissions set to 700 (read, write, and execute for the owner only).

Creating a directory with parent directories:

mkdir -p documents/important/2023

This will create the directory structure: documents/important/2023.

Creating multiple directories:

mkdir dir1 dir2 dir3

This will create three directories named dir1, dir2, and dir3 in the current working directory.

Creating directories with complex names:

mkdir "My Documents" 'Work Files' 'Images and Videos'

This will create three directories with spaces in their names.

Remember that the mkdir command allows you to create directories in the specified path or current working directory. You can also provide an absolute path to create directories at a specific location in the file system.

Always be cautious when using commands that modify the file system, especially with elevated privileges, as they can have significant consequences.

Leave a Comment

Scroll to Top