Delete files and folders.
Syntax rm [options] file ... unlink file Options -d Attempt to remove folders. -f Attempt to remove the files without prompting for confirmation, regardless of the file's permissions. If the file does not exist, do not display a diagnostic message or modify the exit status to reflect an error. -i Request confirmation before attempting to remove each file. -P Overwrite regular files before deleting them. Files are overwritten three times, first with the byte pattern 0xff, then 0x00, and then 0xff again, before they are deleted. -R Remove the entire file hierarchy rooted in each file argument. (implies the -d Delete folders). If the -i option is specified, the user is prompted for confirmation before each directory's contents are processed (as well as before the attempt is made to remove the directory). If the user does not respond affirmatively, the file hierarchy rooted in that directory is skipped. -r Equivalent to -R. -v Be verbose when deleting files, showing them as they are removed. -W Attempt to undelete the named files. Currently, this option can only be used to recover files covered by whiteouts. unlink Unlink a file, only one argument, which must not be a directory can be supplied. Calls the unlink() function which removes the link named by path from its directory and decrements the link count of the file which was referenced by the link.
The rm utility removes symbolic links, not the files referenced by the links.
If you are expanding a variable always put quotes around the filename in case it contains spaces:
To delete a file with non-printable characters in the name: 'bad file name' Use the shell wildcard "?" for each character
If an error occurs, rm exits with a value >0.
Delete all .jpg files in the current folder:
$ rm *.jpg
Delete the folder named "temp", and all its contents:
$ rm -R temp
Delete a protected folder:
$ sudo rm -r NAME_OF_FOLDER_TO_DELETE
you will be prompted for your password. hit return.
“The erase function in Disk Utility can erase an entire partition”
Related macOS commands:
cp - Copy files
find - Find and optionally Delete files
ls - List information about files
rmdir - Remove empty folder
srm - Securely remove files or directories
HT1526 - You can't empty the Trash or move a file to the Trash