cp - cannot create regular file : permission denied

429,085

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:

  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.

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:

  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

Solution 4

Try cp /tmp/ok_pcscd_hotplug.sh /lib/udev/ in root user.

Share:
429,085

Related videos on Youtube

user278122
Author by

user278122

Updated on September 18, 2022

Comments

  • user278122
    user278122 almost 2 years

    I want copy to /lib/udev but gives error

    cp -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
    user278122 about 10 years
    dont change,gives error again - root@atrust-00351A:/lib# ls-l drwxrwxrwx 4 root root 324 2009-05-22 11:40 udev
  • Sambit
    Sambit about 10 years
    Please post the output whoami and ls -al /tmp/ok_pcscd_hotplug.sh
  • user278122
    user278122 about 10 years
    whoami - output root ls -al /tmp/ok_pcscd_hotplug.sh - output -rwxr-xr-x 1 root root 229
  • user278122
    user278122 about 10 years
    whoami - output root i tried cp -f and sudo cp -f , but gives error again
  • girardengo
    girardengo about 10 years
    I 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
    Sambit about 10 years
    Then make sure that ok_pcscd_hotplug.sh is not corrupted and /lib/udev/ exist in your system.
  • user278122
    user278122 about 10 years
    either ok_pcscd_hot_plug.sh or /lib/udev avaliable on system
  • girardengo
    girardengo about 10 years
    I edited my answer, post in your question also output of mount and lsattr /lib/
  • user278122
    user278122 about 10 years
    mount /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
    girardengo about 10 years
    Use command mount, without /lib/, but please edit your question, not copy output in comment.
  • user278122
    user278122 about 10 years
    i use chattr and output chattr:Inappropriate ioctl for device while reading flags on /lib/udev ? and where is edit in /etc/fstab ? thanks
  • Jonathon
    Jonathon over 8 years
    I 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
    passerBy over 5 years
    * chmod 766 <file/dir>
  • Kulfy
    Kulfy over 5 years
    You 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. :-)