Definition of Create a Folder in Linux
To create a folder in Linux, we can use ‘mkdir’ command line in Linux Servers. This command also helps in creating multiple directories at the same time and even grant the permissions for the folders. Any user who creates a folder should have enough permissions in the parent directory else they might receive ‘permission denied’ error. In this article, we will learn how to create a folder in Linux Server. We will also see how to set permissions for a folder with examples and screenshots for better understanding.
Syntax to create a folder in Linux:
We use ‘mkdir’ command to create a folder. Different options are provided or passed through this command as per our requirement. We can specify number of directories at the same time to create in Linux. The syntax to create a folder is given as below:
mkdir [options..] [directories..]
- -m: To set the folder’s permission level. Be default, if no permission is specified, it will take the same permission of its parent.
- -p: It will create the directories structures from parent path.
- -v: It will print the directories created explicitly.
- -Z: By default, it will set the SELinux security.
How to Create a Folder in Linux?
To create a folder in Linux, we can use different options as below. The description of each option is mentioned for better understanding.
|-m, –mode=MODE||It will help in setting the file mode like chmod command.|
|-p, –parents||It will create folder structures from parent directories, it will not throw error if existing.|
|-v, –verbose||It prints messages when each directories are created.|
|#NAME?||It sets SELinux security data of every directory created by default .|
|–context[=CTX]||It is similar to -Z option, or if CTX is passed in the arguement then it will set the SELinux or SMACK security data to CTX.|
|–help||It prints the list of options and exits .|
|–version||It will print the output version info and exits .|
Examples to Create a Folder in Linux
Below are the options with examples on how to create a folder in Linux.
1. No Option
When no options are passed through mkdir command in Linux, it will simply create the directories. We can create one directory or multiple directories at a time as shown below.
mkdir folder1 folder2 folder3
2. Option –version
This option will help to display the version of ‘mkdir’ command in Linux. It also provides other information regarding the license and authors. Once all the information is displayed, it will exit.
3. Option –help
The option ‘–help’ will display all the options that are available for ‘mkdir’ command with its description and it will exit.
We can see that –help command displays the options available for mkdir command.
4. Option -v, –verbose
It will display all the process explicitly. For ‘mkdir’ command, it will display all the directories created when we pass this option.
mkdir -v [directories..]
In the below example, we can see the information on how the folders are been created one by one.
mkdir -v fold1 fold2 fold3
5. Option -p
The option -p, will help to create directories from the parent path. If the directories are present, then no error is thrown. If we do not specify ‘-p’ and we try creating directories from parent path, it will thrown an error stating that ‘no such file or directory found’.
mkdir -p [directories]
From the below example, it is clear that the directories are been created from the parent path by using -p option.
mkdir -p -v fold4/first/second/third
6. Option -m
The option -m helps to set the file permissions. It is similar to chmod command in Linux. We can specify the permissions to the folder as per our requirement.
mkdir -m a=rwx [directories]
Here the permissions to folder is set to rwx which means the folder is given all the permissions like read, write and execute.
mkdir -m a=rwx folder
To create a folder in Linux, we can use ‘mkdir’ command line in Linux Servers. This command also helps in creating multiple directories at the same time and even grant the permissions for the folders. Any user who creates a folder should have enough permissions in the parent directory else they might receive ‘permission denied’ error. In this article, we will learnt how to create a folder in Linux Server. The command ‘mkdir’ is one of the most useful command in Linux to create a folder through CLI.
This is a guide to Create Folder in Linux. Here we also discuss the definition and how to create a folder in linux along with examples to create a folder in linux. You may also have a look at the following articles to learn more –