How to create a folder

Report
Question
851 views

Please explain why do you think this question should be reported?

Report Cancel

To create a folder in Linux, you can use the command mkdir (short for “make directory”).

Navigate to the directory where you want to create the new folder. You can use the cd command to change to the desired directory.

Once you are in the desired directory, use the mkdir command followed by the name of the new folder.

$ mkdir my_folder

If the folder name contains spaces, you can enclose it in quotes, like this:

$ mkdir "my_folder"

To create more than one directory simultaneously, specify the names of the new directories after mkdir with a blank space between them:

$ mkdir dir1 dir2 dir3

$ ls -l
total 0
drwxrwxr-x. 2 localuser localuser 6 Jun  9 14:57 dir1
drwxrwxr-x. 2 localuser localuser 6 Jun  9 14:57 dir2
drwxrwxr-x. 2 localuser localuser 6 Jun  9 14:57 dir3
[mydir]$ ls -R
.:
dir1  dir2  dir3

./dir1:

./dir2:

./dir3:

To create a directory with a directory inside of it, use the -p option:

$ mkdir -p dir4/subdir1

$ ls -l
total 0
drwxrwxr-x. 2 localuser localuser  6 Jun  9 14:57 dir1
drwxrwxr-x. 2 localuser localuser  6 Jun  9 14:57 dir2
drwxrwxr-x. 2 localuser localuser  6 Jun  9 14:57 dir3
drwxrwxr-x. 3 localuser localuser 21 Jun  9 16:57 dir4

$ ls -lR
.:
total 0
drwxrwxr-x. 2 localuser localuser  6 Jun  9 14:57 dir1
drwxrwxr-x. 2 localuser localuser  6 Jun  9 14:57 dir2
drwxrwxr-x. 2 localuser localuser  6 Jun  9 14:57 dir3
drwxrwxr-x. 3 localuser localuser 21 Jun  9 16:57 dir4

./dir1:
total 0

./dir2:
total 0

./dir3:
total 0

./dir4:
total 0
drwxrwxr-x. 2 localuser localuser 6 Jun  9 16:57 subdir1

./dir4/subdir1:
total 0
[mydir]$ ls -l dir4/
total 0
drwxrwxr-x. 2 localuser localuser 6 Jun  9 16:57 subdir1

Ref: RedHat

About the Author

Leave an answer