How to create and remove the directory in Linux

There is a separate command to create and remove the directory in Linux. mkdir command is used to create a directory/folder on the Linux file system.

Syntax:
mkdir [OPTION] DIRECTORY

Refer below options used in mkdir command:

-m, –mode=MODESet file mode (as with the chmod command).
-p, –parentsCreate parent directories as necessary. When this option is used, no error is reported if a specified DIRECTORY already exists.
-v, –verboseVerbose output; print a message for each created directory.
–helpDisplay a help message, and exit.

Note: If the directory already exists then the command will modify the creation time of the directory.

Examples:

#Creates a new directory called linuxinanutshell whose parent is the current directory.
mkdir linuxinanutshell

#Create the linuxinanutshell directory, and set its permissions such that all users may read, write, and execute the contents.
mkdir -m a=rwx linuxinanutshell

#Creates the directory /home/linuxinanutshell/a/b/c. If the parent directory /home/linuxinanutshell/a/b/c does not already exist, mkdir will create that directory first.
mkdir -p /home/linuxinanutshell/a/b/c

To remove directory, use rmdir command

The rmdir utility removes the directory entry specified by each directory argument, provided the directory is empty.

Arguments are processed in the order given. In order to remove both a parent directory and a subdirectory of that parent, the subdirectory must be specified first so the parent directory is empty when rmdir tries to remove it.

Syntax:
rmdir [-p] directory

–ignore-fail-on-non-emptyignore any failure which occurs solely because a directory is non-empty.
-pEach directory argument is treated as a pathname of which all components will be removed, if they are empty, starting with the lastmost component. (See rm for fully non-discriminant recursive removal.)
-v, –verboseDisplay verbose information for every directory processed.
–helpDisplay a help message, and exit.


Example:
rmdir linuxinanutshell

Default options to create and remove the directory in Linux

create and remove the directory in Linux
You may want to see
How to sort contents of a file

The sort command is used to sort the contents of a file. You can sort the data in a text Read more

How to use sed command in Linux

sed, short for "stream editor", allows you to filter and transform text. A stream editor is used to perform basic Read more

How to use crontab in Linux

Cron is the system process that will automatically perform tasks for you according to a set schedule. The schedule is Read more

How to extract archive file in Linux

To extract archive file in Linux, you can use the tar command, used for extracting content from the archive files. "tar" Read more

Leave a Reply

Your email address will not be published. Required fields are marked *