Hot answers tagged

80

/dev/zero is an example of a "special file" — particularly, a "device node". Normally these get created by the distro installation process, but you can totally create them yourself if you want to. If you ask ls about /dev/zero: # ls -l /dev/zero crw-rw-rw- 1 root root 1, 5 Nov 5 09:34 /dev/zero The "c" at the start tells you that this is a "...


27

Most of the /dev entries are block device inodes or character device inodes. One previous answer has many details about that, which I am not going to repeat. But /dev/tcp which is mentioned in your question is not explained by any of the existing answers. /dev/tcp and /dev/udp are different from most other /dev entries. The block and character devices are ...


23

So there are basically two different types of thing here: Normal filesystems, which hold files in directories with data and metadata, in the familiar manner (including soft links, hard links, and so on). These are often, but not always, backed by a block device for persistent storage (a tmpfs lives in RAM only, but is otherwise identical to a normal ...


19

Yes, both accept and discard all input, but their output is not the same: /dev/null produces no output. /dev/zero produces a continuous stream of NULL (zero value) bytes. You can see the difference by executing cat /dev/null and cat /dev/zero. Try cat /dev/null > file and you will find an empty file. Now try cat /dev/zero > file, while ...


16

In addition of device nodes explained in other answers (created with mknod(2) or supplied by some devfs), notably the one from Sepahrad Salour, Linux has other "magical" files provided by special virtual file systems, in particular in /proc/ (see proc(5), read about procfs) and in /sys/ (read about sysfs). These pseudo files (which appear -e.g. to stat(2)- ...


16

Here's a file listing of /dev/sda1 on my nearly up-to-date Arch Linux server: % ls -li /dev/sda1 1294 brw-rw---- 1 root disk 8, 1 Nov 9 13:26 /dev/sda1 So the directory entry in /dev/ for sda has an inode number, 1294. It's a real file on disk. Look at where the file size usually appears. "8, 1" appears instead. This is a major and minor device number. ...


11

They're called device nodes, and are created either manually with mknod or automatically by udev. They are typically file-like interfaces to character or block devices with drivers in the kernel - e.g. disks are block devices, ttys and serial ports etc are character devices. There are other "special" file types too, including named pipes and fifos and ...


7

No, /dev/raw is different from the conventional /dev/sda block device. According to The Linux 2.4 SCSI subsystem HOWTO: Chapter 11. Raw devices: A raw device can be bound to an existing block device (e.g. a disk) and be used to perform "raw" IO with that existing block device. Such "raw" IO bypasses the caching that is normally associated with block ...


7

/dev/tty is the controlling tty of the current process, for any process that actually opens this special file. It isn’t necessarily a virtual console device (/dev/ttyn), and can be a pty, a serial port, etc. If the controlling tty isn’t a virtual console, then the process has not to interact with console devices even if its pseudotty is actually implemented ...


7

As other users have already explained in great detail, special files require code to back them up. However, nobody seems to have mentioned that Linux provides several ways to write that code in userspace: A. FUSE (Filesystem in USErspace) allows you to write something like /proc without risk of crashing the kernel and do it in a language/runtime of your ...


7

If you could call mknod arbitrarily, then you could create device files owned and accessible by you for any device. The device files give you unlimited access to the corresponding devices; therefore, any user could access devices arbitrarily. For instance, suppose /dev/sda1 holds a file system to which you have no access. (Say, it is mounted to /secret). ...


7

For all the tmpfs mounts, "Avail" is an artificial limit. The default size for tmpfs mounts is half your RAM. It can be adjusted at mount time. (man mount, scroll to tmpfs). The mounts don't share the same space, in that if you filled the /dev/shm mount, /dev would not show any more "Used", and it would not necessarily stop you from writing data to /dev ...


6

The book Linux Device Drivers (highly recommended) explains this in detail, and even has you create a kernel module that does this as an example, but in a nutshell, each device driver has specific functions that get called when a file is opened, closed, read, written, etc. The "special" files just do something special inside those functions, instead of ...


5

At the end of the day they are all files for Unix, that´s the beauty of the abstraction. The way the files are handled by the kernel, now that is a diferent story. /proc and nowadays /dev and /run (aka /var/run) are virtual filesystems in RAM. /proc is an interface/windows to kernel variables and structures. I recommend reading The Linux Kernel http://...


5

The drive names are (on a typical Linux system) decided by udev.How it decides which hardware maps to which block special file is an implementation detail that will depend your udev configuration, kernel configuration, module setup, and many other things, too (including plain luck). Typically udev will assign the first letter to whichever device it detects ...


4

A loop device is a particular type of block device, managed by the loop device driver. A loop device is a block device whose content is stored in a file, similar to the way a SCSI disk device is a block device whose content is stored on a SCSI disk, a USB storage device is a block device whose content is stored on a USB storage peripheral, etc. Linux has a ...


4

I always do cat /proc/net/dev it's simple and easy to memorize


4

Libncurses was recently updated from /usr/lib32/libncursesw.so.5 to /usr/lib32/libncursesw.so.6. There would have been a matching bash update, but you don't have it. In fact, I just found this in my own pacman.log: [2015-09-19 23:45] [ALPM] upgraded ncurses (5.9-7 -> 6.0-3) [2015-09-19 23:45] [ALPM] upgraded readline (6.3.008-1 -> 6.3.008-3) [2015-09-...


4

In addition to @RuiFRibeiro's and @BruceEdiger's answers, the distinction you make is not exactly the distinction the kernel makes. Actually, you have various kind of files: regular files, directories, symbolic links, devices, sockets (and I always forget a few so I won't try to make a full list). You can have the information on the type of a file with ls: ...


4

After the regular, FIFO and socket file types, mknod can also create device files. These are used to access devices. Granting access to devices is considered a privileged operation. Generally, we don't want to create arbitrary device nodes and make them accessible to regular users. That would be Bad. [Aside: Typically device access is granted by ...


4

With mknod, you create device-special files that allow raw access to the hardware. That is, the kernel looks at the device-special file's permissions to decide whether a given user is allowed raw acess to hardware, not to anything in configuration or some such. E.g., on Debian, devices related to optical drives are created with 0660 permission bits, user ...


4

Unix/Linux systems are multi-user. Anyone who has read access to a raw storage device can read all the files on it, regardless of who owns the files and their permissions (modulo the filesystem being encrypted, of course). So traditionally the raw devices have only allowed access to root and to members of an administrative group such as operator or disk, and ...


4

Most filesystems have unique UUIDs and have labels which you can set to a distinctive values. These allow you to refer to the volume containing the filesystem through /dev/disk/by-uuid or /dev/disk/by-label. Other types of volumes (RAID, LVM, etc.) generally have a name as well. RAID and LVM volumes are assembled based on unique identifiers in the physical ...


3

ttyUSBx devices are not simple USB ports, but rather USB UART devices which emulate a serial port via USB. They are often based on Prolific (PL2303) or FTDI chip. You'll have to obtain such a device and connect it to your computer for a /dev/ttyUSBx entry to appear, in the same way as plugging in a USB flash drive creates a /dev/sdx device.


3

that depends on the sound system running on your system. Search for alsa/pulse/jack/oss/whatever interface and you'll find plenty of information. For example if you are using PulseAudio (which seams to be the standard today) you can use pacat/parec to get streams from your audio input. Just have a look at man pacat and you will find out that you can do ...


3

What /dev/sda means There are four levels: raw disk, raw partition of that disk, formatted filesystem on a partition, and actual files stored within a filesystem. /dev/sda means an entire disk, not a filesystem. Something with a number at the end is a partition of a disk: dev/sda1 is the first partition of the /dev/sda disk, and it's not even necessarily ...


3

You can try running # udevadm trigger Or restart the udev daemon.


2

Although you question is slightly ambiguous (what is meant by console), I will attempt to answer for the most common cases: /dev/console, /dev/tty, /dev/fb0 ...adapt this to the devices you need. We assume the username is "myuser." Look at the permissions of the device (this is ubuntu 15.04) odroid@mbrxu3:~/projects/sc$ ls -l /dev/console crw------- 1 ...


2

You might be able to re-detect it without reboot, by unloading / re-loading the correct module (or just un-binding and re-binding the driver). For example: [ 978.527221] sd 11:0:0:1: [sdk] Attached SCSI removable disk #~> echo 11:0:0:1 > /sys/bus/scsi/drivers/sd/unbind #~> echo 11:0:0:1 > /sys/bus/scsi/drivers/sd/bind [ 5572.027119] sd 11:0:0:...


2

No, a UUID can't be guaranteed to be unique. A UUID is just a 128-bit random number. When my computer generates a UUID, there's no practical way it can prevent your computer or any other device in the universe from generating that same UUID at some time in the future. It may not be likely that any two UUIDs will be the same, but they can be. In this case,...



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