rm—removes files from directories

rm [–f] [–i] filename…
rm –r [–f] [–i] dirname…[filename…]

rm removes the entries for one or more files from a directory if the file has write permission. If filename is a symbolic link, the link will be removed, but the file or directory to which it refers will not be deleted. User do not need write permission on a symbolic link to remove it, provided they have write permissions in the directory.

Example A.48.
1  rm file1 file2
2  rm -i *
3  rm -rf dir
				

Explanation

  1. Removes file1 and file2 from the directory.

  2. Removes all files in the present working directory, but asks first if it is okay.

  3. Recursively removes all files and directories below dir and ignores error messages.

Get Linux Shells by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.