How to Create A Folder In Linux By Command?

12 minutes read

To create a folder in Linux using the command line, you can use the mkdir command. "mkdir" stands for "make directory" and it allows you to create a new directory or folder.


The basic syntax for creating a folder is as follows:

1
mkdir foldername


Replace "foldername" with the desired name of your folder.


For example, to create a folder named "documents", you would run the following command:

1
mkdir documents


This command creates a folder named "documents" in the current working directory.


Additionally, you can create nested directories by specifying the path. For example, to create a folder named "projects" within a folder named "documents", use the following command:

1
mkdir documents/projects


This command creates a "projects" folder within the "documents" folder.


It is important to note that if you wish to create a folder in a specific location, you need to provide the full path to that location. For instance, to create a folder named "photos" in the "/home/user/pictures" directory, use the following command:

1
mkdir /home/user/pictures/photos


That's it! You've now learned how to create a folder in Linux using the command line.

Best Linux Books to Read in 2024

1
Linux Bible

Rating is 5 out of 5

Linux Bible

2
CompTIA Linux+ Certification All-in-One Exam Guide, Second Edition (Exam XK0-005)

Rating is 4.9 out of 5

CompTIA Linux+ Certification All-in-One Exam Guide, Second Edition (Exam XK0-005)

3
How Linux Works, 3rd Edition: What Every Superuser Should Know

Rating is 4.8 out of 5

How Linux Works, 3rd Edition: What Every Superuser Should Know

4
The Linux Command Line, 2nd Edition: A Complete Introduction

Rating is 4.7 out of 5

The Linux Command Line, 2nd Edition: A Complete Introduction

5
CompTIA Linux+ Study Guide: Exam XK0-005

Rating is 4.6 out of 5

CompTIA Linux+ Study Guide: Exam XK0-005

6
Learn Linux Quickly: A Comprehensive Guide for Getting Up to Speed on the Linux Command Line (Ubuntu) (Crash Course With Hands-On Project)

Rating is 4.5 out of 5

Learn Linux Quickly: A Comprehensive Guide for Getting Up to Speed on the Linux Command Line (Ubuntu) (Crash Course With Hands-On Project)

7
Linux All-In-One For Dummies (For Dummies (Computer/Tech))

Rating is 4.4 out of 5

Linux All-In-One For Dummies (For Dummies (Computer/Tech))

8
Mastering KVM Virtualization: Design expert data center virtualization solutions with the power of Linux KVM, 2nd Edition

Rating is 4.3 out of 5

Mastering KVM Virtualization: Design expert data center virtualization solutions with the power of Linux KVM, 2nd Edition

9
Efficient Linux at the Command Line: Boost Your Command-Line Skills

Rating is 4.2 out of 5

Efficient Linux at the Command Line: Boost Your Command-Line Skills


What command can be used to create a temporary folder that gets automatically deleted after a certain period of time?

There is no built-in command or functionality in most operating systems to create a temporary folder that automatically gets deleted after a certain period of time.


Can you create a folder in Linux using the GUI?

Yes, you can create a folder in Linux using the Graphical User Interface (GUI). Here are the steps to create a folder using the GUI in popular Linux desktop environments:

  1. GNOME (used in Ubuntu, Fedora, etc.): Open the file manager (Nautilus). Navigate to the location where you want to create the folder. Right-click on an empty area and select "New Folder". Enter a name for the folder and press Enter.
  2. KDE (used in Kubuntu, openSUSE, etc.): Open the file manager (Dolphin). Navigate to the desired location. Right-click on an empty area and select "Create New" => "Folder". Enter a name for the folder and press Enter.
  3. Cinnamon (used in Linux Mint): Open the file manager (Nemo). Navigate to the location where you want to create the folder. Right-click on an empty area and select "Create Folder". Enter a name for the folder and press Enter.


These instructions may vary slightly depending on the Linux distribution and version you are using.


Can you create a folder with spaces in its name using the command line?

Yes, you can create a folder with spaces in its name using the command line. To do this, you need to enclose the folder name in quotes. Here's an example of how you can create a folder named "My Folder" using the command line:

1
mkdir "My Folder"


This command will create a folder named "My Folder" in the current working directory.

Best Linux Hosting Providers in 2024

1
AWS

Rating is 5 out of 5

AWS

2
DigitalOcean

Rating is 4.9 out of 5

DigitalOcean

3
Vultr

Rating is 4.8 out of 5

Vultr

4
Cloudways

Rating is 4.7 out of 5

Cloudways


Are there any restrictions on naming folders in Linux?

Yes, there are certain restrictions on naming folders in Linux. The restrictions are primarily related to the characters used in the folder name.

  1. Avoid using special characters: Folder names should generally avoid using special characters such as spaces, slashes (/), backslashes (), colons (:), question marks (?), asterisks (*), quotes (" or '), and so on. These characters have special meanings or functions in Linux, so using them in folder names can cause issues.
  2. Use alphanumeric characters and underscores: Folder names should primarily consist of alphanumeric characters (A-Z, a-z, 0-9) and underscores (_). However, it is recommended to start the folder name with an alphabet rather than a number.
  3. Use lowercase letters: Linux is case-sensitive, so it is advisable to use lowercase letters for folder names. While Linux allows uppercase letters as well, it can create confusion and potential issues while accessing files/folders in a case-sensitive environment.
  4. Avoid using reserved words: Certain words, such as "dev", "proc", "root", "tmp", etc., are reserved for system use in Linux. It is recommended not to use these reserved words as folder names to prevent any conflicts or confusion.


By adhering to these restrictions, you can ensure the compatibility and ease of use of your folder names in the Linux environment.


What is the command to create a folder with read-only permissions?

To create a folder with read-only permissions, you can use the "mkdir" command followed by the "chmod" command to set the permissions. Here is an example command:

1
2
mkdir folder_name
chmod 555 folder_name


In this example, the "mkdir" command is used to create a folder named "folder_name". Then, the "chmod" command is used to set the permissions of the folder to read-only. The permission code "555" means that the owner, group, and others have read-only permission, but no write or execute permissions.

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

Related Posts:

Setting folder permissions in Linux involves using the chmod command. Here is some information about how to set folder permissions:The chmod command stands for "change mode" and is used to modify the access permissions of files and directories in Linux...
To start a MySQL server on a Linux system, follow these steps:Open a terminal on your Linux machine. You can do this by searching for "Terminal" in the applications menu or using the keyboard shortcut Ctrl+Alt+T. Log in to the Linux system as the root ...
To determine the architecture of Linux, you can follow these steps:Open a terminal: Launch a terminal window on your Linux system to execute commands. Use the uname command: Type the uname -a command and press Enter. This will display information about your Li...