When you install any programs with root access in Linux, you may get a Permission Denied error if you try to remove or delete the remaining folders/files. As a result, you will not be able to delete the folder or file. Now, you may need to know how to delete an undeleted folder or file in Linux.
For instance, you are using the Linux Mint/ Ubuntu operating system. Also, you have made a new folder or file on the desktop. Since you are logged in to the system with a non-root user, easily you are able to remove or delete the folder/file you made. But, in other cases, when you install a program that needs root access, you may find the folders and files cannot be removed on the desktop or anywhere.
So, when you try to remove those folders and files, you are going to get a Permission Denied error. On Linux, you are able to use Terminal to remove such folders and files that cannot be removed. You will be able to remove folders that cannot be removed by using the Linux RM command.
HOW TO DELETE FOLDERS AND FILES BY USING TERMINAL ON LINUX
Now, you are going to use the Linux Rm command to remove a folder. On Linux, you are able to remove files or directories by using the Rm command. To remove folder in Linux, you have to follow these steps below:
As you will see, there is a folder in Linux that cannot be removed. When you try to remove it normally, you are going to get a Permission Denied error. Now, try to remove that folder. As we explained before that you are going to get a Permission Denied error.
After that, you have to open the Terminal in Linux and run sudo su to access root. Next, you are able to type your root password. Please press Enter.
On Linux, you are able to use the Is command to show the directory in your location. To remove an undeleted folder, you have to run rm -rf vmware-tools-distrib.
As soon as you run the command, you are able to view that the folder has been removed.
For those who encounter the error Permission Denied While using Linux, you do not worry as it can be solved. Remember that the error is encountered when you do not have the privileges to make edits a file.
Root has access to all folders and files and can make any edits. But, other users may not be allowed to make such edits. For your information, the permissions can be changed by using the chmod keyword.
The syntax for the command is:
chmod flags permissions filename
- flags are the additional option you can set.
- permissions define if you can read, write, or execute the file. They are able to be represented by using symbolic (Octal numbers).
- filename is the name of a file whose permissions are changed.
Here is an instance where you are able to read, write, and execute a file whereas, group and others can only read it.
chmod u=rwx,g=r,o=r file
Each letter has a meaning:
- r gives read permissions.
- w gives write permissions.
- x gives execute permissions .
To change directory permissions in Linux, you are able to use the following command:
- chmod +rwx filename: To add permissions.
- chmod -rwx directoryname: To delete permissions.
- chmod +x filenam: To offer executable permissions.
- chmod -wxfilename: To pick up write and executable permissions.
For note: “r” is for read, “w” is for write, and “x” is for execute.
HOW TO CHANGE DIRECTORY PERMISSIONS FOR THE GROUP OWNERS IN LINUX
Actually, the command to change directory permissions for the group owners is similar. However, it add a “g” for the group or “o” for the users:
- chmod g+w filename
- chmod g-wx filename
- chmod o+w filename
- chmod o-rwx foldername
To change directory permissions for everyone, you are able to use “u” for the users, “g” for the group, “o” for others, and “ugo” or “a” for all.
- chmod ugo+rwx foldername: To allow read, write, and run to everyone.
- chmod a=r foldername: To allow only read permission for everyone.
HOW TO CHANGE GROUPS OF DIRECTORIES AND FILES IN LINUX
By using these commands, you are able to change groups of files and directories in Linux.
- chgrp groupname filename
- chgrp groupname foldername
For note: the group has to exit before you are able to assign groups to files and directories
HOW TO CHANGE OWNERSHIP IN LINUX
Another command is changing ownerships of files and directories in Linux:
chown name filename
chown name foldername
The commands above are going to allow ownership to someone, but all sub files and directories still belong to the original owner.
Also, you are able to combine the group and ownership command by using:
chown -R name:filename /home/name/directoryname
This command provides someone the ownership of the directory files, and all files and subfolders. The -R stands for recursive, that transfers ownership of all sub directories to the new owner.
HOW TO CHANGE PERMISSIONS IN LINUX USING NUMERIC CODE
You may need to learn how to change permissions in numeric code in Linux. To do that, you are able to use numbers instead of “r”, “w”, or “x”.
- 0 = No Permission
- 1 = Execute
- 2 = Write
- 4 = Read
Usually, you add up the numbers depending on the level of permission you want to give.
Permission numbers are:
0 = —
1 = –x
2 = -w-
3 = -wx
4 = r-
5 = r-x
6 = rw-
7 = rwx
- chmod 777 foldername. This is going to give read, write, and run permissions for everyone.
- chmod 700 foldername. This is going to give read, write, and run permissions for the user only.
- chmod 327 foldername. This is going to give write and run permission for the user, w (2) for the group, and read, write, and run for the users.
We are able to conclude that there are some options when it comes to permissions. You have an ability to decide usability among users. Even though it may be easier to only give all permission to everyone, it may end up biting you in the end. So, please select wisely.
On my daily job, I am a software engineer, programmer & computer technician. My passion is assembling PC hardware, studying Operating System and all things related to computers technology. I also love to make short films for YouTube as a producer. More at about me…