How to Create a Directory in Linux
Ads by Google
You can create a directory or folder with different ways in Linux. There are many types of Linux directories, for example, some directories for only Kernel uses, the user uses and some operating system directories. We use directories or folders for storing data or files with specific locations for future uses.
In this article, you will learn about creating a directory in Linux using Commands and as well as a graphical user interface.
How to create a directory in Linux Command
Linux Kernel is open source and Linux provides a lot of commands for interacting with operating system. The Linux also provides a “ mkdir ” command for creating a folder or directory in the Linux. The syntax for creating a directory in Linux is given below:
- First, open the terminal. Shortcut key ( Ctrl + Alt + T ).
- Using “ cd ” command go where you want to create a directory. You also check the present directory with “ pwd ” command.
- Now write the “ mkdir ” command with the name of the directory.
$ mkdir mydirectory
“ mydirectory ” is the name of your newly-created directory.
With “ mkdir ” command in the Linux, you can use “ mkdir ” command for multiple uses as an example, create a subdirectory in existing folder or directory.
Create a subdirectory
Let’s play with “ mkdir ” command a create multiple folders at the same time with a single command.
$ mkdir directory1 directory2 directory3
Now you check the newly directories or folders with the Linux basic command “ ls ”.
The uses of mkdir with different scenarios
Let’s discuss in detail about the “ mkdir ” command with different options and also fast techniques for its working.
mkdir –p option:
If you want to create a directory for complete detail with parents, again parents, and again parent then the syntax is given below:
mkdir – p parents/sun/child
mkdir—m777 option:
We know that the Linux is secure operating system. If you are creating a folder you can set its directories permissions for your new directory. “ –m777 ” option give us complete permission on the new directory for reading data from that folder, writing data in that folder and also execution for everyone. Also 775, 700 etc for different user accesses
Example
mkdir—m777 mydirectory
mkdir –v option:
“ –v ” is also an important option with “ mkdir ” command but it also works similar to default. But systex is different:
mkdir –v myDirectory
How to create a directory in Linux using java
Java is high-level language but JVM provides a better and fast to interact with basic level of Linux. A simple code for creating a new directory in Linux using java is:
new File ( ‘ yourNewDirectory ‘ ).mkdirs( );
File myDirectory = new File ( ‘ new folder ‘ ) ;
// this code first chechk the availability of directory that name is wirting in command above.
if ( !myDirectory.exists( ) ) {
System.out.println ( ‘ creating directory: ‘ + myDirectory.getName());
boolean result = false;
try{
myDirectory.mkdir( );
result = true;
}
Catch ( SecurityException se ) {
//handle it
}
If ( result ) {
System.out.println ( ‘ DIR created ‘ ) ;
}
}
How do you create a directory in Linux terminal?
- Open the terminal application in Linux.
- The mkdir command is is used to create new directories or folders.
- Say you need to create a folder name dir1 in Linux, type: mkdir dir1.
How do I create a directory in Unix?
- mkdir dirname — make a new directory.
- cd dirname — change directory. You basically ‘go’ to another directory, and you will see the files in that directory when you do ‘ls’.
- pwd — tells you where you currently are.
How do I copy directories in Linux?
What is MD command?
What is MD in PowerShell?
What is MD in batch file?
What does P mean in Linux?
What does R mean in Linux?
What is the use of P in Linux?
Which is the best Linux OS for beginners?
- Linux Distros.
- Ubuntu.
- Linux Mint.
- Kali Linux.
- Linux Kernel.
- Coding.
What is Linux OS command?
What is symbol called in Linux?
How do I find Linux?
- Open the terminal application (bash shell)
- For remote server login using the ssh: ssh user@server-name.
- Type any one of the following command to find os name and version in Linux: cat /etc/os-release. lsb_release -a. hostnamectl.
- Type the following command to find Linux kernel version: uname -r.
How do you represent in Linux?
Why do we use Linux?
Do hackers use Linux?
Ads by Google