1

According to my last question I think we can't use 'cp' to copy file to the tape device or device like '/dev/lp0'.But I still don't understand why.

To make this question simple enough,just tell me if the command 'cp' can only used on block device?

1

There are block devices and character devices (and others). Regarding a character device, a stream of characters is going to or coming from. For example a keyboard or a tape drive. Regarding block devices you can seek forward and backward on them, therefore create a file allocation table and manage files. For example a disk.

cp is used for (mounted) block devices: It creates an entry in the filesystem table that has it where the file is stored - then the file is stored to this place. Seeking forward (and maybe backward) included. You cannot do this with a tape device (just as you cannot with a keyboard). That is why you use cat with a tape drive and cp with a disk.

  • 1
    The cp command is not normally used on block devices, even though technically it can be. It is normally used with regular files. Other kinds of "files" it is not normally used with are sockets, fifos, etc... – Celada Nov 21 '14 at 6:30
  • So I think what you talked about are virtual devices@Celada – cain abel Nov 21 '14 at 6:54
  • correct, the command cp is normally used not on block devices, but on mounted block devices, so on volumes – Thorsten Staerk Nov 21 '14 at 14:47
2

One way to think of it is to think of these things as different device types. 'cp', only knows how to copy files to and from a limited number of device types. The most commonly used device for storing files is the disk drive. 'cp' knows how to copy files to and from the disk drive, as well as a limited set of other devices, such as /dev/tty.

Writing and reading data to and from a tape or CD or printer or across the network to another computer, requires special knowledge about how those devices work.

It is entirely possible that 'cp' could have been enhanced each time a new device type is added, but that would mean that there would be many different command options that would work sometimes, on some computers, and not on others.

The design of UNIX was that a command should do one thing, and do it well. For 'cp' that one thing is to make a copy of a disk file to a disk file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.