Ubuntu – Access denied to delete file

filespermissions

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

Best Answer

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.

Related Question