cp - cannot create regular file : permission denied

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:

  1. the directory has the immutable flag enabled. check with lsattr.
  2. the directory is mounted with read-only permissions: type in terminal:

    cat /proc/mounts (or mount or cat /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.


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:

  1. Check the permissions of file. You must have read permissions to that
  2. 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

You should create directory first if /lib/udev doesn't exist

mkdir -p /lib/udev