• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

UNIX: Removing another owner's files in your home directory

JonathanYoung

Senior member
Hi all,

I'm currently taking a UNIX course, and right now we're studying permissions. In class the other day, I learned that if you have write permission to a directory, you can basically delete that directory because you can change that directory's "file table". So, I tried an experiment by using the command mv to copy over files from my professor's public directory and keeping the same permissions as in my prof's directory to a test directory in my home. When I tried rm -r on test, I deleted everything except those files which I didn't have permission to. I can't change permissions on those files because I am neither owner nor in the same group. Does anyone know how to remove these files from my home directory now? I think it doesn't work because rm -r doesn't edit a directory's "file table" directly, but rather recursively goes into each directory to delete stuff, and when it encountered my prof's files, it couldn't delete them. Any way to just delete test without checking what's in it? THanks in advance for any replies!

In summary:
I own directory "test" with full permissions.
I copied professor's files over into test, kept his permissions.
Tried to rm -r test but couldn't delete prof's files.
Help!

Edit: I don't have root access!
 
You should be able to just rm <filename> and have it delete them as long as you have write access to the parent directory.

ls -l blah
-rw-r--r-- 1 root root 0 Feb 14 01:28 blah
$ rm blah
rm: remove write-protected regular empty file `blah'? y
$ ls -l blah
ls: blah: No such file or directory
 
I know that when I copy files, I use the cp command, and when they are copied to a folder that I own, it automatically changes the owner/group ownership of the files so that I can manipulate them.

I am not sure what is wrong with your system.
 
Originally posted by: rmrf
I know that when I copy files, I use the cp command, and when they are copied to a folder that I own, it automatically changes the owner/group ownership of the files so that I can manipulate them.

I am not sure what is wrong with your system.

Yeah, cp works fine because it changes the permissions to your own settings, but for some reason mv will "move" all files, including the ones you don't have write permission to... effectively creating an exact copy of those files, including permissions. I emailed the class list and a tutor said that it was probably a bug in the system.

Thank you everyone for replying!
 
What OS is this? If it is linux, what distro is it. I have seen different OS's handle this differently.

foxkm
 
Any chance of you perhaps posting a ls -al for us ?

The only weird thing that I can think of is some system immutable flag or you just dont have write access to the file
 
Hey guys,

Thanks for all the replies. The version of Unix is HP Release B.11.00.

n0cmonkey, I didn't use cp to copy the files. I used mv, which basically created a copy of my prof's files since I don't have write permission to "delete" those files after moving them.

foxkm, you're right. One of the tutors said that on some systems, the move would not have been made, while on others, it would have copied the original files but created new permissions for me.

djdrastic: yup, you said it. I basically don't have write permission to the directory I'm trying to remove. I am also not the owner. So, even though I own and have write permission to the parent of said directory, I can't remove it.

Now, if there were only my professor's *files* in a directory I owned and could write to, I could easily remove those files by removing my directory. The whole thing doesn't make sense, because in UNIX, a directory is just a special kind of file, right? Anyway thanks again everyone, I'll post another reply if I learn anything else.

Edit: I think I just saw the light: when it comes to deleting files, it doesn't matter what permissions you have on those files. The most important thing is to have write permission to the directory those files are in!!! So I can have a directory full of files with 000 permissions set, but as long as I have some form of w to the parent directory, I can delete them.
 
Edit: I think I just saw the light: when it comes to deleting files, it doesn't matter what permissions you have on those files. The most important thing is to have write permission to the directory those files are in!!! So I can have a directory full of files with 000 permissions set, but as long as I have some form of w to the parent directory, I can delete them.

That makes sense to me.

This is becuase those filenames and such is only meta-information stored in your directory 'file'. At least in Linux you have links that point to the inode number(s) that the file is stored in. The directory simply contains the information about all those links. So when you go "ls directoryname" your just showing the information that is stored in that directory. The bits themselves could be anywere on the harddrive. Your looking at just pointers... Links (like symbolic link vs hard link)...

When you move a file with 'mv' you aren't actually copying the file if the file remains on the same partition/mount. What your doing is creating a new hardlink to that file, then deleting the old one. That way the file bit themselves still remain in the same section of the harddrive, but directory that holds the links to them is just different.

If you use 'mv' to move files onto a different volume/directory/whatever then your actually copying the file contents itself and then deleting all record of the file in it's previous location because what is in one partition will remain seperate from what is inside a different partition.

Now the delete with 'rm' is something i don't know about. It shouldn't delete a directory with contents in it, unless specify the recursive command then if you have a file you don't have permission for it should stop you from deleting the file, which in turn stops you from deleting the directory holding it. Could be different on HP-UX though. And rm doesn't actually destroy the contents of a file (unless there is some security 'shredder' thing setup, I suppose), it just removes the record of it from the directory.

So you can go:
echo "this file is here" > tester

ln tester testy

rm tester

cat testy
"this file is here"
 
Back
Top