Why does the rm command not remove the file? [closed] Why does the rm command not remove the file? [closed] shell shell

Why does the rm command not remove the file? [closed]


To remove a file, you need to be able to modify (write) in the directory that contains the file. If the file isn't deleted, then you probably don't have permission to write on the directory. This could be because the file is on a read-only file system, but it is more likely that you do not have write permission on the directory. Using rm -f suppresses error messages (and prompts).

One other possibility (probably not the case here), is that the file name has a space or other invisible character at the end, and the name you specify as a file doesn't actually exist (the file is "test2" and not "test2"; or maybe it is "test1<bs>2" where the <bs> represents a backspace, or … there are endless ways to run into problems).

Rerun rm test2; respond to the prompt; look at the error messages.

Or run ls -ld . in the directory containing the file and look at the permissions, but remember that ACLs (access control lists) and extended attributes can make it harder to work out what your permissions are (though again, they're unlikely to be a factor in the problem).