Home Ask Us Create the directory structure given in the image using mkdir command and touch command

Create the directory structure given in the image using mkdir command and touch command

by Anup Maurya
14 minutes read

Create the directory structure given in the image using mkdir for directory creation and touch for creating files.

Note:assume that you are inside your home directory and always specify only relative path.

mkdir -p mydir/{colors/{basic,blended},shape,animals/{mammals,reptiles}}
 touch mydir/colors/{basic/{red,blue,green},blended/{yellow,orange,pink}}
 touch mydir/shape/{circle,square,cube}
 touch mydir/animals/{mammals/{platypus,bat,dog},reptiles/{snakes,crocodile,lizard}}

Let’s break down each part of the command:

  • mkdir -p mydir/{colors/{basic,blended},shape,animals/{mammals,reptiles}}
    • mkdir: This command is used to create directories.
    • -p: It stands for “parents” and ensures that the command creates parent directories as needed. If a directory already exists, it won’t produce an error.
    • mydir: The main directory to be created.
    • {}: This syntax is used to create nested directories within the specified path.
    • colors/{basic,blended}: Creates two subdirectories, “basic” and “blended,” within the “colors” directory.
    • shape: Creates a standalone “shape” directory.
    • animals/{mammals,reptiles}: Creates two subdirectories, “mammals” and “reptiles,” within the “animals” directory.
  • touch mydir/colors/{basic/{red,blue,green},blended/{yellow,orange,pink}}
    • touch: This command is used to create empty files.
    • mydir/colors/{basic/{red,blue,green},blended/{yellow,orange,pink}}: Creates a hierarchy of empty files in the specified structure.
      • In the “colors” directory, it creates subdirectories “basic” and “blended.”
      • In the “basic” directory, it creates empty files with the names “red,” “blue,” and “green.”
      • In the “blended” directory, it creates empty files with the names “yellow,” “orange,” and “pink.”
  • touch mydir/shape/{circle,square,cube}
    • Creates empty files with the names “circle,” “square,” and “cube” in the “shape” directory.
  • touch mydir/animals/{mammals/{platypus,bat,dog},reptiles/{snakes,crocodile,lizard}}
    • Creates empty files with the names “platypus,” “bat,” and “dog” in the “mammals” directory.
    • Creates empty files with the names “snakes,” “crocodile,” and “lizard” in the “reptiles” directory.

Create the directory structure given in the image using mkdir command for directory creation and touch command for creating files.

Note: assume that you are inside your home directory and always specify only relative path.

mkdir -p livingthings/{birds/{flyingbirds,nonflyingbirds},plants,animals/{mammals,reptiles}}
touch livingthings/birds/{flyingbirds/{stork,eagle,eider},nonflyingbirds/{kiwi,ostrich,penguin}}
touch livingthings/plants/{carrot,cabbage,daisy}
touch livingthings/animals/{mammals/{jaguar,dog,tiger},reptiles/{alligator,skink,turtle}}

Let’s break down each part of the command:

  • mkdir -p livingthings/{birds/{flyingbirds,nonflyingbirds},plants,animals/{mammals,reptiles}}
    • mkdir: This command is used to create directories.
    • -p: It stands for “parents” and ensures that the command creates parent directories as needed. If a directory already exists, it won’t produce an error.
    • livingthings: The main directory to be created.
    • {}: This syntax is used to create nested directories within the specified path.
    • birds/{flyingbirds,nonflyingbirds}: Creates two subdirectories, “flyingbirds” and “nonflyingbirds,” within the “birds” directory.
    • plants: Creates a standalone “plants” directory.
    • animals/{mammals,reptiles}: Creates two subdirectories, “mammals” and “reptiles,” within the “animals” directory.
  • touch livingthings/birds/{flyingbirds/{stork,eagle,eider},nonflyingbirds/{kiwi,ostrich,penguin}}
    • touch: This command is used to create empty files.
    • livingthings/birds/{flyingbirds/{stork,eagle,eider},nonflyingbirds/{kiwi,ostrich,penguin}}: Creates a hierarchy of empty files in the specified structure.
      • In the “birds” directory, it creates subdirectories “flyingbirds” and “nonflyingbirds.”
      • In the “flyingbirds” directory, it creates empty files with the names “stork,” “eagle,” and “eider.”
      • In the “nonflyingbirds” directory, it creates empty files with the names “kiwi,” “ostrich,” and “penguin.”
  • touch livingthings/plants/{carrot,cabbage,daisy}
    • Creates empty files with the names “carrot,” “cabbage,” and “daisy” in the “plants” directory.
  • touch livingthings/animals/{mammals/{jaguar,dog,tiger},reptiles/{alligator,skink,turtle}}
    • Creates empty files with the names “jaguar,” “dog,” and “tiger” in the “mammals” directory.
    • Creates empty files with the names “alligator,” “skink,” and “turtle” in the “reptiles” directory.

related posts

Leave a Comment