In the previous article, we have discussed the ways in which we can utilise the command line interface of Windows for creating new directories. Now, let’s look at this process of creating a new directory on macOS and Linux.
Create a new directory
You can create any directory on these operating systems in the same way, except, md would not work here. You need use mkdir to make directories on macOS and Linux. In order to verify the creation use ls command to view the folder and list of contents. One thing to note for that Linux is being careful about the case. Meaning it is case sensitive. Name created like this – mymusic, Mymusic, MYMUSIC will create three instances of folder.
Removing directories on Windows
Fantastic! We have learned to use the command line to create directories. Now how about removing the directories? Removing directory works exactly the same way. All you have to do is to make sure that you are in the right directory where you want to remove that directory from and use the right command.
To remove any directory you are to put this rmdir command. But then again, rmdir is universal and rd command works only on Windows.
Let’s practice removing directories on Windows. Let’s delete the folder you have created earlier. Make sure to navigate to the right directory and practice rd <your folder name>.This should delete the folder. Run a verification with dir and see if the folder is there or not. Note that if you have files inside the directory, rd alone will not do any good. In such a case, you have to use a switch at the end like rd <name> /s. This will delete all of the files and sub directories from this directory.
You can imagine the power of this and how cataclysmic it can be. Remember that there is no recycle bin or anything when you delete from command line like this. Once done, there is no getting back. Hence, it will always pay if you check thrice and hit the enter once.
How can you remove a directory on Linux?
On Linux, you will land in a line like – ~/<directory name>. the ‘~’ sign tells you that you are in the home directory. Navigate around if you are not in your desired directory with cd and ls. Once you detect your directory or file, run rmdir <directory name> and then run a verification with ls. The directory should be deleted now.
In case of removing everything like sub-directories, files, documents, we have another command for Linux system.
You use rm -r <directory name> to remove the sub directories as well. You will be prompted with a assurance message if you are really sure or not.
An exercise for you to practise
Let’s practise a final round with these commands line we just learned. Try the following.
- Go ahead and create a new directory inside your home directory using the md/mkdir you have just learned. Make the directory called Pokemon.
- You know you need to run the dir or ls command based on your operating system to check for verification. See If the directory is being created or not. Now go to that Pokemon directory.
- Now try creating another directory called Red and run the verification again and get into the Red directory.
- Once you done verifying, use the cd.. command to go up a level from the Red.
- Use the rd /s Pokemon to delete the whole directory including the Red directory. Confirm by Y upon assurance check.
There you go, now you are well acquainted with making, removing, navigating and exploring directories.