error message while trying to remove file

Asked

Viewed 666 times

3

When I execute the command

root@debian-hy:/var/www/sys# rm teste.txt
rm: cannot remove `teste.txt': Operation not permitted

Strange because I can edit the file and save, but when I close saw it generates a swap file, follows the file permissions:

-rwxrwxrwx  1 root root        6 May 21 08:31 teste.tx~
-rwxrwxrwx  1 root root      12K May 21 08:31 teste_tx.swn
-rwxrwxrwx  1 root root      12K May 21 08:31 teste_tx.swo
-rwxrwxrwx  1 root root     4.0K May 21 08:26 teste_tx.swp
-rwxrwxrwx  1 root root       12 May 21 08:31 teste.txt
-rwxrwxrwx  1 root root        0 May 21 08:26 .teste.txt.swp
-rwxrwxrwx  1 root root        0 May 21 08:26 .teste.txt.swx
  • 1

    If when you close the saw it generates a .swp, then you cannot edit the file. (can only read). What are the outputs of the commands lsattr teste.txt and echo $UID $EUID?

  • @fonini I didn’t even know this command lsattr, was researching this command I managed to solve the problem, thank you!

2 answers

1

Perform the operation with sudo: sudo rm teste.txt

If this does not work, perform the following operations:

sudo chown root teste.txt
sudo chmod 777 teste.txt
sudo rm teste.txt
  • root@debian-hy:/var/www/sys# sudo rm teste.txt -bash: sudo: command not found (using debian 7 )

  • You executed: sudo rm teste.txt ???? Which Linux you use?

  • yes @Eduardofernandes the comment above got a little bad to read but there is the command and the return of the executed command and in parentheses the distribution that use <br/> root@debian-hy:/var/www/sys# sudo rm test.txt <br/> -bash: sudo: command not found <br/> (using debian 7 )

  • Note that if you do not have the command available sudo something is very wrong with your Linux installation.

  • i installed the sudo command via apt-get now the message from is this "rm: cannot remove `test.txt': Operation not permitted"

  • I updated the answer. Please see if it helps you.

Show 1 more comment

0


I found a documentation ref. to commands lsattr and chattr

The command chattr serves to increase security in the file or directory, the command it uses attributes and not permission like the chmod, these attributes are extensions that do not let the file be removed, changed or renamed depending on the parameters used, these attributes can be assigned to the file owner and even to the root

when I executed the command:

root@debian-hy:/var/www/sys# lsattr -d teste.txt
-----a------------- teste.txt

This "a" indicates that the file can be incremented by adding more text at the end of the file, but cannot be renamed or deleted.

So I used the remote:

root@debian-hy:/var/www/sys# chattr -a teste.txt
root@debian-hy:/var/www/sys# lsattr -a teste.txt
------------------- teste.txt

Note that I used the command lsattr to see the trailers again and this time the file no longer has any trailers, so now it can be removed.

http://www.vivaolinux.com.br/dica/Comandos-chattr-e-lsattr

  • I want to leave my thanks to Mr. Eduardofernandes and @fonini, for their dedication, I had already given up on the directory that was "locked"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.