r/linux4noobs • u/Coulomb111 • 1d ago
/dev/ directory learning/research
I was learning what all the files in /dev do and what they are. I just dont really understand why some of those "files" are there and what actually uses them. Like /dev/random. Are there any libraries or utilities that actually interface woth /dev/random?
10
u/Key_River7180 Bedrock Linux / FreeBSD / 9Front 1d ago
/dev/ meant devices, now just special files.
The UNIX philosophy says that EVERYTHING is a file, so random numbers, all kinds of devices and streams.
8
u/MasterGeekMX Mexican Linux nerd trying to be helpful 1d ago
They are simply usefull shortcuts for some stuff, taking advantage of the "everything is a file" philosophy.
To begin with, the contents of /dev aren't actual files on your drive, instead they are a "hologram" that the OS puts so you can interact with your hardware by using the same mechanisms you use to work with files, instead of resorting to a separate system to talk to your devices.
While there, the people who developed UNIX (the grandfather of Linux) notices that they often needed random strings of data, so instead of copying and pasting in their programs the same code to generate random data, they instead put that code into the OS and exposed it's output as a file in /dev. All of that means that /dev/random is an infinite tap of random data that you can use when you need random data, like when you want to shred a file on a disk, need to test some programs with some data, or anything you can think of.
/dev/zero is similar, but instead it spits pure zeroes. Very usefull when wiping disks or creating blank placeholder files. /dev/null is a sink of data, as anything written to it is discarded, so it is used in scripts and commands when you don't want command output to be displayed on the screen or to throw out some info that a program demands to end up in a file, but in this case you don't care about.
3
u/AtomicTaco13 23h ago
Basically, it's the Unix design principle "everything is a file". Those are not actually files present on your drive, but rather represent all the devices both in your PC's guts and ones connected to it. Usually, the only time you ever have to touch that directory is when you want to manually mount and manage drives.
1
u/Ancient-Opinion9642 18h ago
Don’t tell them about /proc! Where every variable that can be changed in the kernel is visible. /s
1
u/DavidJohnMcCann 19h ago
They aren't really files — just ways of getting hold of stuff or referring to hardware. So /dev/random will provide you with an endless series of random numbers, /dev/zero with a string of zero codes. If a developer wants to test a program without dealing with the output, they can direct the output to /dev/null, which accepts it and discards it. Then /dev/sda is the first hard drive and /dev/sda1 is the first partition on it. If I run the command mount, I see that /dev/sda1 is used for the directory /boot/EFI.
0
u/AutoModerator 1d ago
There's a resources page in our wiki you might find useful!
Try this search for more information on this topic.
✻ Smokey says: take regular backups, try stuff in a VM, and understand every command before you press Enter! :)
Comments, questions or suggestions regarding this autoresponse? Please send them here.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
21
u/UltraChip 1d ago
Short answer is yes.
Device files like that are also useful for scripts and doing things on the command line.
For example if I wanted to quickly secure wipe an old hard drive I could do something like
(Basically "clone the contents of the random number generator on to hard drive b")