Which of the following commands will delete a directory and all of the files contained within it?

Skip to main content

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

del

  • Article
  • 06/22/2022
  • 2 minutes to read

In this article

Deletes one or more files. This command performs the same actions as the erase command.

The del command can also run from the Windows Recovery Console, using different parameters. For more information, see Windows Recovery Environment (WinRE).

Warning

If you use del to delete a file from your disk, you can't retrieve it.

Syntax

del [/p] [/f] [/s] [/q] [/a[:]<attributes>] <names>
erase [/p] [/f] [/s] [/q] [/a[:]<attributes>] <names>

Parameters

ParameterDescription
<names> 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 Prompts for confirmation before deleting the specified file.
/f Forces deletion of read-only files.
/s Deletes specified files from the current directory and all subdirectories. Displays the names of the files as they are being deleted.
/q Specifies quiet mode. You are not prompted for delete confirmation.
/a[:]<attributes> Deletes files based on the following file attributes:
  • r Read-only files
  • h Hidden files
  • i Not content indexed files
  • s System files
  • a Files ready for archiving
  • l Reparse points
  • - Used as a prefix meaning 'not'
.
/? Displays help at the command prompt.

Remarks

  • If you use the del /p command, you'll see the following message:

    FileName, Delete (Y/N)?

    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.

  • 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 <names> 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:

    del \work
    
  • 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)?

    To delete all of the files in the current directory, press Y and then press ENTER. To cancel the deletion, press N and then press ENTER.

    Note

    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

To delete all the files in a folder named Test on drive C, type either of the following:

del c:\test
del c:\test\*.*

To delete all the files in a folder where the folder has a space in its name, the full path needs to be wrapped in double quotes. Type either of the following:

del "c:\test folder\"
del "c:\test folder\*.*"

To delete all files with the .bat file name extension from the current directory, type:

del *.bat

To delete all read-only files in the current directory, type:

del /a:r *.*

Additional References

  • Command-Line Syntax Key

  • Windows Recovery Environment (WinRE)

Feedback

Submit and view feedback for

Jamie has created a hard link to another file within the same directory. Which of the following commands can he use to verify that the hard link was created correctly? (Choose all that apply)

Which of the following commands can be used to update the last modified time stamp on a file, or if the file specified does not exist will create the file?

Which of the following commands will delete a directory and all of the files contained within it? (Choose all that apply)

In order to set all of the special permissions on a certain file or directory, which command should be used on a file named filename?

Jean installs a distribution of Linux on a workstation and attempts to run the locate command to find a certain file. Instead of returning the results she expected, an error message is displayed that it cannot find the mlocate.db file in its default location. Which of the following commands should Jean run in an attempt to resolve this problem?

Which of the following commands will return one result of where the grep binary executable is located? (Choose two)

Which of the following permissions would show for a symbolic link when displayed with the ls -l command?

/var/lib/mlocate/mlocate.db

What is the complete path and filename for the database that is used by the locate and mlocate commands?

Which of the following commands can be used to recursively search a directory tree for files that meet a certain criterion without using a database or premise index of files?

The file system hierarchy standard specified what directory as the roots users home directory?

Which of the following commands will delete a directory and all the files contained within it?

The -r option for the rm command will recursively delete directories as well as any subdirectories contained within them, as well as files contained in any of those directories or subdirectories.

Which of the following commands will help find you all the files in current directory?

The ls command is used to list files or directories in Linux and other Unix-based operating systems. Just like you navigate in your File explorer or Finder with a GUI, the ls command allows you to list all files or directories in the current directory by default, and further interact with them via the command line.

Which of the following options will change the ownership of files and directories recursively within a directory choose all that apply quizlet?

Which of the following options will change the ownership of files and directories recursively within a directory? (Choose all that apply.) The -R option will recursively change ownership on files and subdirectories within a directory.

Which of the following commands lets you move to another directory choose only one answer?

The cd (“change directory”) command is used to change the current working directory in Linux and other Unix-like operating systems. It is one of the most basic and frequently used commands when working on the Linux terminal.