In this article, we want to show you how to create and remove a directory in Linux.
What is a directory?
A directory is a location for storing files on your computer. Directories are found in a hierarchical file system, such as Linux, MS-DOS, OS/2, and Unix.
So here we go to create a directory in Linux.
How to create and remove a directory in Linux
How to create a directory in Linux
By using mkdir command you can create a directory. for example, we create a directory named orcacore:
[email protected]:~# mkdir orcacore [email protected]:~# ls orcacore
How to create multiple directories
You can create multiple directories by the following command:
mkdir directory1 directory2 directory3 ls directory1 directory2 directory3
Note: The names of directories should be separated by spaces.
How to create parent directories
To create parent directories using the mkdir command pass the –p switch.
mkdir –p directory 1 directory2 directory3
By using this switch if directory1 doesn’t exist mkir first makes the directory1 (parent) by itself.
Note: tree command shows the tree of the directory.
Here is some common switch of mkdir command:
set file mode (as in chmod), not a=rwx – umask.
no error if existing, make parent directories as needed.
print a message for each created directory.
If you don’t have permission to use mkdir command you need to use Sudo permissions to contact a system administrator.
How to remove a directory
By using of rmdir command you can remove your directory.
Note: if your directory doesn’t empty you can’t remove it.
Remove Directories with rm
rm is a command-line utility for deleting files and directories. Unlike rmdir the rm command can delete both empty and non-empty directories.
By default, when used without any option rm does not remove directories. To delete an empty directory, use the -d (–dir) option and to delete a non-empty directory, and all of its contents use the -r (–recursive or -R) option.
rm -d orcacore rm -r orcacore
Hope you enjoy this article about how to create and remove a directory in Linux from the Linux command category on Orcacore.