Windows commands remove file

Delete files from command line

Deleting files is one of the frequently done operation from Windows command prompt. This post explains how to use ‘del’ command from CMD for different use cases like deleting a single file, deleting files in bulk using wild cards etc. Before we start to look at the syntax, note that the command works only for files and can’t handle folders.

How to delete a file

Run del command with the name of the file to be deleted, you are done!

You do not see message after running the command if the file is deleted successfully. Error message is shown only when something goes wrong.

Delete files in bulk

Del command recognizes wildcard(*) and so can be used to delete files in bulk from CMD. Some examples below.
To delete all the files in current folder

To delete all the files with ‘log’ extension

Delete all files having the prefix ‘abc’

Delete all files having ‘PIC’ somewhere in the file name.

The above are the basic use cases of del command. Continue to read below for non trivial use cases.

Delete multiple files

‘Del’ command can accept multiple files as argument

Delete Read only files

We can’t delete a read-only file using simple‘del’ command. We get access denied error in this scenario.

A read-only file can be deleted by adding /F flag.

Alternatively, we can use the below command too

Is there any batch command to delete all zero byte sized files from cmd.

There is a way to remove folders from the commandline, use “RD” (remove directory), and it has a couple of silent switches, “RD /S /Q C:/Directory” will remove C:/Directory silently, I use this all the time. I think that the directory path has to be in quotations if it contains any spaces.

UAC might want to fight over deleting files, in that case, the command “takeown” to give you ownership of the file first, should get around that.

Sometimes we get an error when we try to delete a File or a folder for no reason , but of course there is a reason.We have many damage file or blocked files.Do not worry if we want to remove the error files or too long path files from our system,here I suggest a smooth way.So use “Long path tool” software and keep yourself.

Well done, I used this when del *1*.*

Will keep this in my reference book. Thanks a lot!

Is there a way to exclude filenames matching a pattern from a delete? For example, I want to delete all files except those whose names are like *xyz*

I am trying to delete csv files in DOS that have a date suffix of earlier
than 2 months ago. I need to do this dynamically, from a batch file.
Is this possible ? Many thanks.
Bethany

I want to delete a file from all the user’s profiles using cmd.
The file is on the desktop.

Name of the file-Hello My Name

I’m writing del %PUBLIC%\Desktop\Hello*My*Name.pdf,but that doesnt seem to work.
I also tried del %PUBLIC%\Desktop\*Hello* but that didnt work too.

Any help is appreciated

c. Using the for loop create 5 text files which start from letter a (ex: a1, a2, a3, a4, a5).

Читайте также:  Нормальный просмотрщик изображений для windows 10

can you help me
create 5 files like this command.
for /l %a in (1 1 5) do mkdir File%a.

del del

Удаляет один или несколько файлов. Deletes one or more files. Эта команда выполняет те же действия, что и команда Erase . This command performs the same actions as the erase command.

Команда Del также может запускаться из консоли восстановления Windows с использованием различных параметров. The del command can also run from the Windows Recovery Console, using different parameters. Дополнительные сведения см. в разделе Среда восстановления Windows (WinRE). For more information, see Windows Recovery Environment (WinRE).

Если удалить файл с диска с помощью Del , вы не сможете получить его. If you use del to delete a file from your disk, you can’t retrieve it.

Синтаксис Syntax

Параметры Parameters

Параметр Parameter Описание Description
Указывает список из одного или нескольких файлов или каталогов. Specifies a list of one or more files or directories. Для удаления нескольких файлов можно использовать подстановочные знаки. Wildcards may be used to delete multiple files. Если указан каталог, все файлы в каталоге будут удалены. If a directory is specified, all files within the directory will be deleted.
/p /p Запрашивает подтверждение перед удалением указанного файла. Prompts for confirmation before deleting the specified file.
/f /f Принудительное удаление файлов, которые доступны только для чтения. Forces deletion of read-only files.
/s /s Удаляет указанные файлы из текущего каталога и всех подкаталогов. Deletes specified files from the current directory and all subdirectories. Отображает имена файлов при их удалении. Displays the names of the files as they are being deleted.
/q /q Задает тихий режим. Specifies quiet mode. Подтверждение удаления не запрашивается. You are not prompted for delete confirmation.
/a [:] /a[:] Удаляет файлы на основе следующих атрибутов файлов: Deletes files based on the following file attributes:
  • файлы r только для чтения r Read-only files
  • h скрытые файлы h Hidden files
  • я не проиндексированные файлы содержимого i Not content indexed files
  • системные файлыs System files
  • файлы , готовые к архивации a Files ready for archiving
  • l точки повторного анализа l Reparse points
  • Используется в качестве префикса, означающего «not» Used as a prefix meaning ‘not’

. .

/? /? Отображение справки в командной строке. Displays help at the command prompt.

Комментарии Remarks

При использовании del /p команды вы увидите следующее сообщение: If you use the del /p command, you’ll see the following message:

FileName, Delete (Y/N)?

Чтобы подтвердить удаление, нажмите клавишу Y. Чтобы отменить удаление и отобразить следующее имя файла (если указана группа файлов), нажмите клавишу N. Чтобы закрыть команду Del , нажмите клавиши CTRL + C. To confirm the deletion, press Y. To cancel the deletion and to display the next file name (if you specified a group of files), press N. To stop the del command, press CTRL+C.

Если вы отключаете расширение команды, параметр /s отображает имена всех файлов, которые не были найдены, а не отображает имена удаляемых файлов. If you disable command extension, the /s parameter will display the names of any files that weren’t found ,instead of displaying the names of files that are being deleted.

Если указать определенные папки в параметре, все включаемые файлы также будут удалены. If you specify specific folders in the parameter, all of the included files will also be deleted. Например, если нужно удалить все файлы в папке \ворк , введите: For example, if you want to delete all of the files in the \work folder, type:

Можно использовать подстановочные знаки (* и ?) для удаления нескольких файлов за раз. You can use wildcards (* and ?) to delete more than one file at a time. Однако во избежание непреднамеренного удаления файлов следует использовать подстановочные знаки с осторожностью. However, to avoid deleting files unintentionally, you should use wildcards cautiously. Например, если ввести следующую команду: For example, if you type the following command:

Команда Del выводит следующее сообщение: The del command displays the following prompt:

Are you sure (Y/N)?

Чтобы удалить все файлы в текущем каталоге, нажмите клавишу Y и нажмите клавишу ВВОД. To delete all of the files in the current directory, press Y and then press ENTER. Чтобы отменить удаление, нажмите клавишу N и нажмите клавишу ВВОД. To cancel the deletion, press N and then press ENTER.

Прежде чем использовать подстановочные знаки с командой Del , используйте те же подстановочные знаки с командой dir , чтобы получить список всех файлов, которые будут удалены. Before you use wildcard characters with the del command, use the same wildcard characters with the dir command to list all the files that will be deleted.

Примеры Examples

Чтобы удалить все файлы в папке с именем Test на диске C, введите следующую команду: To delete all the files in a folder named Test on drive C, type either of the following:

Чтобы удалить все файлы с расширением bat из текущего каталога, введите: To delete all files with the .bat file name extension from the current directory, type:

Чтобы удалить все файлы только для чтения в текущем каталоге, введите: To delete all read-only files in the current directory, type:

Methods to Delete Files Using Command Prompt and Command Line

How to use command prompt and command line to delete files easily? Follow this guide to delete files using command direction on Windows and Mac.

Amy Dennis

Dec 21, 2020 • Filed to: Recover & Repair Files • Proven solutions

Regarding handling everyday tasks, the command line can turn out to be powerful as well as harmful. For instance, the rm command enables you to eliminate or delete files. The rmdir command works in the same manner for directories or folders.

However, you should be cautious because unlike transferring files from the Finder to the Trash, it is not possible to retrieve them if you utilize these commands. Still, in case you desire to make use of the Terminal’s powers, the command delete file is one command which you cannot ignore.

There are ways to include a safeguard to make sure that the only files you erase are truly the ones you want to delete.

Part 1. Advantages of Erasing Files Using the Command Line

It is not complicated to delete files using the Finder and you are always able to recover files from Trash in case you want to change your mind. So why take the trouble to delete files using command prompt and command line?

Below are several reasons to delete files Using Command Prompt and Command Line:

  • By making use of wildcards, you can erase multiple files fast and effectively.
  • You can retrieve files from the trash when you come across immovable errors.
  • You can erase files that are concealed in the Finder; these are files that might have settings for specific apps or sections of OS X, which consist of a dot (.) in front of their names, which are not displayed by Finder.
  • In case your Mac is faulty and you do not have access to the Finder anymore, you can utilize the command line for troubleshooting the issue.

Part 2. Deleting Files and Folders Using Command Prompt on Windows

Are you aware that it is possible to erase a file on Windows by making use of the Command Prompt? Below are some steps on how to go about it:

Steps

  • Begin from Start, and then proceed to All Programs, Accessories, and finally Command Prompt. You can alternately access the run dialog (WinKey and R) and key in ‘cmd’ but not with the quotes.

  • Key in ‘del’ but omit the quotes.

  • Type the file’s name and the extension. In case you are presently in the directory which contains the file, you are ready to proceed. In case you are not aware of what an extension file is, key in the file inside a kind of search box (this is determined by the computer you have and the kind of search available to you). Click on the right and find properties and it will be present on the key page. It will be the same as ‘C:/myfilename.ext.’

In case you are not in the appropriate directory, you can type ‘cd’ to the directory or key in the complete file path to be erased.

For instance, in case you want to erase ‘file.txt’ you need to key in ‘del file.txt.’ If the file is situated on the desktop, key in ‘C: /Users/username/Desktopfile.txt’ in case you are one directory on top.

  • DEL provides support for wildcards characters also, like an asterisk (*). For instance, in case you desire to delete every file on your desktop which has a .wav extension, you should type ‘del C: Users/username/Desktop/*.wav.’ Deleting

Video Tutorial on How to Recover Deleted Files on Windows 10/8/7 Easily?

Recent Videos from Recoverit

Part 3. Deleting files/folders using the command line on Mac

Erasing folders or directories varies a bit. If you attempt to operate the rm command on a folder, the message below will appear:

You can’t erase a directory utilizing the rm command. rmdir is a special command used to delete directories. Therefore, to erase a director called Archives, you need to operate the command below:

Part 4. Deleting a Directory as well as Files in it

  • The rm command provides a strong option (-R or –r) also referred to as the recursive option. After running the rm-R command on a directory, you are directing the Terminal to erase this folder, whatever files it has or sub-folders, and any folders or files inside the sub-folders, all through.
  • For instance, in case you possess a directory packed with archives that have files or directory, erasing every item one by one from the command line or Finder might consume a lengthy period. Therefore, simply operate the command as follows:

Keep in mind that this is a permanent decision. You can, however, make use of the –flag for security.

This will request you to verify the deletion of every item.

Part 5. Tips and Tricks for Using cmd delete file

In case you are unable to empty your Mac’s trash, the rm – R command is useful. A file may be locked or you might not be permitted to erase one or multiple files. This may be irritating; however, you can make use of the command line to get a simple solution.

1. Type as shown underneath in Terminal

  • rm-R
  • Type in a space
  • Open Trash in Finder and drag the items inside to Terminal Window. You will view one or multiple files with paths like /Users/.Trash/file.txt.
  • In case many files are present, you might discover that the list which comes up is all on a single lengthy line, enveloping the Terminal Window. In case you are very certain you want to delete each of these items, click on Return. The Trash will be emptied by the Terminal.

2. Send the Output of a Command to the Clipboard

You will simply send the output straightaway to the clipboard.

From a folder, open the command prompt

You might have attempted to open the command prompt and encountered a lot of cd commands trying to access a folder. The good news is that you can save lots of time by using Explorer to open a command prompt inside a folder. You just need to hold shift, click right on a folder and the context menu will present the option.

Command History

Most probably, you might have been tapping the up key to access your earlier commands; this can be tiresome if you are attempting to get a specific command. Another method you can use to see your earlier command is using the donkey command.

If you lost data on your computer, don’t worry! You still have the chance to get lost data back. To recover files from the computer, you can have tried the file recovery tool.

Читайте также:  Установка windows с iso образа с жесткого диска
Оцените статью