🗑️

Guide to Deleting Files and Directories

Jun 2, 2025

Lecture Notes: Removing Files and Directories

Removing Files and Directories in Windows GUI

  • Removing Files/Folders:
    • Right-click on the file/folder and select "Delete."
    • Deleted files go to the Recycle Bin.
    • Files in the Recycle Bin can be restored by right-clicking and selecting "Restore."
    • Once the Recycle Bin is emptied, files cannot be retrieved.

Removing Files and Directories in PowerShell

  • Command: rm or remove
  • Caution:
    • Removed files do not go to the Recycle Bin, they are permanently deleted.

Example Commands:

  1. Remove a File:

    • Remove a file like text1.txt in the home directory using rm text1.txt.
    • File is permanently deleted.
  2. Permission Restrictions:

    • Attempting to remove a file like an "important system file" may result in an error due to lack of permissions.
    • Files marked as system files or those you don't have permission for cannot be removed without proper access.
    • Files can be removed using -force if you have the necessary permissions, which overrides the safety checks.
  3. Permissions and Administration:

    • If lacking permissions (non-admin or file owned by someone else), admin rights are required.

Removing Directories:

  • Removing a Directory:
    • Use remove command but may prompt for confirmation if using without -recurse.
    • -recurse parameter confirms awareness of removing all contents within the directory.

Important Considerations

  • Safety Measures:

    • Only authorized users can use the removal commands.
    • Ensure awareness of file permissions and potential impacts of removing files.
  • Best Practices:

    • Always double-check before using removal commands to avoid unintended data loss.