Bird
Raised Fist0
Linux CLIscripting~20 mins

mkdir (create directories) in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
πŸŽ–οΈ
mkdir Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
πŸ’» Command Output
intermediate
1:30remaining
What is the output of this mkdir command?
You run the command mkdir -p /tmp/testdir/subdir on a Linux system. What happens if /tmp/testdir does not exist?
Linux CLI
mkdir -p /tmp/testdir/subdir
ABoth /tmp/testdir and /tmp/testdir/subdir directories are created without error.
BOnly /tmp/testdir/subdir is created; /tmp/testdir must exist first or it errors.
CThe command fails with a permission denied error.
DThe command creates a file named subdir inside /tmp/testdir.
Attempts:
2 left
πŸ’‘ Hint
The -p option helps create parent directories if missing.
πŸ’» Command Output
intermediate
1:30remaining
What error does this mkdir command produce?
You run mkdir /root/newdir as a normal user (not root). What is the expected output?
Linux CLI
mkdir /root/newdir
Amkdir: invalid option -- 'r'
BDirectory /root/newdir created successfully.
Cmkdir: missing operand
Dmkdir: cannot create directory β€˜/root/newdir’: Permission denied
Attempts:
2 left
πŸ’‘ Hint
Normal users usually cannot write inside /root directory.
πŸ“ Syntax
advanced
1:30remaining
Which mkdir command creates multiple directories at once?
You want to create three directories named dir1, dir2, and dir3 in your current folder with one command. Which option is correct?
Amkdir dir1 dir2 dir3
Bmkdir -p dir1,dir2,dir3
Cmkdir dir1; mkdir dir2; mkdir dir3
Dmkdir -m dir1 dir2 dir3
Attempts:
2 left
πŸ’‘ Hint
mkdir can take multiple directory names separated by spaces.
πŸ’» Command Output
advanced
1:30remaining
What is the effect of this mkdir command with -m option?
You run mkdir -m 700 secret. What are the permissions of the created directory?
Linux CLI
mkdir -m 700 secret
AThe directory 'secret' is created with default permissions 755.
BThe command fails with an invalid mode error.
CThe directory 'secret' is created with permissions rwx------ (only owner can read, write, execute).
DThe directory 'secret' is created with permissions rwxrwxrwx.
Attempts:
2 left
πŸ’‘ Hint
The -m option sets the permission mode of the new directory.
πŸš€ Application
expert
2:00remaining
How many directories are created by this command?
You run mkdir -p /tmp/a/b/c /tmp/a/d/e. How many new directories are created if none of these exist?
Linux CLI
mkdir -p /tmp/a/b/c /tmp/a/d/e
A2 directories: /tmp/a/b/c and /tmp/a/d/e only
B5 directories: /tmp/a, /tmp/a/b, /tmp/a/b/c, /tmp/a/d, /tmp/a/d/e
C3 directories: /tmp/a/b/c, /tmp/a/d/e, /tmp/a
D6 directories: /tmp, /tmp/a, /tmp/a/b, /tmp/a/b/c, /tmp/a/d, /tmp/a/d/e
Attempts:
2 left
πŸ’‘ Hint
The -p option creates all missing parent directories for each path.

Practice

(1/5)
1. What does the mkdir command do in Linux?
easy
A. Deletes files from the system
B. Creates new directories (folders) to organize files
C. Lists files in a directory
D. Changes the current directory

Solution

  1. Step 1: Understand the purpose of mkdir

    The mkdir command is used to create new directories (folders) in Linux.
  2. Step 2: Compare with other commands

    Deleting files is done by rm, listing files by ls, and changing directories by cd.
  3. Final Answer:

    Creates new directories (folders) to organize files -> Option B
  4. Quick Check:

    mkdir = create folders [OK]
Hint: mkdir always makes folders, not files or lists [OK]
Common Mistakes:
  • Confusing mkdir with rm or ls commands
  • Thinking mkdir deletes files
  • Assuming mkdir changes directories
2. Which of the following is the correct syntax to create a directory named projects?
easy
A. mkdir: projects
B. mkdir -d projects
C. mkdir projects
D. mkdir > projects

Solution

  1. Step 1: Recall mkdir syntax

    The basic syntax to create a directory is mkdir directory_name. No extra symbols or options are needed for a simple directory.
  2. Step 2: Evaluate options

    mkdir -d projects uses a non-existent -d flag, mkdir: projects uses invalid colon syntax, and mkdir > projects uses redirection which is incorrect here.
  3. Final Answer:

    mkdir projects -> Option C
  4. Quick Check:

    Simple mkdir = mkdir directory_name [OK]
Hint: Use just mkdir plus folder name to create one folder [OK]
Common Mistakes:
  • Adding unnecessary flags like -d
  • Using colons or symbols incorrectly
  • Trying to redirect output with >
3. What will be the result of running this command?
mkdir -p home/user/docs
medium
A. Creates home, user, and docs directories if they don't exist
B. Creates only the docs directory if home/user exists
C. Shows an error because -p is invalid
D. Deletes existing home/user/docs directory

Solution

  1. Step 1: Understand the -p option

    The -p option tells mkdir to create parent directories as needed without error if they already exist.
  2. Step 2: Analyze the command effect

    This command creates the full path home/user/docs including any missing directories in the path.
  3. Final Answer:

    Creates home, user, and docs directories if they don't exist -> Option A
  4. Quick Check:

    mkdir -p = create nested folders [OK]
Hint: Use -p to make all needed folders in one go [OK]
Common Mistakes:
  • Thinking -p only creates the last folder
  • Assuming -p is invalid or causes errors
  • Confusing mkdir with delete commands
4. You run mkdir folder1 folder2 folder3 but get an error. What is the most likely cause?
medium
A. You need to use -p to create multiple folders
B. mkdir cannot create more than one folder at a time
C. You must create folders one by one with separate commands
D. One or more folder names contain spaces without quotes

Solution

  1. Step 1: Check mkdir multiple folder support

    mkdir supports creating multiple folders by listing names separated by spaces.
  2. Step 2: Identify common error with spaces

    If folder names contain spaces, they must be quoted or escaped. Otherwise, mkdir treats parts as separate names causing errors.
  3. Final Answer:

    One or more folder names contain spaces without quotes -> Option D
  4. Quick Check:

    Spaces in names need quotes for mkdir [OK]
Hint: Quote folder names with spaces to avoid errors [OK]
Common Mistakes:
  • Thinking -p is needed for multiple folders
  • Believing mkdir only creates one folder at a time
  • Not quoting folder names with spaces
5. You want to create a project folder structure with src, bin, and docs inside myproject in one command. Which command achieves this?
hard
A. mkdir -p myproject/src myproject/bin myproject/docs
B. mkdir myproject && mkdir src bin docs
C. mkdir -p myproject/src/bin/docs
D. mkdir myproject/src myproject/bin myproject/docs

Solution

  1. Step 1: Understand nested folder creation

    Using -p allows creating parent directories and nested folders in one command without errors.
  2. Step 2: Analyze each option

    mkdir myproject/src myproject/bin myproject/docs lacks -p so may fail if myproject doesn't exist. mkdir -p myproject/src myproject/bin myproject/docs correctly uses -p to create all paths. mkdir -p myproject/src/bin/docs creates nested folders incorrectly. mkdir myproject && mkdir src bin docs creates folders separately, not in one command.
  3. Final Answer:

    mkdir -p myproject/src myproject/bin myproject/docs -> Option A
  4. Quick Check:

    Use mkdir -p with full paths for multiple nested folders [OK]
Hint: Use mkdir -p with all paths to create nested folders at once [OK]
Common Mistakes:
  • Omitting -p when parent folder doesn't exist
  • Creating nested folders incorrectly as one path
  • Running multiple mkdir commands instead of one
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard