Issue removing File or Folder on Lawrence

Summary

How to diagnose and fix an error when trying to remove a file or folder.

Body

Issue/Question

I tried removing a file or folder and it doesn't work

Using rmdir on a folder fails

Removing a file or folder gives me an error message

Environment

  • Lawrence
  • HPC
  • linux

Cause

rm: cannot remove ‘folder-without-write/file’: Permission denied

rmdir: failed to remove ‘folder-with-hidden/’: Directory not empty

Resolution

  1. Use long list to check the permissions
    1. Pass the long, -l, flag (and others if you wish) to ls to make it list the permissions
      $ ls -lFah folder-without-write/
      total 1.5K
      dr-xr-sr-x 2 bill.conn@usd.local jennewein_lab@usd.local 3 Jun 16 10:41 ./
      drwxr-sr-x 4 bill.conn@usd.local jennewein_lab@usd.local 4 Jun 16 10:41 ../
      -rw-r--r-- 1 bill.conn@usd.local jennewein_lab@usd.local 0 Jun 16 10:41 file
    2. Use the chmod command to attempt to add write permissions to the folder
      Note: if you get the error 'Operation not permitted', you need to ask the owner (or the Service Desk) to change the file
      chmod +w folder-without-write/
    3. You may now remove the file and folder
      rm -rf folder-without-write/
  2. Use long list to check for hidden files
    1. Pass the long, -l, flag (and others if you wish) to ls to make it list the permissions
      Note: Files and folders that start with a period ',' are normally 'hidden' during a normal list command
      $ ls -lFah folder-with-hidden/
      total 1.5K
      drwxr-sr-x 3 bill.conn@usd.local jennewein_lab@usd.local 3 Jun 16 10:41 ./
      drwxr-sr-x 3 bill.conn@usd.local jennewein_lab@usd.local 3 Jun 16 10:50 ../
      drwxr-sr-x 2 bill.conn@usd.local jennewein_lab@usd.local 2 Jun 16 10:41 .git/
    2. Remove the hidden files or hidden directories before removing the original directory
      Note: You may need to remove several things before a directory becomes empty
      rm -rf folder-with-hidden/.git
    3. Remove the original directory
      rmdir folder-with-hidden
  3. Please contact the Service Desk with the following information: 
    1. Machine with the issue
    2. Your username on the machine
    3. The file or folder you are having a problem with

ITS STAFF ONLY

  1. Log in to the machine with the issue
  2. Become a superuser
    sudo su -
  3. Navigate to the problem files or folders
  4. Since you are root, you can force permissions changes with chmod
  5. Remove the files for the user

Details

Details

Article ID: 7243
Created
Thu 6/16/22 12:08 PM
Modified
Tue 12/19/23 10:13 AM
KCS Article Status
WIP: Only Problem & some Environment captured
Not Validated: Complete & Resolution captured, confidence lacks in structure, content, no feedback
Validated: Complete & reusable, used by licensed KCS user, confidence in resolution & std. compliance
Validated