I was reading about the cp
command in unix and one of the options is:
cp -f : force copy by removing the destination file if needed
so I wanted to test this to see how it works, I did the following: In some directory as a root I created a file with the name "rootfile":
-rw-r--r--. 1 root root 0 Jan 5 20:27 rootfile
then as a normal user called "User" I created another file called "Userfile":
-rw-rw-r--. 1 User User 0 Jan 5 20:27 Userfile
now I tried to perform some simple cp of the file "Userfile" to the existing root file named "rootfile" while I logging using the normal user account "User" using the following command:
cp Userfile rootfile
and this what I got :
cp: cannot create regular file `rootfile': Permission denied
This is perfect normal since I don't have permission to overwrite the existing root file.
Now applying the command with "-f
" option:
cp -f Userfile rootfile
all works fine no errors were reported, now my question is how this is possible if i don't have permission to overwrite the file named "rootfile". Is it maybe because I have permission on the folder containing the file? and how does the -f
option really works?
Regards