164
votes
Accepted
When to use /dev/random vs /dev/urandom
TL;DR
Use /dev/urandom for most practical purposes.
The longer answer depends on the flavour of Unix that you're running.
Linux
Historically, /dev/random and /dev/urandom were introduced at the same ...
159
votes
Accepted
Why is /dev/null a file? Why isn't its function implemented as a simple program?
In addition to the performance benefits of using a character-special device, the primary benefit is modularity. /dev/null may be used in almost any context where a file is expected, not just in shell ...
100
votes
Accepted
What does the letter 'u' mean in /dev/urandom?
Unlimited.
In Linux, comparing the kernel functions named random_read and random_read_unlimited
indicates that the etymology of the letter u in urandom isunlimited.
This is confirmed by line 114:
...
64
votes
Accepted
What happens when Linux goes out of letters for drives?
It will go to /dev/sdaa, /dev/sdab, /dev/sdac, etc.
Here is a comment from the source code:
/**
* sd_format_disk_name - format disk name
* @prefix: name prefix - ie. "sd" for SCSI disks
...
60
votes
Why is /dev/null a file? Why isn't its function implemented as a simple program?
In fairness, it's not a regular file per se; it's a character special device:
$ file /dev/null
/dev/null: character special (3/2)
It functioning as a device rather than as a file or program means ...
55
votes
Why is /dev/null a file? Why isn't its function implemented as a simple program?
I suspect the why has a lot to do with the vision/design that shaped Unix (and consequently Linux), and the advantages stemming from it.
No doubt there's a non-negligible performance benefit to not ...
55
votes
Accepted
Why don't reads from /dev/zero count as IO_RBYTES?
They do count as I/O, but not of the type measured by the fields you’re looking at.
In htop, IO_RBYTES and IO_WBYTES show the read_bytes and write_bytes fields from /proc/<pid>/io, and those ...
48
votes
Accepted
When is mandatory use /dev/zero over /dev/null for write/discard purpose?
If you're using Linux, it's never "mandatory" to redirect to /dev/null instead of /dev/zero. As you've noticed, you'll get the same result either way.
That said, you should always redirect ...
38
votes
Accepted
Why are < or > required to use /dev/tcp
Because that's a feature of the shell (of ksh, copied by bash), and the shell only.
/dev/tcp/... are not real files, the shell intercepts the attempts to redirect to a /dev/tcp/... file and then does ...
35
votes
Accepted
Are /dev/{udp,tcp} standardized or available everywhere?
This is a feature of the shell and not the operating system.
So, for example,on Solaris 10 with ksh88 as the shell:
% cat < /dev/tcp/localhost/22
ksh: /dev/tcp/localhost/22: cannot open
However ...
31
votes
Accepted
What are nvme namespaces? How do they work?
In NVM Express and related standards, controllers give access to storage divided into one or more namespaces. Namespaces can be created and deleted via the controller, as long as there is room for ...
30
votes
/dev/input - What exactly is this?
I'll go with the question in reverse order:
Why are there so many?
Those are devices that stand for most inputs present on a machine (there are others, a microphone for example will not be ...
30
votes
Accepted
What happens if you delete a device file?
Those are simply (special) files. They only serve as "pointers" to the actual device. (i.e. the driver module inside the kernel.)
If some command/service already opened that file, it already has a ...
28
votes
Accepted
Should I use single or double angle brackets to redirect to /dev/null?
By definition /dev/null sinks anything written to it, so it doesn't matter if you write in append mode or not, it's all discarded. Since it doesn't store the data, there's nothing to append to, really....
28
votes
Accepted
Multiple /dev/video for one physical device
The second device provides metadata about the video data from the first device. The new devices were introduced by this patch:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/...
27
votes
Why do directories created under /dev disappear after reboot?
Yes, you can create files and/or directories under /dev/. But you can't expect them to still be there after a reboot.
Here is why: the dev filesystem is responsible for device access. It's not a block ...
23
votes
How to Reset/Cycle Power to a PCIe Device?
Resets in PCI express are a bit complex. There are two main types of resets - conventional reset, and function-level reset. There are also two types of conventional resets, fundamental resets and ...
22
votes
Accepted
Is /dev/nvram dangerous to write to?
I'm curious as to exactly why you'd want to run such a command if you think it might damage your computer...
/dev/nvram provides access to the non-volatile memory in the real-time clock on PCs and ...
21
votes
What does the letter 'u' mean in /dev/urandom?
It depends on which "Unix" system you are talking about.
On FreeBSD, /dev/urandom and /dev/random are the same device. The letter u is now a historical legacy that exists for backward compatibility. ...
20
votes
how to get bus id of an usb device
You can read off the sequence from the device tree you get with lsusb -t. The number before the hyphen is the bus, the numbers after the hyphen are the port sequence. Your device is on bus 01, on port ...
20
votes
Accepted
With ZFS on Linux, how do I list device (vdev) specific properties?
In order to view the current value of a specific setting like ashift, you will need to use the zdb command instead of the zpool command.
Running zdb on its own with no arguments will give you a view ...
20
votes
Accepted
Would chmod 000 /dev/stdin disable terminal forever?
No, /dev/stdin and /dev/stdout are the wrong device. These are not terminal devices, they're aliases for standard input and standard output respectively. Standard input and standard output are, by ...
20
votes
Accepted
How does udev/uevent work?
UDEV
Udev stand for "userspace /dev" it is a device manager for the Linux kernel. It is part of systemd (an init system used to bootstrap user space and manage user processes).
Originally udev was ...
19
votes
Accepted
What is `/dev/sda0`? Is it a standard thing?
I’m not aware of /dev/sda0 ever being a standard device name, even on other Unix systems. And as far as I can tell, references to sda0 are likely mistakes rather than indications of a custom setup.
...
17
votes
Accepted
What is swap priority and why does it matter
man 2 swapon describes priorities thus:
Each swap area has a priority, either high or low. The default priority is low. Within the low-priority areas, newer areas are even lower priority than older ...
16
votes
Are there alternatives to using `udev`?
There are several alternatives:
Simply have a set of appropriate chmod, chown, ln, and suchlike commands in a script that is run as part of the bootstrap.
Use systemd-udev, the plug-and-play manager ...
16
votes
Accepted
Why do special device files have inodes?
The short answer is that it does only if you have a physical filesystem backing /dev (and if you're using a modern Linux distro, you probably don't).
The long answer follows:
This all goes back to ...
16
votes
Why do special device files have inodes?
Device files have permissions, too, and those are stored in an inode.
16
votes
Accepted
What's the reason to add a symlink to /dev directory with udev rules?
Typically it's to give a known fixed pathname to access the device; /dev/mydevice is fixed but depending on the order things are plugged in it might be /dev/ttyUSB0 or /dev/ttyUSB1 or /dev/ttyUSB2 or.....
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
devices × 849linux × 273
udev × 106
usb × 89
drivers × 73
block-device × 65
mount × 50
linux-kernel × 43
filesystems × 38
debian × 37
kernel × 32
files × 29
permissions × 27
ubuntu × 25
usb-device × 23
kernel-modules × 21
tty × 21
disk × 21
partition × 20
audio × 20
serial-port × 18
arch-linux × 17
sysfs × 17
hard-disk × 16
input × 15