How To Create, Open and Delete A File/Directory In Command Prompt

Using command line is beneficial in every way, doesn’t matter if talking about the system smoothness or about the user experience. For user, if you know the right command then it’s a quick process and you don’t have to handle the GUI (Graphical User Interface) and don’t need to go through various pages to perform a specific task, if you are a programmer then you probably with the number of pages or steps you have to go through to just set environment variable for running a java program. But if you know the right command then it’s just a few second process, all you need is a good typing speed sometimes.

No, doubt that command line makes the process much shorter than it is in GUI. Another best part of using command line is that it takes less RAM and you,ll be far away from system freezing situations. Due to low ram, sometimes when you run too many processes at the same time then you can get into such situation.

If you just started with Cmd and not much familiar with it then you probably don’t even know some basic commands to create a file, open or delete them or even the similar directory operations.

Since this post is specifically for how to create, open or delete a file/Directory in command prompt then here is how you can perform these tasks in CMD:

For File:

How To Create A File In Command Prompt:

In order to create a file in command prompt simply type this following command:      create a file in command prompt

Start notepad filename

Or

Start notepad example.txt

Once you hit the enter button it will open notepad and ask your confirmation to save file, so press OK again.

Open Any type of File Using Command Prompt

In order to open a file in command prompt, which can be any kind of file you need to follow these instructions:;

Before opening the file you need to know the path or the location of that file. if the file names as example.txt is placed under Users directory then the command will be:

open any file in command prompt

Cd /

Users/example.txt

Run the above two commands, in which the first command will take you to the home/root area of that drive then on the second command simply just specify the location of that file.

Delete A File in Command Prompt

For deleting any file, run command:                                                                                                                                                 delete file in command prompt

cd /

del Users/example.txt

Similarly, as the command to open a file in cmd, this command to delete a file in cmd is almost the same. The first command will take you to the root of that drive and on the second command, putting the keyword del will delete the specific file which address you will put right after it.

 

For Directory

Create A New Directory in Command Prompt

To create a New Directory in the current location use the command:

mkdir Directory Name

Or 

mkdir Testing

If you want to make a new directory in  another or any specific location then firstly specify the location or change the location to that location or that directory under which you want to make the new directory, for example:

cd c:\users\files

mkdir Testing

In above example, the first command will change the current location to the c>>users>>files and then second command will make a new directory named Testing unders Files directory/Folder.

Open a Directory in Command Prompt

Type the command:

dir htdocs\img

The above command will show all the files information under htdocs>>img folder. So to open a directory and show its content in command prompt all you need to do is add dir command to first then specify the location of that directory which you wanted to open.

Delete a Directory in Command Prompt

To delete a directory in command prompt simply just type the following command:

rmdir directory name

Or

rmdir testing

The above command will delete the directory named as testing. Also, we are assuming that the directory is present in the current location so we havn’t specify the location. If you want to delete a directory of another location then specify the location first.