why cp fails to copy /proc/stat file? why cp fails to copy /proc/stat file? unix unix

why cp fails to copy /proc/stat file?


/proc is a pseudo-filesystem. It indicates a size of 0 for the file /proc/stat.

This is why copying doesn't work (cp does first look at the size of the file it has to copy), but you can easily read the information and write it back to a file.

$> cat /proc/stat > statfile

This was fixed in GNU coreutils 7.3.


Use find to do a cp being as root user as shown,

find /proc/cpuinfo -type f -exec cp -iv '{}' /home/dir/ \;


Here is my attempt,

~/cpuinfo$ ls~/cpuinfo$ sudo find /proc/cpuinfo -type f -exec cp -iv '{}' /home/esunboj/  stackoverflow/cpuinfo/ \;  `/proc/cpuinfo' -> `/home/esunboj/stackoverflow/cpuinfo/cpuinfo'~/cpuinfo$ ls     cpuinfo

Also, as said /proc is a pseudo file system meaning the files are not stored on disk but have hooks to kernel. Probably you can read and/or write each entry from user space like a normal file operations. Usually different monitoring programs when they fopen a file, its now kernel job to find the appropriate driver which handles the task and assign it to that driver. Where in case of /proc its proc system in the kernel which will read the memory entities with the cost of system load involved.