Tag Info

Hot answers tagged

62

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


34

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


30

How about lshw -class disk


25

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


24

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


21

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


18

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


18

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


17

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/


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


14

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


13

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


13

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


12

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


12

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


11

@Giles says this is highly platform-dependent. Here's one such example. I'm running a CentOS 5.5 system. This system has 4 disks and a 3ware RAID controller. In my case, lshw -class disk, cat /proc/scsi/scsi and parted --list shows the RAID controller (3ware 9650SE-4LP). This doesn't show the actual disks: only shows the 3ware RAID controller which ...


11

Making /dev/null a named pipe is probably the easiest way. Be warned that some programs (sshd, for example) will act abnormally or fail to execute when they find out that it isn't a special file (or they may read from /dev/null, expecting it to return EOF). # Remove special file, create FIFO and read from it rm /dev/null && mkfifo -m622 /dev/null ...


11

Run udevadm info -a -n /dev/sda and parse the output. You'll see lines like DRIVERS=="ahci" for a SATA disk using the ahci driver, or DRIVERS=="usb-storage" for an USB-connected device. You'll also be able to display vendor and model names for confirmation. Also, ATTR{removable}=="1" is present on removable devices. All of this information can also ...


11

Looking at the source code for mv, http://www.opensource.apple.com/source/file_cmds/file_cmds-220.7/mv/mv.c : /* * If rename fails because we're trying to cross devices, and * it's a regular file, do the copy internally; otherwise, use * cp and rm. */ if (lstat(from, &sb)) { warn("%s", from); return (1); } return (S_ISREG(sb.st_mode) ? ...


11

There are various alternatives to udev out there. Seemingly Gentoo can use something called mdev. Another option would be to attempt to use udev's predecessor devfsd. Finally, you can always create all the device files you need with mknod. Note that with the latter there is no need to create everything at boot time since the nodes can be created on disk and ...


10

Using udev: You can get useful information querying udev (on systems that use it - almost all desktop-type Linuxes for sure). For instance, if you want to know which attached drive is associated with /dev/sdb, you can use: udevadm info --query=property --name=sdb It will show you a list of properties of that device, including the serial ...


10

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


10

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


10

One more option is xinput. For instance, xinput test 8 would write motion a[0]=496 a[1]=830 motion a[0]=496 a[1]=829 motion a[0]=496 a[1]=832 motion a[0]=496 a[1]=834 upon mouse movement, where "8" is my mouse device number. Use xinput --list to find out the number of your mouse among devices.


10

Moving a file to the location of an already existing file replaces the existing file. In this case the /dev/null device file is replaced, just as any normal file would be. To avoid this use the -i (interactive, warns before overwriting) or -n (no clober) option for mv. /dev/null only performs its special function as a bit-bucket then the device is opened as ...


9

I'm running fedora 14 and lshw is not available here (at least not by default). However in my case, I used fdisk -l command (as a root user) to get the following output: Disk /dev/sda: 8589 MB, 8589934592 bytes 255 heads, 63 sectors/track, 1044 cylinders, total 16777216 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes ...


9

On the systems I've looked at, /dev/root is a symlink to the real device, so readlink /dev/root (or readlink -f /dev/root if you want the full path), will do it.


9

Yes - either directly or as symlinks - that is what /dev/ is for. For various purposes: sometimes for compatibility between naming schemes, sometimes it is necessary for the working environment - as in the example of /dev/stdin. This does not point statically to /dev/pts/2 or any other - just switch to another terminal and you'll see. /dev/stdin is the ...


9

The walk is over the different software components (drivers) that handle the device; this corresponds by and large to the hardware devices and buses that are involved in connecting to the device. This is mostly unrelated to the physical arrangement of the devices: most of them are inside the same chip anyway. Taking this example from the top: First we ...


8

Yes. Actually there are lots of ways. You can setup a sound dummy sound card device that you can just rip the data out of the device ... however this isn't a very useful format. More useful to you is something like the arecord utility that allows you to evesdrop on the alsa output stream and save it to several known formats. Basically anything that you can ...



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