41

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 ?

Cristian Ciupitu
  • 163
  • 1
  • 16
user278122
  • 431
  • 1
  • 4
  • 4
  • 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 '18 at 17:10

5 Answers5

38

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.

mahatmanich
  • 649
  • 6
  • 13
girardengo
  • 4,925
  • 1
  • 26
  • 31
  • whoami - output root i tried cp -f and sudo cp -f , but gives error again – user278122 May 07 '14 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 07 '14 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 07 '14 at 12:39
  • I edited my answer, post in your question also output of `mount` and `lsattr /lib/` – girardengo May 07 '14 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 07 '14 at 14:01
  • Use command `mount`, without `/lib/`, but please edit your question, not copy output in comment. – girardengo May 07 '14 at 14:26
  • i use chattr and output chattr:Inappropriate ioctl for device while reading flags on /lib/udev ? and where is edit in /etc/fstab ? thanks – user278122 May 07 '14 at 15:43
  • 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? – Jonathon Dec 13 '15 at 21:06
  • I had accidentally added a trailing } to the script generated file name . My problem was not noticing the } in the error message – zzapper Sep 22 '22 at 12:01
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
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.

Sambit
  • 1,224
  • 1
  • 10
  • 14
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

passerBy
  • 1
  • 1
  • * chmod 766 – passerBy Dec 10 '18 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 '18 at 17:54