LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   block special and character special files (https://www.linuxquestions.org/questions/linux-newbie-8/block-special-and-character-special-files-314813/)

s_shenbaga 04-19-2005 04:49 AM

block special and character special files
 
Hello,

My query is how to view the contents of block special and character special files.

Thanks.

cyent 04-20-2005 03:49 PM

First thing you need to have firmly welded into your head is that in Unix everything is a file, and a file is just a stream of bytes.

Disk drives, graphics cards, mice, network cards, files, directories, memory, etc. etc. etc. everything is a file and file is just a stream of bytes.

So the short answer is is that anything that can read a file, can read any file.

Ooh. "cat" can. "less" can. And editor can! Wow!

Ok, cool it for a moment. Some of those files are pretty big and a editor that pulls the whole file into memory may struggle a little, especially if it is the "memory" file !
ls -l /proc/kcore
-r-------- 1 root root 519241728 Apr 21 08:40 /proc/kcore

Next you may find some of the "special files" are there but nothing is attached or you don't have permission.

cat /dev/hdd
cat: /dev/hdd: Permission denied

So you need to be root...
su -
Password: ******
cat /dev/hdd
cat: /dev/hdd: No such device or address

The file is there, but there is no device behind it. So opening the file gets me nowhere fast.

Lets try /dev/hda
cat /dev/hda
....screenfulls of binary garbage...

Well, that worked. Sort of. (Hint to unscramble your terminal type "reset" and hit enter)

You can write to it too. DON'T DO THIS! NO! THIS WILL ZERO YOUR HARDDRIVE NO QUESTIONS ASKED!!!!
cat /dev/zero > /dev/hda

Don't DO THAT!!!

How ever, block and char special devices usually speak some protocol. You say something to them (write to file) and they say something in some strict format back to you.

Often you will find life easier to talk to them via an appropriate driver. eg. the /dev/hd* you use
"mount /dev/hdc /mnt/cdrom" and mount and the OS do magic for your and turn that ghastly stream of bytes into a file system.

Or use X windows to talk to your graphics card. etc.

So the question really is, so now you know you can _always_ read and write to a block and char special, which one is it and what do you want to say to it?

Fortitude1 06-22-2015 08:15 AM

Wow, the heavens just opened up for on this matter
 
I'm beginning to think that this site might be a first stop repository for me :D

cyent 06-22-2015 03:56 PM

It's are rather powerful unifying paradigm...

veerain 06-23-2015 02:16 AM

You can only read serially char files. And for block file in block of data and may be able to specify position of device to read.

Rest follow what @cyent said.


All times are GMT -5. The time now is 08:47 AM.