Translate

Sunday 19 November 2023

Creation of directories in Linux

 Creation of directories in Linux


Creating directories in Linux is a fundamental task for managing file organization and storage. There are two primary methods for creating directories in Linux: the mkdir command and the mkdtemp command.

Using the mkdir Command

The mkdir command is the standard tool for creating directories in Linux. It allows you to specify the names of the directories you want to create and the locations where you want to place them. The syntax for the mkdir command is as follows:


Bash

mkdir [options] directory_name1 directory_name2...

For example, to create a directory named "mydir" in your current working directory, you would use the following command:


Bash

mkdir mydir

To create a directory named "mydir" within a specific directory, such as "/home/user/Documents", you would use the following command:


Bash

mkdir /home/user/Documents/mydir

Using the mkdtemp Command

The mkdtemp command is specifically designed for creating temporary directories. It creates a directory with a unique, randomly generated name and returns the pathname of the newly created directory. The syntax for the mkdtemp command is as follows:


Bash

mkdtemp [options] [template]

For example, to create a temporary directory in your current working directory, you would use the following command:


Bash

mkdtemp

This will create a directory with a unique name, such as /tmp/d123456, and return the pathname of that directory. The temporary directory will be automatically deleted when the process that created it terminates.

Additional Options for Creating Directories

The mkdir and mkdtemp commands offer various options for customizing the directory creation process. Some commonly used options include:

  • -p: Creates parent directories if they do not exist

  • -m: Sets the permissions of the newly created directory

  • -v: Displays verbose output, including the pathnames of the created directories

For more detailed information on the mkdir and mkdtemp commands, refer to the respective man pages:


Bash

man mkdir
man mkdtemp

No comments:

Post a Comment

Note: only a member of this blog may post a comment.