Skip to main content

Command Palette

Search for a command to run...

Cheatsheet & Examples: userdel

Updated
2 min read

Delete User Account

Example Usage: userdel [options] username
What it does: Removes the user account and all associated files, including home directory, shell, and password entries.
Command-line Arguments Explained:

  • --remove: Removes the home directory and other associated files (e.g., .bashrc, .bash_profile).
  • --keep: Preserves the home directory and associated files (e.g., .bashrc, .bash_profile).
  • --force: Forces deletion even if the user is locked (e.g., sudo userdel --force username).

Remove Home Directory

Example Usage: userdel --remove username
What it does: Deletes the user's home directory and all associated files (e.g., .bashrc, .bash_profile).
Command-line Arguments Explained:

  • --remove: Removes the home directory and related files.

Delete User from System

Example Usage: userdel --remove --force username
What it does: Removes the user from the system (e.g., /etc/passwd, /etc/group) and all associated files.
Command-line Arguments Explained:

  • --remove: Removes the home directory and related files.
  • --force: Forces deletion even if the user is locked.

Keep Home Directory

Example Usage: userdel --keep username
What it does: Deletes the user account but preserves their home directory and associated files.
Command-line Arguments Explained:

  • --keep: Prevents removal of the home directory and associated files.

Delete User with Recursive Options

Example Usage: userdel -r username
What it does: Recursively deletes the user's home directory and all associated files.
Command-line Arguments Explained:

  • -r: Recursively deletes the home directory and related files.

More from this blog

Hong's Tech Blog

110 posts

The blog is older than you know. I prefer counting from the emergence of one integral anomaly to the emergence of the next, in which case this is the forth version.