Linux Tutorial

Linux File/Directory Management

Linux Packaging And Compression

Vim Text Editor

Linux Text Processing

Linux Software Installation

Linux User/User Group Management

Linux Permission Management

Linux Filesystem Management

Linux Advanced Filesystem Management

Linux System Management

Linux Backup and Recovery

Linux System Service Management

Linux System Log Management

Linux Boot Management

LAMP/LNMP Environment

SELinux Management

Linux mkdir Command: Create A Directory (folder)

The mkdir command is a fundamental Linux command used for creating new directories. In this tutorial, we will cover how to use the mkdir command with various options.

Basic Usage

To create a new directory, simply run the mkdir command followed by the directory name. For example, to create a new directory called example_directory, you would use the following command:

mkdir example_directory

This command creates a new directory named example_directory in the current working directory.

Creating Multiple Directories

You can create multiple directories at once by providing multiple directory names separated by spaces. For example, to create three new directories called dir1, dir2, and dir3, you would use the following command:

mkdir dir1 dir2 dir3

Creating Nested Directories

If you want to create a directory along with its parent directories, you can use the -p or --parents option. For example, to create a directory named inner_directory inside a new directory named outer_directory, you would use the following command:

mkdir -p outer_directory/inner_directory

This command creates both outer_directory and inner_directory if they do not already exist.

Setting Directory Permissions

You can set the permissions for the new directory using the -m or --mode option followed by the desired permissions. Permissions can be specified as a symbolic mode or an octal number.

For example, to create a new directory called restricted_directory with read and write permissions for the owner only, you would use the following command:

mkdir -m 700 restricted_directory

Here, 700 represents the owner's read, write, and execute permissions (7), while group and other users have no permissions (0).

Verbose Output

To see the output for each directory created, you can use the -v or --verbose option. For example, to create a new directory called verbose_directory and display a message, you would use the following command:

mkdir -v verbose_directory

This command displays a message similar to:

mkdir: created directory 'verbose_directory'

Conclusion

The mkdir command is a fundamental command in Linux for creating new directories. By using various options, you can create single or multiple directories, nested directories, and set directory permissions, as well as display verbose output. Mastering the mkdir command is essential for efficient file management on Linux systems.

  1. How to create a directory in Linux using mkdir: To create a directory in Linux, you can use the mkdir command followed by the desired directory name. For example:

    mkdir my_directory
    
  2. Using mkdir to make a folder in Linux: The mkdir command is the key to making folders in Linux. Simply provide the folder name after the command:

    mkdir my_folder
    
  3. Linux mkdir command examples: Here are some examples of using mkdir with different options:

    • Create multiple directories:
      mkdir dir1 dir2 dir3
      
    • Create a nested directory:
      mkdir -p parent/child
      
  4. Create directory in Linux terminal with mkdir: In the Linux terminal, use the mkdir command to create a directory. Specify the directory name as an argument:

    mkdir new_directory
    
  5. Making directories in Linux with mkdir: Making directories is a breeze with mkdir. Simply enter the command followed by the directory name:

    mkdir my_directory
    
  6. Linux command line create folder with mkdir: Utilize the Linux command line to create a folder using mkdir. Here's a quick example:

    mkdir my_folder
    
  7. Advanced usage of mkdir command in Linux: mkdir offers advanced options for directory creation. For instance:

    • Set permissions while creating a directory:
      mkdir -m 755 my_directory
      
    • Create a directory with a specific owner:
      mkdir -o username my_directory
      
  8. mkdir vs. rmdir: creating and removing directories in Linux: While mkdir is used for creating directories, rmdir is used to remove them. Example:

    • Create a directory:
      mkdir my_directory
      
    • Remove the directory:
      rmdir my_directory