Hot answers tagged

99

This is highly platform-dependent. Also different methods may treat edge cases differently (“fake” disks of various kinds, RAID volumes, …). On modern udev installations, there are symbolic links to storage media in subdirectories of /dev/disk, that let you look up a disk or a partition by serial number (/dev/disk/by-id/), by UUID (/dev/disk/by-uuid), by ...


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 "...


54

One reason is that block level access is a bit lower level than ls would be able to work with. /dev/cdrom, or dev/sda1 may be your CD ROM drive and partition 1 of your hard drive, respectively, but they aren't implementing ISO 9660 / ext4 - they're just RAW pointers to those devices known as Device Files. One of the things mount determines is HOW to use ...


51

How about lshw -class disk


50

lsblk will list all block devices. It lends itself well to scripting: $ lsblk -io KNAME,TYPE,SIZE,MODEL KNAME TYPE SIZE MODEL sda disk 149.1G TOSHIBA MK1637GS sda1 part 23.3G sda2 part 28G sda3 part 93.6G sda4 part 4.3G sr0 rom 1024M CD/DVDW TS-L632M lsblk is present in util-linux package and is thus far more universal than proposed ...


50

Nothing is stored in /dev/pts. This filesystem lives purely in memory. Entries in /dev/pts are pseudo-terminals (pty for short). Unix kernels have a generic notion of terminals. A terminal provides a way for applications to display output and to receive input through a terminal device. A process may have a controlling terminal — for a text mode application, ...


49

mknod /dev/null c 1 3 chmod 666 /dev/null Use these command to create /dev/null or use null(4) manpage for further help.


43

Some of these have man pages (in section 4; leave out the final digit(s) and in a few cases such as sda the final letter). For a more definitive, but usually less easy to read answer, look in the kernel documentation. First determine whether the device is a block device or a character device, and its major and minor number. For example $ ls -l /dev/sda brw-...


34

mknod was originally used to create the character and block devices that populate /dev/. Nowadays software like udev automatically creates and removes device nodes on the virtual filesystem when the corresponding hardware is detected by the kernel, but originally /dev was just a directory in / that was populated during install. So yes, in case of a near ...


32

When a program reads or writes data from a file, the requests go to a kernel driver. If the file is a regular file, the data is handled by a filesystem driver and it is typically stored in zones on a disk or other storage media, and the data that is read from a file is what was previously written in that place. There are other file types for which different ...


28

The kernel lists them by name in /sys, both separately in (e.g.) the tree of PCI devices -- although finding them there if you don't know where they are to start with is not simple -- and together via symlinks in /sys/class/net. E.g.: > ls /sys/class/net em1 lo wlp6so Another example: > ls /sys/class/net lo p6s1 wlan0 If you are not sure which is ...


27

Almost all the files under /dev are device files. Whereas reading and writing to a regular file stores data on a disk or other filesystem, accessing a device file communicates with a driver in the kernel, which generally in turn communicates with a piece of hardware (a hardware device, hence the name). There are two types of device files: block devices (...


27

On many devices, the main operations are to send bytes from the computer to a peripheral, or to receive bytes from a peripheral on the computer. Such devices are similar to pipes and work well as character devices. For operations that aren't reading and writing (such as flow control on a serial line), the device provides ad-hoc commands called ioctl. Some ...


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 ...


25

Under many traditional unices, you can recreate devices with their default permissions with the MAKEDEV script. This script is traditionally in /dev but is in /sbin on Ubuntu. Pass it an argument that indicates what devices you want to create; on Ubuntu that's std (you can write MAKEDEV null as well, that creates null as well as a number of other devices). ...


23

The simplest method I know to list all of your interfaces is ifconfig -a EDIT If you're on a system where that has been made obsolete, you can use ip link show


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 ...


20

It writes until the disk is full (usually there is still some space reserved for the root user). But as the pool of random data is limited, this could take a while. If you need a certain amount of random data, use dd. For 1MB: dd if=/dev/random iflag=fullblock of=$HOME/randomFile bs=1M count=1 Other possibilities are mentioned in answers to a related ...


19

The stty utility sets or reports on terminal I/O characteristics for the device that is its standard input. These characteristics are used when establishing a connection over that particular medium. cat doesn't know the baud rate as such, it rather prints on the screen information received from the particular connection. As an example stty -F /dev/ttyACM0 ...


19

Basically, and to put it easily, the operating system needs to know how to access the files on that device. mount is not only "giving you access to the files", it's telling the OS the filesystem the drive has, if it's read only or read/write access, etc. /dev/cdrom is a low-level device, the operating system functions wouldn't know how to access them... ...


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 ...


18

Try the following command : xdotool getmouselocation 2>&1 | sed -rn '${s/x:([0-9]+) y:([0-9]+) .*/\1 \2/p}' See http://www.semicomplete.com/projects/xdotool/


18

You cannot easily do that. You might consider writing your own kernel module providing such a device. I don't recommend that. You could write a tiny C program writing an infinite stream of same bytes on some pipe (or on stdout) or FIFO. You could use tr(1) to read from /dev/zero and translate every 0 byte to somethng else. You could use perhaps yes(1), ...


18

The following bash code is set to work with the byte being representred in binary. However you can easily change it to handle ocatal, decimal or hex by simply changing the radix r value of 2 to 8, 10 or 16 respectively and setting b= accordingly. r=2; b=01111110 printf -vo '\\%o' "$(($r#$b))"; </dev/zero tr '\0' "$o" EDIT - It does handle the full ...


16

hwinfo helps: > hwinfo --disk 21: IDE 00.0: 10600 Disk [Created at block.245] Unique ID: 3OOL.8MZXfAWnuH8 Parent ID: w7Y8.1T_0outZkp6 SysFS ID: /class/block/sda SysFS BusID: 0:0:0:0 SysFS Device Link: /devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0 Hardware Class: disk Model: "Hitachi HTS54322" Vendor: "...


16

If you're writing a real-world program that uses the mouse in Linux, you're most likely writing an X application, and in that case you should ask the X server for mouse events. Qt, GTK, and libsdl are some popular C libraries that provide functions for accessing mouse, keyboard, graphics, timers, and other features needed to write GUI programs. Ncurses is ...


16

The shell will open the device /dev/sdX. All output of the cat command, which ends up being the contents of debian.iso, is written directly to that device. The end result is that debian.iso is written byte-for-byte to the start of the disk underlying /dev/sdX. In effect, the device node makes it appear that the low-level contents of your storage medium ...


16

The files in /dev are actual devices files which UDEV creates at run time. The directory /sys/class is exported by the kernel at run time, exposing the hierarchy of the hardware through sysfs. From the libudev and Sysfs Tutorial excerpt On Unix and Unix-like systems, hardware devices are accessed through special files (also called device files or nodes)...


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. ...



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