cp - cannot create regular file : permission denied
Solution 1
Check if you are really superuser with:
whoami
if the output is root
, then you are superuser and you can make the copy of the file with:
cp -f /tmp/ok_pcscd_hotplug.sh /lib/udev/.
otherwise you have to use sudo
:
sudo cp -f /tmp/ok_pcscd_hotplug.sh /lib/udev/.
If you're still not able to write to the directory, then it is possible that:
- the directory has the immutable flag enabled. check with
lsattr
. the directory is mounted with read-only permissions: type in terminal:
cat /proc/mounts
(ormount
orcat /etc/mtab
)and check the output, if directory is mounted read-only.
If you are in the first case, change the directory attributes with chattr
;
- remove immutable flag on file or directory
chattr -i <file/dir>
- adding immutable flag on file or directory again
chattr +i <file/dir>
If you're in the latter case, edit the file /etc/fstab
.
Solution 2
You should create directory first if /lib/udev
doesn't exist
mkdir -p /lib/udev
Solution 3
Its not necessary every time that you need to be root for this purpose So if you want to do it with root user its fine, but if you want to do it without root, then you have 2 options:
- Check the permissions of file. You must have read permissions to that
- Check that file or link with same name is not present in the destination directory. Because if link with same name is there in destination directory, it won't allow you to do that and also will not warn that link with same name is present
Solution 4
Try cp /tmp/ok_pcscd_hotplug.sh /lib/udev/
in root user.
Related videos on Youtube
user278122
Updated on September 18, 2022Comments
-
user278122 almost 2 years
I want copy to
/lib/udev
but gives errorcp -f /tmp/ok_pcscd_hotplug.sh /lib/udev cp:cannot create regular file /lib/udev/ok_pcscd_hotplug : Permission denied
I am root , but I can't understand . what can I do ?
-
user278122 about 10 yearsdont change,gives error again - root@atrust-00351A:/lib# ls-l drwxrwxrwx 4 root root 324 2009-05-22 11:40 udev
-
Sambit about 10 yearsPlease post the output
whoami
andls -al /tmp/ok_pcscd_hotplug.sh
-
user278122 about 10 yearswhoami - output root ls -al /tmp/ok_pcscd_hotplug.sh - output -rwxr-xr-x 1 root root 229
-
user278122 about 10 yearswhoami - output root i tried cp -f and sudo cp -f , but gives error again
-
girardengo about 10 yearsI made a small change to my answer: I copied the command from your question, but there is an error: the command as you wrote, it will overwrite udev, you must add
/.
at the end of the command to copy the files in the directory -
Sambit about 10 yearsThen make sure that
ok_pcscd_hotplug.sh
is not corrupted and/lib/udev/
exist in your system. -
user278122 about 10 yearseither ok_pcscd_hot_plug.sh or /lib/udev avaliable on system
-
girardengo about 10 yearsI edited my answer, post in your question also output of
mount
andlsattr /lib/
-
user278122 about 10 yearsmount /lib/ - mount:can't find /lib/ in /etc/fstab or /etc/mtab lsattr /lib/ - Inapppropriate ioctl for device while reading flags on lib/filename output for everyfile
-
girardengo about 10 yearsUse command
mount
, without/lib/
, but please edit your question, not copy output in comment. -
user278122 about 10 yearsi use chattr and output chattr:Inappropriate ioctl for device while reading flags on /lib/udev ? and where is edit in /etc/fstab ? thanks
-
Jonathon over 8 yearsI am confused. I am trying to copy a file from a cdrom to my home dir. Why would I not always have permission to write to my home directory?
-
passerBy over 5 years* chmod 766 <file/dir>
-
Kulfy over 5 yearsYou can still edit the answer and add that. And I don't believe in granting all permissions to users. Instead if folder/file is to be made login as the user who has privileges. Thanks. :-)