😎
CS1.dev
  • Welcome to Computer Science 1
  • Unit 2
    • Activity 2.1
    • Activity 2.2
    • Activity 2.3
    • Activity 2.4
    • Activity 2.5
    • Activity 2.6
    • Activity 2.7
    • Activity 2.9
    • Activity 2.10
    • Project 2
    • Activity 2.8
    • Activity 2.11
    • Activity 2.12
    • Activity 2.13
    • Activity 2.14
    • Activity 2.15
    • Activity 2.16
    • Activity 2.17
    • Activity 2.18
    • Activity 2.19
    • Project 3
    • Activity 2.20
    • Activity 2.21
    • Activity 2.22
    • Activity 2.23
    • Activity 2.24
    • Project 4
    • Activity 2.25
    • Activity 2.26
    • Activity 2.27
    • Activity 2.28
    • Project 5
    • Activity 2.29
    • Activity 2.30
    • Activity 2.31
    • Activity 2.32
    • Activity 2.33
    • Activity 2.34
    • Activity 2.35
    • Activity 2.36
  • Unit 3
    • Activity 3.1
    • Activity 3.2
    • Activity 3.3
    • Activity 3.4
    • Activity 3.5
    • Activity 3.6
    • Activity 3.7
    • Activity 3.8
    • Activity 3.9
    • Activity 3.10
    • Activity 3.11
    • Project 6
    • Activity 3.12
  • Activity 3.13
  • Activity 3.14
  • Activity 3.15
  • Activity 3.16
  • Project 7
  • Activity 3.17
  • Activity 3.18
  • Activity 3.19
  • Project 8
  • Linux
    • bash
    • cat
    • cd
    • chmod
    • df
    • echo
    • find
    • grep
    • less
    • ls
    • mkdir
    • more
    • pwd
    • tar
    • touch
    • unzip
    • zip
Powered by GitBook
On this page
  1. Linux

mkdir

The mkdir command in Linux is a commonly used command in the command-line interface, and its primary function is to create new directories. The name mkdir stands for "make directory". Understanding the usage of mkdir is essential for file system organization and management in Linux. Here are the key aspects and functionalities of the mkdir command:

  1. Basic Directory Creation: To create a new directory, you simply use mkdir followed by the name of the directory you want to create. For example, mkdir new_directory will create a directory named new_directory.

  2. Creating Multiple Directories: mkdir can create multiple directories at once. For instance, mkdir dir1 dir2 dir3 will create three new directories named dir1, dir2, and dir3.

  3. Creating Nested Directories: The -p (parents) option allows you to create a directory along with any necessary parent directories. For example, mkdir -p dir1/dir2/dir3 will create dir3 and also create dir1 and dir2 if they don't already exist. This is useful for setting up a nested directory structure in one command.

  4. Setting Permissions: When creating a directory, you can set its permissions using the -m option followed by the permission set. For example, mkdir -m 755 new_directory creates a directory with read, write, and execute permissions for the owner, and read and execute permissions for the group and others.

  5. Checking for Errors: If mkdir encounters an error (like trying to create a directory that already exists), it will display an error message. This behavior can be suppressed using the -p option, which will not show an error if the directory already exists.

  6. Verbose Mode: Using mkdir with the -v (verbose) option will make it display a message for each directory it creates. This can be useful for debugging or confirming the actions of a script.

  7. Use in Scripts: mkdir is frequently used in shell scripts to ensure the required directory structure is in place for the script's operations.

PreviouslsNextmore

Last updated 1 year ago