Skip to main content
Share Your Experience: Take the 2024 Developer Survey
163 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 ...
Tom Hale's user avatar
  • 30.8k
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 ...
ioctl's user avatar
  • 1,306
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: ...
Tom Hale's user avatar
  • 30.8k
62 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 ...
jesse_b's user avatar
  • 37.3k
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 ...
DopeGhoti's user avatar
  • 76.5k
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 ...
mtraceur's user avatar
  • 1,166
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 ...
Stephen Kitt's user avatar
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 ...
Nick Matteo's user avatar
  • 1,505
36 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 ...
Stéphane Chazelas's user avatar
34 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 ...
Stephen Harris's user avatar
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 ...
michas's user avatar
  • 21.6k
30 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 ...
Stephen Kitt's user avatar
28 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 ...
grochmal's user avatar
  • 8,677
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....
ilkkachu's user avatar
  • 140k
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/...
James Henstridge's user avatar
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 ...
Edward's user avatar
  • 2,509
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 ...
alex.forencich's user avatar
22 votes
Accepted

According to which algorithm does Linux assign the hard drive letters?

The drive names are (on a typical Linux system) decided by the kernel (as the device must first be detected there), and may later be modified by udev. How it decides which hardware maps to which block ...
Chris Down's user avatar
  • 126k
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 ...
Stephen Kitt's user avatar
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. ...
Walter's user avatar
  • 389
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 ...
dirkt's user avatar
  • 32.5k
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 ...
Gilles 'SO- stop being evil''s user avatar
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 ...
intika's user avatar
  • 14.5k
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. ...
Stephen Kitt's user avatar
18 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 ...
Tim Kennedy's user avatar
  • 19.7k
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 ...
JdeBP's user avatar
  • 69.1k
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 ...
Austin Hemmelgarn's user avatar
16 votes

Why do special device files have inodes?

Device files have permissions, too, and those are stored in an inode.
Hauke Laging's user avatar
16 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 ...
Stephen Kitt's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible