Linux for Beginners: Mastering the mkdir Command

If you’re new to the world of Linux, you’ve probably encountered a plethora of commands that seem cryptic and intimidating. Fear not! In this beginner-friendly guide, we’ll demystify one of the most fundamental commands: mkdir.

What is mkdir?

mkdir stands for “make directory.” It’s like a magic wand for creating folders super easily. Whether you’re organizing your files, setting up a project structure, or just want to keep things neat and tidy, mkdir is your trusty companion.

Basic Syntax

To create a directory in Linux, simply type:

mkdir directory_name

Replace directory_name with the desired name of the directory you want to create. For example:

mkdir my_directory

This command will create a new directory named “my_directory” in your current working directory.

Cool Tricks with mkdir

1. Creating Multiple Directories

You’re not limited to creating just one directory at a time. Use mkdir to create multiple directories simultaneously:

mkdir dir1 dir2 dir3

This command will create three directories: dir1, dir2, and dir3.

2. Verbose Mode

Want to see what’s happening behind the scenes? Enable verbose mode with the -v or --verbose option:

mkdir -v my_folder

You’ll get a message for every directory created, making it easier to track your actions.

3. Creating Parent Directories

Sometimes you need to create a directory hierarchy. The -p option allows you to create parent directories as necessary:

mkdir -p project/docs/images

This command will create the project, docs, and images directories, even if they don’t exist yet.

4. Setting Permissions

Use the -m option to set file modes or permissions for the created directories. The syntax follows that of the chmod command:

mkdir -m 755 public

This sets the permissions to read, write, and execute for the public directory.

Practical Examples

Let’s put theory into practice:

  1. Creating a Simple Directory:
mkdir my_photos
  1. Creating Nested Directories:
mkdir -p project/src/components
  1. Verbose Mode:
mkdir -v logs

Now you’re armed with the knowledge to wield mkdir like a pro. Go forth, create directories, and organize your digital life with confidence!

Click to View Video