Access denied to delete file

14,112

Linux's permissions system is very different from that of Windows. For a crash course, each permission has a few facets assigned to it. Namely, there are three octal bits (u, g, and o) that control who can access the file and to what degree. There is also a concept called a file "owner", which is a pair of a user and a group that has control over a single file (and are controlled by the u and g bits). For a more detailed look into how Linux permissions work, check out this excellent writeup over on the Arch Wiki.

In your case, the files are owned by the nobody user and the nogroup group, and the permissions are set such that the nobody user can read, write, and execute files while the nogroup group can only read and execute. Similarly, everyone else can only read or execute the files.

That said, there are about three solutions to this problem. You can become the nobody user, you can become root, or you can change ownership of these files. The first one is really not recommended, as the nobody user is a special account that shouldn't really get used.

If you just want to delete the files and be done with it, you're going to need to use the terminal. Just run the below command to delete any specific file:

sudo rm /path/to/file/you/want/gone

If you want to delete a folder, you need to use a different command:

sudo rm -rf /path/to/the/folder/you/want/gone

Before pressing ENTER, make sure your command is free of typos or other errors. These commands are very dangerous, and can have unintended side effects if a command is typed improperly.

Alternatively (and probably the better way), you can take ownership of the files, giving you full control over them. Linux has something called the chown command for exactly this purpose. I'd assume you want to change the ownership of everything, so use this command:

sudo chown -R $USER:$USER /path/to/your/folder

If you only want to change the ownership of a single file, it's this command:

sudo chown $USER:$USER /path/to/your/file

For more information into how chown works, run the man chown command in your terminal to pull up its manual. Once again, be very careful with typographical errors -- they can and will bite you in unexpected ways.

Share:
14,112

Related videos on Youtube

Anant_infinity
Author by

Anant_infinity

Updated on September 18, 2022

Comments

  • Anant_infinity
    Anant_infinity over 1 year

    I moved my files from Windows 7 PC to another Ubuntu 16.1 PC over LAN cable.

    Now when I try to delete my files in the Ubuntu PC it says access denied?

    total 28
    -rwxr--r--  1 nobody nogroup  889 Jun 16  2016 Android Book Links.txt
    -rwxr--r--  1 nobody nogroup    0 Mar  7  2009 AUTOEXEC.BAT
    drwxr-xr-x  2 nobody nogroup 4096 Mar 11 03:22 Book
    -rwxr--r--  1 nobody nogroup    0 Mar  7  2009 CONFIG.SYS
    drwxr-xr-x  6 nobody nogroup 4096 Mar 11 03:33 Documents and Settings
    drwxr-xr-x  2 nobody nogroup 4096 Mar 11 03:33 i386
    drwxr-xr-x 13 nobody nogroup 4096 Mar 12 09:59 My Documents
    drwxr-xr-x 11 nobody nogroup 4096 Mar 11 23:25 TCWIN45
    drwxr-xr-x  3 nobody nogroup 4096 Mar 11 23:25 VALUEADD
    

    • Sethos II
      Sethos II about 7 years
      Can you open a terminal in the folder with the files and post the result of ls -l? How did you copy the files? They probably have the wrong owner.
    • Sumeet Deshmukh
      Sumeet Deshmukh about 7 years
      If you didn't understand @SethosII comment, go to the folder which contains the files you want to delete, right click and select open in terminal option, then type ls -l in terminal and you'll get an output, update your question with that output
    • Anant_infinity
      Anant_infinity about 7 years
      @Sethos I selected my files from my Windows PC, then I CUT them and open the folder of the Ubuntu PC from the Windows PC using Windows file explorer and paste it into the drive of the Ubuntu PC by the help of LAN cable. It has some kind of Owner issue
    • Sumeet Deshmukh
      Sumeet Deshmukh about 7 years
      @Anant_infinity yes it can be, update your question with the output of ls -l
    • Sumeet Deshmukh
      Sumeet Deshmukh about 7 years
      askubuntu.com/a/175083/665251 you can even see the permission using gui
    • Anant_infinity
      Anant_infinity about 7 years
      Please see now I have added the output of ls -l
    • Kaz Wolfe
      Kaz Wolfe about 7 years
      Hello and welcome to Ask Ubuntu! I would highly suggest you read our tour in order to get a better idea of how our site operates (and to get a free badge). We hope to see you around!
  • sudodus
    sudodus about 7 years
    Commands that operate on folders are particularly dangerous: sudo chown -R $USER:$USER /path/to/your/folder ; sudo rm -rf /path/to/the/folder/you/want/gone
  • Anant_infinity
    Anant_infinity about 7 years
    Thanks, I will try to change the ownership and see what happens will let you know then.
  • Anant_infinity
    Anant_infinity almost 7 years
    I really worked I changed the ownership of the folder
  • Dinesh ML
    Dinesh ML over 4 years
    I dont have root access. But I want to remove the folder owned by nobody. so, How to change the owner using normal user login or else suggest any other alternatives.