How to use the mkdir command on Ubuntu Linux with Examples

|

|

The post walks through the “mkdir” command on Ubuntu used for creating new directories on the file system. It breaks down the command’s syntax, options, and examples. Options discussed include setting file modes, creating parent directories as needed, displaying verbose output, setting SELinux security context, and displaying help or version information.

The mkdir command on Ubuntu allows users to create new directories if they do not exist on the file systems.

The mkdir command on Ubuntu Linux creates new directories or folders if they do not exist on the file systems. It is similar to using your mouse and keyboard to create new folders, but the mkdir command is used on the command line.

This command is particularly useful for Linux users who prefer to work with the system through the command line interface. By using the mkdir command, users can create directories with specific permissions and attributes.

When you’re ready to learn how to use the mkdir commands, follow the guide below:

About mkdir command:

The mkdir command on Ubuntu allows users to create new directories if they do not exist on the file systems, like using your mouse and keyboard to create new folders. The mkdir is the way to do it on the command line.

Syntax:

The syntax is the rule and format of how the mkdir command can be used. The syntax can be reordered. But a straight format must be followed.,.

Below is an example syntax of how to use the mkdir command.

mkdir [OPTION]. DIRECTORY.

Options:

The command line options are switches or flags that determine how the commands are executed or controlled. They modify the behavior of the command. They are separated by spaces and followed after the command options.

Below are some options for the mkdir command:

DIRECTORY.Replace DIRECTORY .. with the name of the directory you want to create. If the specified directory does not already exist, mkdir creates it.
-m=MODE,
–mode=MODE
Use the -m or –mode option set file mode (as in chmod), not a=rwx – umask. The syntax of MODE is the same as with the chmod command.
-p,
–parents
Use the -p or –parents option to make parent directories as needed
-v,
–verbose
Verbose output. Print a message for each created directory.
 -ZUse the -Z option to set the SELinux security context of each created directory
to the default type
–helpUse the –help option with the command to display this help and exit
–version Use the –version option to output version information and exit.

Examples:

Below are some examples of how to run and use the mkdir on Ubuntu Linux.

Run the command below to create a new directory, Confidential, without any mkdir command options. This will create a simple directory or folder called Confidential.

mkdir Confidential

You can use the mkdir command with the -m or –mode option to create a directory and specify the permissions. For example, run the commands below to create a directory or folder called Confidential and set permission.

mkdir -m a=rwx Confidential

The above command will create a Confidential directory and give all users = read, write, and execute permissions. (a = read, write, execute)

When you run mkdir with the –help option, you’ll see the help text below:

Usage: mkdir [OPTION]. DIRECTORY.
Create the DIRECTORY(ies), if they do not already exist.

Mandatory arguments to long options are mandatory for short options too.
  -m, --mode=MODE   set file mode (as in chmod), not a=rwx - umask
  -p, --parents     no error if existing, make parent directories as needed
  -v, --verbose     print a message for each created directory

That’s it!

I hope you like it, and please come back soon for more Ubuntu Linux commands!


Discover more from Geek Rewind

Subscribe to get the latest posts to your email.

Like this:



Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Blog at WordPress.com.

Discover more from Geek Rewind

Subscribe now to keep reading and get access to the full archive.

Continue reading