Tag Info

Hot answers tagged

49

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


31

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


21

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


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

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


15

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


11

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


11

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


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


10

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


10

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


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

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


9

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.


9

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


8

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


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


8

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


8

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


8

/dev/sgxx is a SCSI-generic device, which allows sending and receiving of raw SCSI commands. When you write to the device, you are expected to start the write with a SCSI header, which defines the operation you wish to do. Writing random data to an sg device is really a bad idea. You'll be sending random SCSI commands, which might not even exist (hence ...


8

Umm, because you overwrite the special file with normal one? What did you expect to happen? dev/null is not a directory, it is a file pointing to a null device. When you mv something to it, you delete the original and replace it with whatever you moved: $ file /dev/null /dev/null: character special $ sudo mv file /dev/null $ file /dev/null /dev/null: ...


8

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


7

For sure. Here are two suggestions: Behind the scenes CLI. Use V4L2VD to create a virtual video device such as /dev/videoVirt1 and pipe through mplayer for the effects. Even some similar examples in the notes. Use a fat desktop program such as webcamstudio to create the pipes and do your skype/broadcast wonders - still with mplayer for the ascii effect ...


7

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


7

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


7

The AT&T/Solaris "Transport Level Interface" (TLI) way of doing TCP/IP networking has special files like "/dev/tcp" or "/dev/udp". The programmer opens that special file to get a socket of an appropriate protocol family. I think that's why you have to have "-lnsl" when compiling a program that uses sockets on Solaris: underneath it all it's TLI.


7

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


6

There are a lot of questions here and I'll do my best to answer them. I'm certain that those more knowledgeable than I will be able to help you further. (I'd appreciate if those people could help me out too.) In *nix, everything is a file. For example, your CD-ROM is a file. /dev - Here you'll find physical devices as well as things you wouldn't normally ...


6

If your system, or just the application you want to record, is directing its output to a sound server, look into recording possibilities for that sound server. For example, on Ubuntu, the official sound server is PulseAudio, which comes with the parec command (from the pulseaudio-utils package ). You may need to convert the output from parec into something ...


6

They show up as SCSI devices because the drivers speak SCSI to the next kernel layer (the generic disk driver). This isn't actually true of all SATA drivers on all kernel versions with all kernel compile-time configurations, but it's common. Even PATA devices can appear as SCSI at that level (again, that depends on the kernel version and kernel compile-time ...



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