How to Create a New Directory in Ubuntu using Terminal

  • Post category:Ubuntu

Creating and managing directories in Ubuntu is a fundamental skill for organizing your files efficiently. The terminal provides a powerful way to create directories with just a few commands. In this guide, we’ll show you how to use the mkdir command to create directories in Ubuntu.

Steps to Create a New Directory

Follow these simple steps to create a new directory in Ubuntu:

1. Open the Terminal

To open the terminal, press Ctrl + Alt + T or search for “Terminal” in your applications menu.

2. Navigate to the Desired Location (Optional)

If you want to create the directory in a specific location, you can navigate to that location using the cd (change directory) command. For example, to go to the Desktop, type:

cd ~/Desktop

3. Create the Directory

To create a new directory, use the mkdir command followed by the name of the directory. For example, to create a directory called “newfolder,” type:

mkdir newfolder

4. Verify the Directory Creation

To verify that the directory has been created, list the contents of the current directory using the ls command:

ls

You should see “newfolder” listed among the contents.

Creating Multiple Directories at Once

If you need to create multiple directories, you can do so by specifying their names in a single command. For example:

mkdir dir1 dir2 dir3

This will create three directories: dir1, dir2, and dir3 at the same time.

Creating Nested Directories

Sometimes, you may want to create directories inside other directories in one go. To do this, use the -p option:

mkdir -p parentdir/childdir/grandchilddir

This will create a directory hierarchy where parentdir contains childdir, which in turn contains grandchilddir.

Additional Options for mkdir

Here are a few more useful options you can use with the mkdir command:

  • Verbose Output: If you want to see a message confirming the creation of each directory, use the -v (verbose) option:
  mkdir -v newfolder
  • Set Permissions: You can set specific permissions for the directory as you create it by using the -m option. For example, to create a directory with permissions set to 700 (owner can read, write, and execute, others have no access), type:
  mkdir -m 700 newfolder

Conclusion

Using the mkdir command in Ubuntu, you can quickly and efficiently manage your directories. Whether you need to create a single directory, multiple directories, or even a nested directory structure, these commands give you the flexibility to organize your files just the way you want.

For more tutorials and tech tips, stay tuned to codeallow.com.