Linux удалить папку permission denied

Why I can’t delete a folder?

If that error output is from nautilus, you can add a screen-shoot to your question. Also, what is the output of rm -r from terminal? Have you tried with the answers of this post?

I have been used rm -Rf for remove recursively directories, may be this work for you. The uppercase R means Recursive, see man pages man rm

Do you have permission to remove this directory? Please execute ls -la and paste it here to discard this option.

The folder was I think deleted first on windows and then tried to delete on Ubuntu. Then tried to delete on Windows but said error. Directory not empty but its all empty promise. On windows it says error Error x00000

8 Answers 8

Did you try sudo rm -r . What kind of files are there? You could also delete all the files first then delete the folder. It’s extra work, but sometimes it is worth it to get the job done.

sudo is for superuser actions.

I know sudo and the folder has no files inside only a sub folder. Artist Folder then Album Folder no MP3s inside. Just folder.

Try cd into the directory, then remove all files using rm -rf * . Then try going out of the directory and use rmdir to delete the directory.

I had this issue with a folder on a btrfs filesystem. Checking mount points and lsof are the normal things to look for. In my case it was corruption caused by an old bug, since fixed:

The normal things to check for:

  • lsof +D — This will list all open files. You cannot delete a folder that contains open files, though that would also normally give a slightly different error: «Device or resource busy». Note that if you leave out the «+D «, lsof will show a listing for all folders on all filesystems — which will waste time. 😉
  • mount: This will show you the currently mounted filesystems. You cannot delete an actively-mounted mountpoint or its parent folders.
  • btrfs sub list : Similar to a mount point, you cannot delete a btrfs subvolume except by using the btrfs-specific command: btrfs subvolume delete .

Corruption Workaround

In the case of corruption where it cannot easily be fixed, the basic workaround is to back up, format the filesystem, and then restore (leaving out the bad data). Depending on how much data you have in the filesystem, this can be a chore. :-/

In my case the problem folder was inside a subvolume so I was able to do the above but by deleting only the subvolume instead of the entire filesystem. I backed up my data and deleted the subvolume: btrfs sub del . I was then able to restore into a new subvolume, leaving out the problem folder.

Corruption of i_size

The cause in my case was found to be corruption of i_size, where it was non-zero. Btrfs uses the i_size to tell whether or not the folder is empty. To check on this, run:

The i_size of an empty folder in btrfs should be zero. In ext it is typically 4k.

Источник

Как принудительно удалить папку в 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.

Заключение

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

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

Источник

Can’t remove directory that I’m owner of

I’m attempting to remove a directory I have permissions to, but for some reason I’m getting a permission denied error when attempting to remove it:

mage@vagrant:/var/www$ ls -la total 16 drwxr-xr-x 4 root root 4096 Oct 30 22:49 . drwxr-xr-x 14 root root 4096 Oct 30 22:20 .. drwxr-xr-x 2 root root 4096 Oct 30 22:20 html drwxrwxrwx 2 mage mage 4096 Oct 30 22:49 mage mage@vagrant:/var/www$ whoami mage mage@vagrant:/var/www$ rm -R mage rm: cannot remove 'mage': Permission denied 

I’m not owner of /var or /var/www but I am owner of /var/www/mage , I thought as I’m the owner of the mage directory I should be able to delete it?

@BugHunterUK To delete /var/www/mage you have to alter /var/www to remove mage from its contents. So you need write rights to /var/www (the same would be true if you were creating or renaming /var/www/mage ).

2 Answers 2

The issue is you’re not the owner nor part of the group of the parent folder and that is what’s blocking you. Run the same command with sudo in front of it without modifying the permissions or ownership of the /var/www/ folder.

Folders inherit the permissions from their parent folders. When you are the owner of the mage/ folder, that will allow you to create new folders and files and delete them within the mage/ folder. But, since the mage/ folder is a subfolder of the /var/www/ folder, which you do not have write or execute permissions to, you cannot create files or folders without sudo permission or changing the ownership or permissions of /var/www/ . If /var/www/ had permissions of drwxrwxrwx that would allow you as a user to delete that folder, but this is not recommended as it could break your apache2 server.

Your folder inherited the same permissions as its parent folder that is why you cannot delete the folder as a regular user.

Источник

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.

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)

Источник

Читайте также:  Linux dns сервер bind
Оцените статью
Adblock
detector