Ubuntu rm Command: The Correct Way to Delete Files/Directories
This article introduces the correct usage of the `rm` command in the Ubuntu system to avoid accidentally deleting important data. `rm` is a core tool for deleting files/directories; it deletes directly by default without sending files to the trash, making recovery difficult after deletion. **Basic Usage**: Delete a single file with `rm filename`; to delete a directory, use the `-r` (recursive) option: `rm -r directoryname`. Common options include: `-i` (interactive confirmation, prompting before deletion to prevent accidental removal), `-f` (force deletion, ignoring errors, use with caution), and `-v` (verbose, showing deletion progress). **Safety Notes**: Avoid using `rm *` or `rm -rf *` (which delete all contents of the current directory). Do not delete system-critical directories (e.g., `/etc`). Before deleting a directory, use `ls` to confirm its structure; for empty directories, `rmdir` is safer. If accidentally deleted, attempt recovery via the graphical trash bin (files deleted via terminal are not sent there) or tools like `extundelete` (requires installation, and avoid writing data after deletion). **Summary**: Always confirm the target before deletion, prioritize using `-i`, avoid dangerous commands, and ensure data security.
Read More