Tag Info

Hot answers tagged

56

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


33

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


27

How about lshw -class disk


24

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


22

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


17

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


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

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

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


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


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

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


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

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

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

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

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


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

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

Parse the root= parameter from /proc/cmdline.


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

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


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

No. You can export a device file through NFS or some other network filesystems. But the meaning of the device file is dependent on the machine where you open it. If you export /dev/video0 over NFS from a server machine to a client machine, the client machine just sees “character device 81:0”, and interprets it as its own video capture device. The client ...


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



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