How do I remove one selected Linux file or an empty directory safely?
Use an explicit path and an interactive removal for a single file. Use rmdir for an empty directory so the command refuses to remove a directory containing data. A shell removal normally bypasses a desktop recycle bin and should be treated as a real data change.
Before you start
- An authorised SSH session on the Linux server.
Instructions
1. Identify the exact object
Inspect the file immediately before removal. Confirm its owner, purpose and spelling; a similar filename can belong to a different task or application.
ls -l -- "$HOME/server-notes/temporary-note.txt"Use the full path in both inspection and removal, and avoid wildcards for a one-file task.
2. Run only the relevant operation
For the file example, read the prompt and confirm only the intended path. The directory example is a separate operation and succeeds only if that directory is empty.
rm -i -- "$HOME/server-notes/temporary-note.txt"-i asks before unlinking this file. There is no recursive or force option.
rmdir -- "$HOME/server-notes/empty-folder"rmdir refuses a nonempty directory instead of expanding the removal scope.
Check the result
- The intended path is absent and neighbouring files remain present. A refusal is information to investigate, not a reason to add force options.
Troubleshooting
- Disk space does not immediately increase
- Another process may still hold the deleted file open. Inspect the owning process before planning a controlled reopen or restart.
Official references
Use the documentation for your installed version when a flag, service name or platform feature differs.
