Tuesday, 29 September 2026

Linux Operating System _ commands _ 1

 

Source : Internet


The $ rm -rf command in Linux is a powerful file and directory removal command that deletes files and directories recursively and forcefully, without prompting for confirmation.

Example:

# Remove a directory named 'project' and all its contents without confirmation
rm -rf project/

This will permanently delete the project folder along with all subfolders and files inside it.

Breakdown of Options:

  • rm – The base command to remove files.

  • -r / --recursive – Removes directories and their contents recursively.

  • -f / --force – Ignores nonexistent files and never prompts for confirmation.

Usage Examples:

  • Delete a single directory recursively and forcefully

rm -rf /path/to/directory

Deletes the directory and everything inside it without asking.

  • Delete multiple directories/files

rm -rf dir1 dir2 file.txt

Removes all listed items in one go.

  • Delete hidden files/folders

rm -rf /path/to/dir/.*

Removes hidden files/directories inside a folder.

Important Considerations:

  • Irreversible Deletion: Unlike GUI trash bins, rm -rf does not move files to a recycle bin — data is gone permanently.

  • Root Directory Protection: By default, GNU rm prevents removing /. Using --no-preserve-root overrides this, but it is extremely dangerous.

  • Safe Practices: Double-check paths before executing. Use ls first to verify contents. Consider using -i for interactive deletion if unsure.

⚠️ Warning: Running rm -rf / or similar on critical paths can wipe your entire system. Always ensure you are targeting the correct directory or file before execution.

No comments:

Post a Comment