Deleting files from the command line. Delete a file or folder that cannot be deleted. Using cmd when booting Windows

To achieve the goal, open cmd with administrator privileges. Enter RD /? and quickly familiarize yourself with the features and parameters of the command. Here you will see only 2 parameters:

  1. /s - when using this prefix, the folder will be deleted, as well as all its nested elements. If your directory is not empty, and you have not specified this parameter, then nothing will work for you.
  2. /Q - used when deleting without confirmation.

In general, the design looks like this:

RD or RMDIR /s/q “full folder path”

Note: when applying the design, the directory and its contents will be completely deleted from the computer and you will not find it in the trash. To be safe, make a backup copy of the folder.

Deleting a folder with or without confirmation

I created a directory on my computer called “cmd” and copied several objects into it. Then I entered the following command into the command line:

RD /s “c:cmd”

Then I pressed Enter and the Y key because cmd prompted me to confirm the deletion.

I checked the C drive and found no directory. Next, I created a folder named “delete” and also copied 5 files, but when entering the command, I removed the /s prefix. It turned out like this:

RMDIR “c:delete”

After pressing Enter, the deletion did not occur, and a message was displayed on the command line that the folder was not empty. Conclusion, without the /s parameter, you can only delete an empty folder, therefore, using it without this prefix is ​​practically useless.

If you are too lazy to enter the confirmation letter (Y or N), then the following construction is for you. The /q prefix was mentioned above; it is what removes the annoying typing of letters (see the screenshot for proof).

That's all, with these actions you can easily delete folder from command line, using a not at all complicated syntax. With the knowledge of cmd, your any ideas will turn into reality, with which you will even turn off the computer from the command line and do much more.

On Windows of any version (XP, 7, 8, 10), a problem often arises when a file or folder with a locked file is not deleted. A message pops up that the file is occupied by another process or is open in some program, or you need to ask permission from someone.

There are several ways to delete a file that is not deleted, renamed, or moved. This is done without additional software, using the free Unlocker program, from a bootable flash drive or LiveCD, or the DeadLock program.

When deleting locked files and folders, be careful; it may be part of the operating system. Without them, Windows will stop loading.

Why isn't it deleted?

  • The file is open in another program. Terminate any unnecessary processes and try again. Sometimes restarting the computer helps.
  • Insufficient permissions to delete. For example, this file was created by another user or the computer administrator removed the deletion rights.

Exceptions

The methods described in the article will not always help:

  • pagefile.sys and swapfile.sys - to remove, disable the swap file.
  • hiberfil.sys - deleted when hibernation mode is disabled.
  • If an access denied message appears. You need to become the owner of the file or folder. The easiest way to do this is with the TakeOwnershipPro program.
  • If a message appears asking for permission from TrustedInstaller. This is protection against the removal of system components.
  • Windows.old - a folder with an old version of the operating system. It is deleted through the “Properties” of the local drive C. On the General tab there is a “Cleanup” button. A window will open in which select “Clean up system files.” Once the analysis is complete, the “Previous Windows installations” item will appear in the list in this window. Check this box and click OK.

Deleting the file manually

Message: The file is already in use, please close and try again.

If a file doesn't want to be deleted, the error message usually tells you which process has locked it. This could be explorer.exe or any program that has it open. If you close this program, the file will be deleted.

If the file is occupied by the explorer.exe process

  • Before completing the task, open Command Prompt as an administrator. It is located in “Start - All Programs - Accessories”. Right-click on Command Prompt and select Run as Administrator.
  • Remove the explorer.exe task in the task manager and write del full_path/name.extension in the command line.
  • The path does not have to be entered manually. Right-click on the desired file while holding Shift - Copy as path, and paste it into the command line through the right-click context menu.
  • Now restart explorer.exe. In the task manager, click "File - New task - explorer.exe".

Use a bootable USB flash drive or disk

If you have a bootable USB flash drive or LiveCD, or a Windows recovery disk, run them and calmly delete the file using the standard method or through the command line.


Be careful, sometimes when you log in through the boot disk, the local drives have different letters. To see a list of folders on drive C, type dir c: on the command line.

If you use a bootable USB flash drive or Windows installation disk, the console opens at any time after the language selection stage, using the key combination Shift + F10.

You can also select the system recovery mode, which will be offered before starting the OS installation.

Command for deleting via the console: del full_path_to_the_file.

Using DeadLock

The free DeadLock program allows you to delete a locked file and change the owner. Download from the official website: https://codedead.com/?page_id=822.

Using the File menu, add the problematic file to the program. Right-click on it in the list - unlock it (Unlock) and delete it (Remove).


Using Unlocker

The simplest and most popular program, but now even on the official website a warning about unwanted software is displayed. Along with the program there may be some other virus or advertising, so use at your own peril and risk. Try the methods above first. Website: http://www.emptyloop.com/unlocker/.

After installation, a new item will appear in the context menu, which is called Unlocker. After clicking the button, the program will complete the interfering process and the file will be unlocked.


If you want to delete a folder, first delete all its contents.

Via command line

There was such a case that the file did not want to be deleted in any way. The size was 0 bytes, the name was written in Russian letters (not supported in older versions of MS-DOS), there was a Read-only attribute and an A attribute (only reading and adding content). The command line helped.


That's all for now. If you know simpler and more effective ways, write them in the comments. Which method helped you?

This lesson will show how to delete a file via command line in Windows(7, 8, XP, Vista). The DEL or ERASE commands will help with this, which are used when you cannot delete a file in the usual way. For , DEL and ERASE are not suitable.

Naturally, for starters. With this action you will get the best results.

If you use this lesson, then the file will be deleted immediately without being sent to the trash.

In cmd type DEL /? and press Enter to preview the command options. If you did it correctly, you will see an explanation (screenshot below).

Using cmd when booting Windows

Sometimes it becomes necessary to go into cmd before starting the system. If the malware is blocking successful login or the boot sector of the system is damaged, then the following steps will help you:

  1. Open Command Prompt when Windows boots
  2. In cmd enter DiskPart and press Enter
  3. Next you will need to write list volume and press enter again (see screenshot below). This will allow you to see the drive letter where you want to delete the file.
  4. After receiving the information, type exit and click Enter.

Now feel free to enter the options for the removal commands, which are described below.

With these steps you will delete any file on your computer using the command line.

Deleting a specific file

To delete a specific element, you need to know its name and extension. Otherwise, the likelihood of deleting the wrong thing increases!

In cmd, enter the following command and press enter:

DEL /F /S /Q /A "Full path of the element with extension"

For example, if I want to delete with the name “delete” and with the extension (.bat), located on drive C in the “trash” folder, I need to enter the command:

DEL /F /S /Q /A "C:\trash\delete.bat"

Delete all files with and without confirmation from the command line

In this case, you must confirm or deny the actions with letters (Y - yes / N - no) to delete all files in the main directory and subfolders.

To confirm, use this syntax:

DEL /F /S /Q /A "Full path to the folder\*"

If I need to delete all the files on drive D from the Trash folder, which contains many other directories and files, I would use the command:

DEL /F /S /Q /A "D:\add to cart\*"

In order to delete file from command line with confirmation, /P is added to the parameters and looks like this:

DEL /P /F /S /A "D:\experiment\*"

It is possible to delete all files with a given extension, then the command will take the form:

DEL /F /S /Q /A "Full path to the folder\*.extension"

It is especially useful when there are a lot of unnecessary elements of the same type that are not an option to sort through manually, but can simply be deleted in batches from cmd.

With the right approach, you can delete file via command line, in a few seconds. I hope the recommendations were helpful. If you are interested in cmd, I advise you to read the material, which will be no less interesting.

The Command Line (abbreviated CMD) is a special program that allows you to perform complex operations in Windows. Ordinary users do not use it, since the need for most functions is realized through the familiar window interface. But when bigger problems arise, command line capabilities can come in handy. This program is suitable for forcibly deleting folders, files and working with directories and local drives.

The essence of the work is simple - a command or a series of sequential commands (algorithm) is entered, and Windows executes them. Moreover, many processes go through CMD much faster than in the familiar graphical interface. Deleting a folder or program on the command line generally takes a couple of clicks.

We'll be using CMD a lot in this tutorial, so let's look at launching it first. To open the program, use one of the methods below.

Method 1

In the Start search, type “command prompt” or “cmd” (without quotes). The system will find the utility, all you have to do is open it.

If you want to find out in more detail, and also consider 5 proven methods, you can read an article about this on our portal.

Method 2


Note! CMD can only be launched by the computer administrator. Since the command line is capable of making serious changes to the operation of the system, Windows OS does not trust other users (with the “Guest” and “Regular” rights categories) to run it.

How to delete a folder via command line

Step 1. Launch CMD.

Step 2. To delete, use the “rmdir” (rd) command - you can only delete a Windows file system directory using it. So, enter the text “RD /?”. The utility will introduce you to the functions for working with folders.

Step 3. We created a folder with unnecessary files to demonstrate how the utility works. The folder is located on the desktop. When you delete a folder, you must enter the following command: “RD /s”, then put a space and enter the path to the folder itself (its address on the computer).

How to find the folder path

How to find out the path to a folder? Doing this manually takes too long, especially if you want to delete several directories. Let's take a look at our desktop. It is located in the “Users” folder on the drive where you have Windows installed.

  1. In our case, the system is located on the local drive C. We go into it.

  2. Then to the users directory.

  3. And then we select a specific user.

  4. There we see the “Desktop” - open it.

  5. At the end of the path we should come to the folder that needs to be deleted.

  6. Now click on the address bar of the explorer (see screenshot) and copy the address (key combination “Ctrl + C”).

Important! The method is applicable to any options: deleting a folder with or without confirmation - there is no difference.

Step 4. Paste the folder address into CMD. To do this, right-click next to the entered command on "Step 3"(unfortunately, the keyboard shortcut “Ctrl+V” in the command line does not work). Press "Enter".

Step 5. The utility will ask if you really need to delete the directory. If you are sure that yes, press the English key “Y”, and then “Enter”.

Step 6. Ready! The folder has been deleted using the command line. Just in case, let's check that the directory is missing.

Note! The folder is completely deleted from the hard drive, not being placed in the Recycle Bin! Be careful when using this tool - you may inadvertently delete important data from your computer permanently. Only the main user of the computer can delete a folder with administrator rights.

How to delete a file via command line

The principle of uninstalling a file is not much different from deleting a folder. We will also need to find out the file address and write it in CMD. The only difference is the team itself.

Step 1. Open CMD.

Step 2. Enter the following command: “DEL /F /S /Q /A”. Then put a space and insert the path to the file.

How to find out the path to a file?


Step 3. Paste the copied text into CMD (it must be in quotes).

Step 4. Now copy the file name from the field (along with the extension - see screenshot) and paste it into CMD.

Step 5. Close the quotes and press Enter.

Done – the file is deleted forever.

How to remove a program via the command line in Windows 7

It happens that the program is not uninstalled by the standard Windows application (from the control panel). To permanently remove software, clearing not only its files, but also data in the registry, the command line is useful.

Step 1. Launch CMD.

Step 2. We drive in “wmic”.

Step 3. Now you need to find out the names of a specific application in Windows so as not to make a mistake and delete useful software. To do this, type in “product get name” (literally, “get the name of the product”).

Step 4. Uninstall the program on the command line. All that remains is to enter the text “product where name=”program name” call uninstall”. The text in quotes is the name of the software of their list provided by the command line.

Step 5. Ready! You can check whether the software has been removed or not by going to the “Uninstall a program” application from the “Control Panel”. If the software is not in the list, it means the operation was completed successfully.

How to change to another drive on the command line

To navigate through directories and local drives, a familiar navigation tool is used - Explorer. However, using CMD you can navigate to directories located on the hard drive.

This instruction answers the question “how to go to another folder on the command line”; there is no fundamental difference between the directory and the local partitions of the hard drive.

Step 1. Launch CMD.

Step 2. Type in the command “cd /d “d:””. In quotes is the address of our local disk or directory.

In the field, enter the command “cd /d “d:””, in quotes - the address of our local disk or directory, press “Enter”

How to make a bat file

Bat file is an algorithm that can be written by the user in the CMD utility. Regarding our topic, it is possible to delete a folder using the bat file command, entering a sequence of steps. Instructions for creating a BAT file:

Step 1. Create a simple document in Notepad.

Step 2. You can put a few spaces or some simple text. This is done so that the file is saved by the program (the main thing is that it is not empty). Now this does not play a big role, since we use the Notepad++ utility to create the BAT file.

Step 3. Download Notepad. We install.

Step 4. Let's open our document.

Step 5. In the menu, select “Encodings” -> “Cyrillic” -> “OEM 866”.

Step 6. Go to the “File” tab and select “Save As”. We confirm the action and replace the old file with a new one.

Step 7 Now you can delete the old contents of the file and enter the desired algorithm.

Step 8 Save the document and change the extension from txt to bat.

Video - How to delete a folder using the command line (cmd) in Windows

As Zhora Kornev from Terminator Three said, “Hacker Magazine is a must read,” and it’s true that it’s probably difficult to find a young user these days who lives on the Internet and has never wondered about hacking something, or at worst, deleting a system file on the command line of your neighbor. Perhaps the most desirable prey for RuNet is the social network Vkontakte.

Yandex alone contains 61 thousand sites with a pure entry “how to hack VKontakte”! Well, it's just hack territory! But... there are few skilled people to create high-quality websites, and even fewer skilled people to provide worthwhile information, not to mention the fact that most hack manuals are banal copy-paste or rewriting. Causing harm to someone else's system is not so easy, but ruining your own hardware is a trifle. And so, let’s get started, since I’m running out of time (special forces in helmets are grazing under the doors), and the user should not take Murzikami, I decided to continue writing posts in the “Working with the command line” section, and in this I will make a brief overview of the del command line utility , which allows you to delete one or a group of files and even programs. I advise you to read an article about the topic.

The first thought that pops into the mind of any dirty trickster is to fucking delete everything. At one time, while sitting in a local area during an informatics lesson, I hacked my neighbor’s entire Windows, he was so upset, he thought he had opened the notepad incorrectly. Watching Hollywood films about evil hackers, you can usually see how a certain Hrundel sticks into a black screen and enters incomprehensible words from the keyboard, and he has full access to the FBI database. Well, as they say, we are worse. And so, we create a smart look, tell our friends to close the curtains, and launch... the CMD command line (Black screen, no matter how). Perhaps it is nostalgia and Western films that give the illusion that you can kill an enemy computer using the command shell. But...this is just the tip of the iceberg.

And so, let’s say we, having read secret waste paper, decided to create a virus, but not wanting to study assembly programming at school leaves only one choice - creating a bat virus. The essence of the virus will be simple and banal - delete the Windows folder and all its files using the command line. Well, let's try...

DEL command line utility

This command contains the following set of parameters:

DEL [drive:] [path]filename]

[drive:] [path]filename - everything is clear here, enters the path to the object that we want to delete, for example a record

Del D:\data.txt- will delete the text file D:data.txt

Team del d:\temp is designed to delete all data stored in the temp directory, but if it contains a subfolder with files, they will not be touched. Additional attributes allow you to control the deletion process:

/P– this attribute will ask for consent to destroy each object stored in the directory

/F– deletes an object, even with the Read-Only attribute

/S– this option will allow you to delete all files via the command line, including data in subdirectories

/Q– disable the display of a request to confirm destruction.

/A[: attributes] – this attribute is good because it allows you to kill only certain objects, for example, those with the following attributes:

R- "Only for reading",

N- "Hidden"

S- "System"

A- "Archival".

The second additional option is to specify a mask of objects to be killed using wildcards: ? (any one character) and * (any number of characters). That is, the entry:

DEL D:\Temp\data*.txt /s/f– will delete through the command line all text files starting with data.

Well, this seems clear, but how to use such meager knowledge for the benefit of the fatherland, so to speak? On one site I came across a rather heated discussion about the creation of batch files; young people vigorously gave examples of their “mega” viruses. And so, using the above command, let's try to write a virus that will supposedly delete the system folder, change the volume label, mock extensions and reboot the computer:

@echo off
label LAMER
assoc.exe=.gif
del %windir%*.* /q/f /s
shutdown -r –f

The first line disables the output of text and commands, the second changes the disk label to Lamer. Team assoc.exe=.gif causes the system to consider all executable files to be images. Next comes deleting files in the system folder via the command line. Well, and finally - a forced reboot without confirmation. There are thousands of such examples, and this one is the most lame, and for them to work, you need to take into account a lot of nuances:

  • Common dirty tricks (such as turning off the mouse or keyboard) are immediately stopped by the antivirus program.
  • Registering the path to the batch file in startup (as a rule, the registry is suitable for this purpose) will not work if the user's rights are limited.
  • Account type and operating system. You can go into more detail here. Seven initially will not allow the execution of a number of command line utilities - only on condition that the launch is made on behalf of the BUILT-IN ADMINISTRATOR ACCOUNT. If you are the proud owner of “simple” XP, then creating a limited account and then setting up access rights to certain resources will allow you to avoid a number of unpleasant situations: money was stolen from webMoney, a virus is always crawling onto a flash drive, someone deleted a file via the command line passwords and much more.

Actually, this is one of the factors in using a script server to solve administrative and other tasks.

What made me laugh the most was when one of the “gifted” creators of the bat virus complained that his creation did not work in Vista and loudly declared that it was screwed.