Linux remove permission denied

Permission Denied To Delete File

First of all, I’m not looking for an answer on how to remove the files. I am looking for a reason why this doesn’t work — and a suggestion on how to remove the files without sudo. I have a directory in my Desktop that has a few inner directories (don’t judge the naming — I just extract what I need from files I’m given) and after getting the files I try and remove the files with rm -rf Bengal\ Tiger\ Creative/ , I am surprised to see the following warning for each image.

rm: cannot remove ‘Bengal Tiger Creative/Bengal Tiger Creative/images/customer-services-landscape.jpg’: Permission denied

nathan@nathan-pc:~/Desktop$ tree . ├── Bengal Tiger Creative │ └── Bengal Tiger Creative │ └── images │ ├── awards.jpg │ ├── blank.gif │ ├── bullet1-light-green.gif │ ├── bullet2-light-green.gif │ ├── bullet3-light-green.gif │ ├── bullet4-light-green.gif │ ├── customer-services-landscape.jpg │ ├── desktop.ini │ ├── header-img1.jpg │ ├── header-img2.jpg │ ├── header-img4.jpg │ ├── header-img5.jpg │ ├── softhr.gif │ ├── Thumbs.db │ ├── tiger_main-img1.jpg │ ├── tiger_main-img2.jpg │ ├── tiger_main-img3.jpg │ ├── tiger_main-img4.jpg │ ├── Vanquis-benefits-icons_iphone-green.gif │ └── white-arrow-green.gif 
nathan@nathan-pc:~/Desktop$ ls -laR Bengal* Bengal Tiger Creative: total 12 drwxrwxr-x 3 nathan nathan 4096 Aug 10 11:30 . drwxr-xr-x 6 nathan nathan 4096 Aug 10 11:34 .. drwxrwxr-x 3 nathan nathan 4096 Aug 10 11:34 Bengal Tiger Creative Bengal Tiger Creative/Bengal Tiger Creative: total 12 drwxrwxr-x 3 nathan nathan 4096 Aug 10 11:34 . drwxrwxr-x 3 nathan nathan 4096 Aug 10 11:30 .. dr-xr-xr-x 2 nathan nathan 4096 Aug 10 11:36 images Bengal Tiger Creative/Bengal Tiger Creative/images: total 356 dr-xr-xr-x 2 nathan nathan 4096 Aug 10 11:36 . drwxrwxr-x 3 nathan nathan 4096 Aug 10 11:34 .. -rwxrwxrwx 1 nathan nathan 14910 Mar 18 12:29 awards.jpg -rw-rw-r-- 1 nathan nathan 1093 Mar 21 2014 blank.gif -rw-rw-r-- 1 nathan nathan 1978 May 8 2014 bullet1-light-green.gif -rw-rw-r-- 1 nathan nathan 1969 May 8 2014 bullet2-light-green.gif -rw-rw-r-- 1 nathan nathan 2416 May 8 2014 bullet3-light-green.gif -rw-rw-r-- 1 nathan nathan 2449 May 8 2014 bullet4-light-green.gif -rw-rw-r-- 1 nathan nathan 113138 Apr 14 2014 customer-services-landscape.jpg -r--r--r-- 1 nathan nathan 142 Mar 25 11:58 desktop.ini -rw-rw-r-- 1 nathan nathan 14312 Mar 23 11:39 header-img1.jpg -rw-rw-r-- 1 nathan nathan 1480 Mar 23 11:41 header-img2.jpg -rw-rw-r-- 1 nathan nathan 1278 Mar 23 11:41 header-img4.jpg -rw-rw-r-- 1 nathan nathan 1168 Mar 23 11:41 header-img5.jpg -rw-rw-r-- 1 nathan nathan 1703 Mar 21 2014 softhr.gif -rw-rw-r-- 1 nathan nathan 88064 Aug 4 10:39 Thumbs.db -rw-rw-r-- 1 nathan nathan 23607 Mar 23 11:56 tiger_main-img1.jpg -rw-rw-r-- 1 nathan nathan 23400 Mar 23 11:56 tiger_main-img2.jpg -rw-rw-r-- 1 nathan nathan 6970 Mar 23 11:56 tiger_main-img3.jpg -rw-rw-r-- 1 nathan nathan 8996 Mar 23 11:57 tiger_main-img4.jpg -rw-rw-r-- 1 nathan nathan 275 Jul 31 2014 Vanquis-benefits-icons_iphone-green.gif -rw-rw-r-- 1 nathan nathan 1821 Jul 9 2014 white-arrow-green.gif 

Doing chmod 777 and then delete does not work.
Doing rm -rf * inside the directory does not work.
Doing sudo rm file does work. I can easily remove these files using sudo, however, I cannot see why they cannot be removed without sudo. As a relatively new Ubuntu user, I would like to learn why. Thanks in advance,
Nathan

Читайте также:  Crossover по для linux

Источник

Как принудительно удалить папку в Linux

Иногда, когда вы пытаетесь удалить папку в Linux, вы можете получить сообщение об ошибке ‘Permission Denied’. Но вам все равно может понадобиться удалить папку. Поэтому вам нужно принудительно удалить папку. В этой статье мы узнаем, как принудительно удалить каталог в Linux.

linux

Как принудительно удалить папку в Linux

Как правило, вы получаете эту ошибку, когда пользователь Linux, под которым вы вошли в систему, не имеет права записи ‘w’ для изменения содержимого каталога. Хотя разрешение на запись требуется для записи содержимого в каталог, оно также необходимо для удаления его содержимого. Если вы находитесь в каталоге, где у вас есть разрешение write(w), вы можете легко удалить его файлы независимо от их прав доступа.

Иногда вы также можете получить эту ошибку, если вы не являетесь владельцем этого каталога. Мы рассмотрим, как решить эти две проблемы.

Допустим, у вас есть папка /home/data, которую вы не можете удалить.

В результате получаем сообщение

rm: cannot remove 'data': Permission denied

Сначала выполните команду ls для этой папки, чтобы проверить, есть ли у вас разрешение на запись или нет.

drwxr-xr-x 2 root root 4096 May 1 13:45

Как вы можете видеть выше, только пользователь root имеет право ‘w’, а другие пользователи — нет. Поэтому вы не сможете удалить папку, если вы не вошли в систему как пользователь root.

Поэтому вам нужно изменить разрешение на папку для вашего пользователя так, чтобы вы получили разрешение на ее удаление. Это можно сделать с помощью команды chmod. Число 777 означает разрешение на чтение-запись-исполнение (rwx) для всех пользователей. Вы можете изменить его в соответствии с вашими требованиями.

Теперь выполните команду ls для проверки разрешений.

drwxrwxrwx 2 root root 4096 1 May 13:45

Вы увидите, что разрешения каталога drwxrwxrwxrwx включают разрешение ‘w’ для всех пользователей. Теперь вы должны иметь возможность удалить каталог.

Если вы все еще не можете удалить нужный каталог, используйте команду chown, чтобы изменить права собственности на каталог. Допустим, вы вошли в систему как пользователь ubuntu. Как вы можете видеть выше, владельцем каталога /home/data является root. Вот команда для изменения владельца на пользователя ubuntu.

hown ubuntu:ubuntu /home/ubuntu

Теперь снова проверьте права доступа к каталогу, чтобы узнать, изменился ли его владелец. Он изменился на ubuntu.

drwxrwxrwx 2 ubuntu ubuntu 4096 May 1 13:45

Теперь вы можете удалить каталог с помощью команды rm -r.

Заключение

В этой статье мы узнали, как принудительно удалить каталог. Вы можете использовать эти шаги для удаления каталогов, при попытке удаления которых вы получаете сообщение об ошибке «разрешение отклонено». Конечно, следует быть осторожным при изменении прав собственности и разрешений каталога, так как это может повлиять на другие приложения, которые обращаются к нему. Поэтому выполняйте описанные выше действия только в том случае, если это действительно необходимо.

Похожие записи:

Источник

How to Delete Permission Denied File/Folder in Linux

Toggle Menu

updateicon

Last Updated: June 2, 2022 | Linux | Tolga Bagci

When you install any programs with root access on Linux-based operating systems, you may receive a Permission Denied error if you try to delete the remaining files or folders, and as a result, you cannot delete the file or folder.

Читайте также:  Узнать cid sd карты linux

How to Delete Permission Denied File/Folder in Linux

How to Delete an Undeleted File or Folder in Linux

For example, you are using the Linux Mint or Ubuntu operating system, and you have created a new file/folder on the desktop. Since you are logged in to the system with a non-root user, you can easily delete the file/folder you created.

However, in some cases, when you install a program that requires root access, you may encounter files and folders that cannot be deleted anywhere or on the desktop. Therefore, when you try to delete these files and folders normally, you will receive a Permission Denied error.

On Linux, you can use Terminal to delete such files and folders that cannot be deleted. You can delete files that cannot be deleted using the Linux RM command by switching to Root in the Terminal.

How to Remove Files and Folders by Using Terminal on Ubuntu, Debian, Linux Mint, Kali Linux

We will use the Linux RM command to delete an indelible folder that we encountered on Linux Mint 18/19. On Linux, you can delete files, directories, and folders using the RM command.

To delete undelete files on Linux or delete folders, follow the steps below.

As you can see in the image below, there is a folder on Linux Mint that cannot delete. When you try to delete it normally, you will receive a Permission Denied error.

Try to delete the vmware-tools-distrib folder as follows.

vmware-tools-distrib

Step 2

You will receive a Permission Denied error as in the image below.

Permission Denied Error

Step 3

Open the Terminal on Linux and execute sudo su to access Root, then type your root password and press Enter.

sudo su

Step 4

On Linux, you can use the ls command to display the directory in your current location. To delete the undeleted folder, execute rm -rf vmware-tools-distrib.

rm -rf vmware-tools-distrib

rm -rf vmware-tools-distrib

Step 5

As soon as you execute the rm -rf vmware-tools-distrib command, you can see that the folder has deleted.

Deleting a Folder

Deleting a File That Cannot Be Deleted ⇒ Video

To delete an undeletable file or folder on Linux Mint 18/19, you can watch the video below and also subscribe to our YouTube channel to support us!

Final Word

In this article, we have examined step by step on how to delete permission denied files or folders. Thanks for following us!

Tolga Bagci

TolgaBagci

Hello, I’m Tolga! I am a computer specialist who has been specializing in computer technologies for about 20 years. I provide solutions to problems encountered in many areas such as hardware, system, network, virtualization, server systems, and operating systems, and create relevant content on my website by explaining how to solve these problems. My goal is to be a reliable source of expert, quality, and trustworthy solutions for your computer problems. By following innovations and using the latest technologies, I aim to be successful in my job and provide you with the best service. Don’t hesitate to contact me for any questions or curiosity about technology. Have a nice day, stay up to date 🙂

Источник

rm: cannot remove directory/: Permission denied

Here the problem is you do not have «w» permission on the /home directory. While deleting a file note that you are not writing to that file but you are changing the contents of the directory that contains the file, so having «w» permission on the directory is a must if you want to delete any file from the directory.

Читайте также:  Linux со всеми драйверами

terminal screenshot of

If I am in a directory with «w» permission, I can delete any of its files without being worried about the file permission itself. Note that my present directory is /home/rohith which has «w» permission and hence I can delete any of its files irrespective of the file permissions.

terminal screenshot of removing /home/rohith/shadi

If the same file is created in the ‘/home’ directory which has no «w» permission I get the same output as yours ! 🙂

terminal screenshot of trying to remove /home/shadi

The restricted deletion flag or sticky bit ‘t’ on a folder would also prevent deleting «it prevents unprivileged users from removing or renaming a file in the directory unless they own the file or the directory; this is called the restricted deletion flag for the directory, and is commonly found on world-writable directories like /tmp. For regular files on some older systems, the bit saves the program’s text image on the swap device so it will load more quickly when run; this is called the sticky bit.»

This happens because you don’t own the directory, it is owned by ‘root’ and the ‘root’ group. So to delete it you can either changing the ownership and then delete it (here you elevate your rights and become ‘root’ for taking the ownership):

sudo chown $USER:$USER ./shadi rm -r ./shadi 

Or you skip taking the ownership and make a sudo rm to elevate your rights and become ‘root’ for the deletion:

Yes, or you need to elevate your rights with the sudo command. this will ask for your password then and you become ‘root’ for the particular following command.

do you now if «shadi» was a file i can remove it with «sinoosh» user .it is not require «sudo » its not make scene for me why it does not work with directory

The permissions show owner root and group root, so you have to use sudo.

Yes this command is ok, but my problem is why rm is not working with this permissions i have full permissions for this directory in other field

It’s different accounts.

How would you expect safety from your account, if everyone had the permission to delete your home directory?

You do not have the w permission to delete someone other’s home directory by default, except if they chmod +w it.

Here are the different permissions, and an example ( -rwxr-x— / rwxrx ):

+-+-+-+-+ |+|u|g|o| +-+-+-+-+ |r|1|1|1| +-+-+-+-+ |w|2|2|2| +-+-+-+-+ |x|4|4|4| +-+-+-+-+ |*|7|5|0| +-+-+-+-+

It goes like this: 1 + 2 + 4 = 7 , 1 + 4 = 5 , 0 = 0 , so 750 , i.e. an ideal permission system. The owner ( u in this case) can read, write and execute the file, the owner’s group ( g in this case) can read and execute, and anyone other ( o in this case) cannot do anything. This is the legendary:

u: current user (User) g: current user's groups (Groups) o: not current user's groups (Others) r: read permission (Read) w: write permission (Write) x: execute permission (X-ecute)

Источник

Оцените статью
Adblock
detector