What is the remove command in Windows?

The remove command in Windows is used to delete one or more files and/or directories from a computer’s hard drive or another storage device. It is a built-in command line utility that has been around since the early days of DOS and is still available today in all modern versions of Windows.

What does the remove command do?

In short, the remove command deletes the specified files and/or folders from a drive. It works similarly to selecting files or folders in Windows Explorer and hitting the Delete key, except it is executed from the command line rather than through the graphical user interface.

Some key points about what the remove command does:

  • It deletes the specified files and/or folders permanently, bypassing the Recycle Bin.
  • It can delete files and folders from any drive, including external drives.
  • It works recursively on directories, deleting all files and subfolders.
  • It does not prompt for confirmation before deleting.
  • It does not differentiate between read-only or hidden files.

In essence, the remove command is a powerful and immediate way to delete files and folders from the command line, giving the user full control over which items to remove.

How to use the remove command

Using the remove command is straightforward. To delete a specific file, the basic syntax is:

remove filename

For example, to delete a file called old-reports.txt, you would type:

remove old-reports.txt

To remove a folder and all its contents recursively, the syntax is:

remove /s foldername

The /s switch tells remove to delete the folder and all its subfolders and files. For instance, to delete a folder called temp along with everything inside it, you would type:

remove /s temp

You can delete multiple files and folders at once by listing each name separated by a space. For example:

remove old-reports.txt temp/*.tmp documents/notes.doc

This would delete old-reports.txt, all .tmp files in the temp folder, and notes.doc inside the documents folder.

Useful remove command options

The remove command has a few options that provide additional capabilities:

  • /q – Quiet mode, does not prompt for confirmation before deleting files.
  • /f – Force delete of read-only files.
  • /s – Delete folder and all subfolders/files inside it recursively.
  • /i – Prompt for confirmation before deleting each file.

Here are some examples using these options:

remove /q c:\temp\*.tmp 

remove /f c:\documents\readonly.txt

remove /s c:\old-projects 

remove /i c:\users\jsmith\*.mp3

Where to use the remove command

The remove command can be executed from a few different places in Windows:

  • Command Prompt – The traditional command line interface in Windows.
  • PowerShell – Microsoft’s powerful shell and scripting tool.
  • RUN dialog box – Type remove followed by the files/folders to delete.
  • Batch files – Include remove commands inside .bat or .cmd scripts.

So in summary, the remove command can be used:

  • In interactive shells like Command Prompt or PowerShell
  • Directly in the RUN dialog (Windows + R)
  • In batch scripts and other automation scenarios

Real world examples

Here are some practical examples of how the remove command can be used:

Clean up temporary files

remove c:\temp\*.* /s /q

This would delete all files recursively from the temp folder without prompting.

Force delete read-only files

remove /f c:\documents\log.txt

Useful for deleting log files or other read-only items.

Selectively delete music files

remove /i c:\users\mary\music\*.mp3

Prompt for each .mp3 file deletion so you can choose which to keep.

Automate deletions in scripts

@echo off
rem Script to cleanup C drive each night

remove /s /q c:\temp\*.*
remove /q c:\windows\temp\*.* 

Schedule this script to run nightly and remove temp files automatically.

Key differences vs the DEL command

Windows has another command, DEL, which also deletes files and folders. What are the main differences between DEL and REMOVE?

Remove Del
Original external command from early DOS versions Introduced later as an internal command
Works on all Windows versions and MS-DOS Only available starting Windows 95/98. Not in MS-DOS.
Requires filename delimiters (C:\path\file.txt) Can use filename delimiters or basic filenames
Faster performance Slower than remove in some tests

In summary, remove is the older, original command that works across all systems. DEL was added later to Windows as an alternative with a few syntactic conveniences. But remove is generally faster and more universal.

Advanced usage

Beyond the basic options covered already, there are a couple advanced usage notes for the remove command:

  • It works with wildcards like * and ? for batches of files.
  • The path and filename are case sensitive.
  • You can use the CLI switch /x to exclude certain files from removal.
  • Errorlevel is set to 0 if no issues, 1 if one or more files did not delete.

Here are some examples of advanced remove usage:

remove C:\temp\app*.log /x app_error.log

if %errorlevel% NEQ 0 (
   echo There was a problem deleting files
)

This excludes app_error.log from the deletion, then checks errorlevel to see if all other app log files were removed properly.

Conclusion

In conclusion, the remove command is a simple yet powerful command line tool for deleting files and folders in Windows. It bypasses the Recycle Bin for immediate file removal and can be used across Command Prompt, PowerShell, batch files and other interfaces. Some key points covered:

  • Remove deletes files/folders permanently without using the Recycle Bin.
  • It works recursively on folders to delete all contents.
  • Options like /s, /q, /f provide additional control over deletions.
  • It has some benefits over the DEL command like broader OS support.
  • With wildcards and switches you can target deletions precisely.

So in scenarios where you need precise control over file deletion from the command line, remember the trusty remove command. Use it carefully, as there is no undo, but leverage its power to efficiently clean up disks and automate key file removal tasks.