Table of contents
The command-line is a powerful tool for managing and organizing files and directories in Linux. In this blog post, we will cover two basic tasks: creating and deleting folders.
Creating a Folder
To create a new folder in Linux, we can use the mkdir
command. The syntax for creating a folder is as follows:
mkdir folder_name
For example, to create a new folder called documents
, we can use the following command:
mkdir documents
By default, the mkdir
the command will create the folder in the current working directory. To create a folder in a different location, we can specify the full path to the desired location as follows:
mkdir /path/to/folder
For example, to create a folder called documents
in the home
directory, we can use the following command:
mkdir /home/documents
Deleting a Folder
To delete a folder in Linux, we can use the rmdir
command. The syntax for deleting a folder is as follows:
rmdir folder_name
For example, deleting documents
the folder that we created earlier, we can use the following command:
rmdir documents
Like the mkdir
command, the rmdir
the command will delete the folder in the current working directory by default. To delete a folder in a different location, we can specify the full path to the folder as follows:
rmdir /path/to/folder
It is important to note that the rmdir
command will only delete empty folders.
Deleting a Non-Empty Folder
If the folder you want to delete is not empty, you will need to use the rm
command with the -r
option to recursively delete the contents of the folder. The syntax for deleting a non-empty folder is as follows:
rm -r folder_name
Like the rmdir
command, the rm
command can also be used with a full path to delete a folder in a different location:
rm -r /path/to/folder
It is important to be careful when using the rm
command, as it can permanently delete files and folders. Make sure you have a backup of any important data before using this command.
In this blog post, we covered the basics of creating and deleting folders in Linux using the mkdir
, rmdir
, and rm
commands. By using these commands, you can easily manage and organize your files and directories on a Linux system.
I hope this blog post has been helpful! If you have any questions or need further assistance, please don't hesitate to ask.