Skip to content

Help us create more tutorials! Make a donation using the Donate button or become a member using the button below to hide this banner and track your progress.

Delete a file – Terminal

Summary

To delete a file using your terminal, enter the following command:

rm file-name

Warning

Unlike when you delete a file with Finder or File Explorer, using rm DOES NOT move files to the Trash or Recycle Bin where they can be restored later if necessary. Instead, the rm command PERMANENTLY deletes the file and it can’t be recovered later. Use the rm command with caution.

Details

Example

If you had a file named index.html that you wanted to delete, you would enter the following command in your terminal:

rm index.html

Delete multiple files

To delete multiple files, pass the file names as arguments to the rm command, like this:

rm index.html about.html

Options

You can use the -i flag to add a prompt asking if you want to remove a file. For example, let’s say you want to remove index.html. With the -i flag, you’ll see the following prompt:

remove index.html?

You can type the letter y or n and press Enter to either remove the file or not.

You can also use the -v flag to get verbose output. For example, if you use the flag and remove the file in the example above, you would see the following output:

index.html

You can combine the 2 flags, like this:

rm -iv index.html

Exercises

Try the following command in your project folder:

rm style.css

References

Command Line Primer on the Apple Developer Archive (see the section called Frequently Used Commands)

Back to: Terminal Course > Terminal Advanced Commands