Why can't I delete my files?

6,648

Solution 1

I've found the answer myself here.

Because cd/Drivers is read-only, only root can delete from it.

Solution 2

I believe some additional information is necessary for a certain answer, but I would suspect the issue is simply permissions related. I'm guessing either you accidentally copied symlinks over instead of the real files, or you're trying to delete the entire directory but haven't reset permissions on all the files within.

First things first, when you stat the file it gives a path of 'cd/Drivers/Drivers_List.rtf', which seems to be different than the directory you're referencing in your commands. Can you confirm that you copied the files instead of creating symlinks? Providing the results of these three commands would be very useful in seeing what's going on:

  • ls -alhd /home/emma/cd
  • ls -alhd /home/emma/Drivers
  • ls -alh /home/emma/Drivers

Second, please attempt the following to see if you can remove a single file from the collection:

  • chmod 660 "/home/emma/Drivers/Drivers_List.rtf"
  • rm "/home/emma/Drivers/Drivers_List.rtf"

Let us know how that goes, and provide any errors you receive!

Share:
6,648

Related videos on Youtube

EmmaV
Author by

EmmaV

Updated on September 18, 2022

Comments

  • EmmaV
    EmmaV almost 2 years

    I copied some files from a data DVD to /home/emma (ext4), and all of the files are read only.

    This is what all of the files are like:

    emma@emma-W54-55SU1-SUW:~$ stat cd/Drivers/Drivers_List.rtf
      File: ‘cd/Drivers/Drivers_List.rtf’
      Size: 28120       Blocks: 56         IO Block: 4096   regular file
    Device: 801h/2049d  Inode: 656521      Links: 1
    Access: (0400/-r--------)  Uid: ( 1000/    emma)   Gid: ( 1000/    emma)
    Access: 2014-01-17 05:34:46.000000000 +0000
    Modify: 2014-01-17 05:34:46.000000000 +0000
    Change: 2015-02-01 23:11:04.226865424 +0000
     Birth: -
    

    When I try to delete them, I get rm: cannot remove ‘cd/Drivers/Drivers_List.rtf’: Permission denied, even though I'm the owner. Changing the mode to 777 doesn't work either. The only thing that works is deleting them as root, using sudo.

    I thought only an i attribute made files unable to be deleted by their owner, so what's going on?

    I'm using Xubuntu 14.10.

    Results of various commands:

    (Please note: I created directory cd myself, and then copied directory Drivers to it from the DVD.)

    emma@emma-W54-55SU1-SUW:~$ ls -dlh cd
    drwxrwxr-x 3 emma emma 4.0K Feb  3 01:44 cd
    
    emma@emma-W54-55SU1-SUW:~$ ls -dlh cd/Drivers
    dr-x------ 11 emma emma 4.0K Feb  3 02:15 cd/Drivers
    
    emma@emma-W54-55SU1-SUW:~$ ls -l cd/Drivers/Drivers_List.rtf
    -r-------- 1 emma emma 28120 Jan 17  2014 cd/Drivers/Drivers_List.rtf
    emma@emma-W54-55SU1-SUW:~$ rm cd/Drivers/Drivers_List.rtf
    rm: cannot remove ‘cd/Drivers/Drivers_List.rtf’: Permission denied
    
    emma@emma-W54-55SU1-SUW:~$ chmod 660 cd/Drivers/Drivers_List.rtf
    emma@emma-W54-55SU1-SUW:~$ ls -l cd/Drivers/Drivers_List.rtf
    -rw-rw---- 1 emma emma 28120 Jan 17  2014 cd/Drivers/Drivers_List.rtf
    emma@emma-W54-55SU1-SUW:~$ rm cd/Drivers/Drivers_List.rtf
    rm: cannot remove ‘cd/Drivers/Drivers_List.rtf’: Permission denied
    
    emma@emma-W54-55SU1-SUW:~$ chmod 777 cd/Drivers/Drivers_List.rtf
    emma@emma-W54-55SU1-SUW:~$ ls -l cd/Drivers/Drivers_List.rtf
    -rwxrwxrwx 1 emma emma 28120 Jan 17  2014 cd/Drivers/Drivers_List.rtf
    emma@emma-W54-55SU1-SUW:~$ rm cd/Drivers/Drivers_List.rtf
    rm: cannot remove ‘cd/Drivers/Drivers_List.rtf’: Permission denied
    
    emma@emma-W54-55SU1-SUW:~$ lsattr cd/Drivers/Drivers_List.rtf
    -------------e-- cd/Drivers/Drivers_List.rtf
    
    emma@emma-W54-55SU1-SUW:~$ ls -alh cd/Drivers
    total 48K
    dr-x------ 11 emma emma 4.0K Feb  3 02:15 .
    drwxrwxr-x  3 emma emma 4.0K Feb  3 01:44 ..
    dr-x------  7 emma emma 4.0K Jan 14  2014 01Chipset
    dr-x------  3 emma emma 4.0K Jan 14  2014 02Video
    dr-x------  9 emma emma 4.0K Jan 14  2014 03Lan
    dr-x------  9 emma emma 4.0K Jan 14  2014 04CReader
    dr-x------  3 emma emma 4.0K Jan 17  2014 05Touchpad
    dr-x------  3 emma emma 4.0K Jan 14  2014 06Airplane
    dr-x------  2 emma emma 4.0K Jan 17  2014 07Hotkey
    dr-x------ 12 emma emma 4.0K Jan 14  2014 08IME
    dr-x------  7 emma emma 4.0K Jan 14  2014 09Audio
    -r--------  1 emma emma  162 Feb 24  2012 ~$ivers_List.rtf
    

    (I've already deleted cd/Drivers/Drivers_List.rtf using sudo as a test.)

    • Ulrich Schwarz
      Ulrich Schwarz over 9 years
      What does grep /home /etc/mtab say, just for completeness' sake?
    • EmmaV
      EmmaV over 9 years
      grep /home /etc/mtab returns no matches.
    • terdon
      terdon over 9 years
      What are the permissions on the cd and Drivers directories?
    • user
      user over 9 years
      How come you run stat Drivers/Drivers_List.rtf but the output is for cd/Drivers/Drivers_List.rtf? What is the relationship between the two?
    • EmmaV
      EmmaV over 9 years
      @MichaelKjörling: I forgot to copy the emma@emma-W54-55SU1-SUW:~$ stat cd/Drivers/Drivers_List.rtf line, so I added it in later, but I omitted the cd/ part by mistake.
  • EmmaV
    EmmaV over 9 years
    Thanks for the suggestion. I already stated that sudo works. What I'm asking is why I can't delete the files without using sudo when I'm the owner.
  • EmmaV
    EmmaV over 9 years
    Thanks for your suggestion, but they aren't immutable. If they were, I wouldn't have been able to delete them using sudo.
  • EmmaV
    EmmaV over 9 years
    Thanks. Regarding the path discrepancy, I forgot to copy the emma@emma-W54-55SU1-SUW:~$ stat cd/Drivers/Drivers_List.rtf line, so I added it in later, but I omitted the cd/ part by mistake. Regarding symlinks, yes I am 100% certain that I copied files and not symlinks. I used Midnight Commander, with 'Preserve attributes' checked. I'll try what you suggested and report back when I get a chance.
  • Viraj Shah
    Viraj Shah over 9 years
    because when talking about computers, the computer does know who the actual owner is, but everything saved on your account of the computer, you are the owner of. Anything from or copied from another place (other than the web), will always have different permissions.
  • EmmaV
    EmmaV over 9 years
    I've added all of the results of the commands now. I've also discovered that not even chmod 777 makes them able to be deleted, so I must have made a mistake the first time.
  • jsagrera
    jsagrera over 9 years
    Ah, I see. Took a bit of looking, but I believe doing a chmod u+w -R ~/cd will do the trick for you. To delete a file, you need write permissions to the directory that file is in, not just the file itself (ref: stackoverflow.com/questions/8175697/… and unix.stackexchange.com/questions/49638/…)