42

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 ?

1
  • In my case, when I needed to copy something onto exFAT, it failed at each file which had a "|" in it's filename.
    – neverMind9
    Apr 14, 2018 at 17:10

5 Answers 5

40

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.

9
  • 1
    whoami - output root i tried cp -f and sudo cp -f , but gives error again
    – user278122
    May 7, 2014 at 11:47
  • 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
    – girardengo
    May 7, 2014 at 12:14
  • i tried : cp -f /tmp/ok_pcscd_hotplug.sh /lib/udev/. cp -f /tmp/ok_pcscd_hotplug.sh /lib/udev/ cp /tmp/ok_pcscd_hotplug.sh /lib/udev i don't understand , i'm root but don't copied where is the problem
    – user278122
    May 7, 2014 at 12:39
  • I edited my answer, post in your question also output of mount and lsattr /lib/
    – girardengo
    May 7, 2014 at 13:48
  • 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
    – user278122
    May 7, 2014 at 14:01
4

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
3

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

mkdir -p /lib/udev
1

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

5
  • dont change,gives error again - root@atrust-00351A:/lib# ls-l drwxrwxrwx 4 root root 324 2009-05-22 11:40 udev
    – user278122
    May 7, 2014 at 10:55
  • Please post the output whoami and ls -al /tmp/ok_pcscd_hotplug.sh
    – Sambit
    May 7, 2014 at 11:26
  • whoami - output root ls -al /tmp/ok_pcscd_hotplug.sh - output -rwxr-xr-x 1 root root 229
    – user278122
    May 7, 2014 at 11:45
  • Then make sure that ok_pcscd_hotplug.sh is not corrupted and /lib/udev/ exist in your system.
    – Sambit
    May 7, 2014 at 13:18
  • either ok_pcscd_hot_plug.sh or /lib/udev avaliable on system
    – user278122
    May 7, 2014 at 13:21
0

First do " ls -l " and check the permissions for this directory. If you see something like -rw-r--r-- , that means Owner can read-write, Usergroup can only read, World can only read. Type in the following command if this be the case : " chmod 766 ". This will allow you to perform read-write operations on that file. Now try copying that file the same way. It should work

2
  • * chmod 766 <file/dir>
    – passerBy
    Dec 10, 2018 at 17:54
  • 1
    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. :-)
    – Kulfy
    Dec 10, 2018 at 17:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .