Is there any way to interact with all the items that are in the /dev
directory? From my understanding, most items in the /dev
directory are not "normal" files. I want to know if there are any commands or any way that you can interact with them, whether it is listing out their properties or do other things with/to them.
1 Answers
This is a bit of a funny question. I'll quote your comment:
Since most things are files, is there a way to see what they contain using some kind of editor?
This reveals a misconception (one I had myself as a beginner) that "everything is a file" should be taken literally.
A "file" is of course a collection of bytes, with a name, considered as an individual unit, and usually stored on disk.
When you hear, "In UNIX, everything is a file," this is not the definition of "file" being used.
Instead, a "file" in this sense is "something that can be accessed or handled in some way by using the standard system calls for dealing with files."
Virtual filesystems such as /proc
exemplify this very well. The "files" and "directories" in /proc
are not actual files and directories stored on disk. They're not stored anywhere.
Instead, when a process attempts to read from one of these files—using the same system calls as are used to read from files—the kernel handles the calls differently. Rather than getting data from disk and returning that, the kernel responds directly with the appropriate runtime data from the kernel. But it is a "transparent" abstraction, because no process reads data from files except by asking the kernel to do so. (That's the concept embodied in the phrase "system call.")
Now, the directory entries within /dev
are "special files." Not all file-related system calls are applicable to every one of them. However, the basic abstraction, that any sort of special device or anything can be dealt with by a process as though it were a file, still holds for the most part.
Since the entries in /dev
are abstractions of many types of things that are actually different, it's not easy to give a single generic answer that covers all the types of things you can do with all of them.
However, to really understand what these entries are and what they mean and how to handle them, you should read:
"File" always means "something with a directory entry," which may or may not be a regular file, and "regular file" always means "collection of bytes with a name," which is usually just called a "file."
To answer the comment on this question point by point:
So all of the items within /dev are "files"...
Yes, but none should be regular files.
...but that does not necessarily mean that they can be edited by the human...
I wonder who else you think edits anything besides a human? Whether it's a long-departed systems programmer or you yourself, humans are the only source of decisions or intention in any computer system. (See Mark Burgess's work for philosophic background on this.) :D
But I think I understand what you meant. We can accurately say that the special files in /dev
cannot be edited by a normal "text editor" because they are not text files. And, modifying the /dev
entries themselves requires root permissions, although user space (a.k.a. non-root) processes may be able to use them.
...because a file when referred to, in UNIX, as something that is handled or managed by system calls...
Yes, that is correct. Anything that is ever called a "file" is dealt with using system calls. This includes regular files, by the way. If you use gedit
, the way it opens the file you want to edit is by using a system call. It reads the contents of the file through another system call.
...but can be edited by a user. Am I correct?
No, that last part is not correct. Not all files can be edited by a user. Also, when we're talking in this level of detail, "edited" is a very very imprecise word, almost meaningless.
Rather we should say that all regular files can be handled by user space processes via system calls to open, read, write, etc., the file, although any one of these system calls may fail for various causes (insufficient permissions, attempting to write when the disk is full, attempting to write when the disk is mounted read only, etc., etc.).
And special files can be handled by system calls as well, although in that case the support for each individual system call is dependent on the type of special file, and ultimately dependent on the underlying driver which handles that system call.
To better understand block and character special files, see:

- 36,499
-
So all of the items within
/dev
are "files" but that does not necessarily mean that they can be edited by the human because a file when referred to, in UNIX, as something that is handled or managed by system calls but can be edited by a user. Am I correct? – Hunter T. Jan 16 '18 at 02:27 -
1@HunterT., "file" always means "something with a directory entry," which may or may not be a regular file, and "regular file" always means "collection of bytes with a name," which is usually just called a "file." These definitions don't change. Use "regular file" when you want to be more precise. Also be sure you understand: symbolic links, directories, block special files, character special files, etc. – Wildcard Jan 16 '18 at 02:27
-
Ok, the only two things I don't understand that I planned on understanding at one point in time, is block special files and character special file. – Hunter T. Jan 16 '18 at 02:30
-
@HunterT., see edit, and especially the link at the bottom. Hope that helps! – Wildcard Jan 16 '18 at 02:42
-
-
1@HunterT., you're welcome. You can also mark the answer "accepted" if that seems appropriate to you. – Wildcard Jan 16 '18 at 02:46
/dev
are files. They just happen to interact with devices when written to or read from. The Linux framebuffer device file can even be read to take a screenshot of your virtual terminal, or written to to display images. None of this is special, you just need to know the format of the data expected or provided – Fox Jan 16 '18 at 01:53vim
but it just tells me that it is not a file. – Hunter T. Jan 16 '18 at 02:01hexedit
likes device files, buthexdump -Cvv
will at least display what it can read from a device file. I don't think a typical editor likes FIFOs either though, so don't assume you can open something in, say,gedit
just because it is a file – Fox Jan 16 '18 at 02:07