![]() |
|
[Noob Friendly] Understanding /dev - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Computing (https://hackforums.net/forumdisplay.php?fid=88) +---- Forum: Linux (https://hackforums.net/forumdisplay.php?fid=85) +---- Thread: [Noob Friendly] Understanding /dev (/showthread.php?tid=5007195) |
[Noob Friendly] Understanding /dev - XMR - Oct 1, 2015 This thread is meant for mainly new Linux users to understand what is inside the /dev folder and what uses they each have. I will briefly explain some of the files in /dev and what each file can be used for, and whether it should be used at all. The /dev folder (dev short for device) contains special device files that should generally be left alone, but it is useful to have some understanding on what they're doing there. Again, this is just a shitty guide to some files in /dev. Constructive criticism welcome, but don't be an asshole. Please don't make any stupid ass posts like "Why would people need this?" either If something here is incorrect or difficult to understand, please tell me! These files can be read from and written to using the dd command, like so: dd if=<input file> of=<output file> bs=<block size> count=<blocks to write> If count is not specified, dd will continue reading/writing until end of file. /dev/block/ - Contains links to devices that handle data in blocks. /dev/char/ - Contains links to devices that handle data character by character rather than in blocks. /dev/console - System console (what you see when booting your system), view by running the xconsole command. /dev/cdrom | /dev/cdrw | /dev/dvd | /dev/dvdrw - Links to your CD/DVD drive at /dev/sr0. Generally shouldn't be tampered with. /dev/disk/ - Contains links to your hard disks and USB drives. /dev/fb* - Frame buffers, more info on that here. Basically a memory buffer for GUI frames. /dev/full - When written to, will return a "no space left on device" or "device full" type error. When read from, will produce a continuous stream of zero value bytes. Attempting to write 1 byte to /dev/full. Notice the error and bytes copied. Code root@arccotangent-kali:/dev# dd if=/dev/zero of=/dev/full bs=1 count=1/dev/full hexdump output. Note the ^C interruption at the end. Code root@arccotangent-kali:/dev# hexdump /dev/full/dev/mem - All data stored in RAM. You can view memory by running memdump OR memdump | hexdump or hexdump /dev/mem. You can also save RAM to a file for later viewing with dd if=/dev/mem of=<output file> bs=2M. /dev/null - When written to, will destroy all data written to it. Useful for trashing data. When read from, will produce no output. /dev/random - A non-deterministic random byte generator. Non-deterministic means it is impossible to predict its output based on its current state. When read from, will produce a small, non-continuous amount of random bytes. Random bytes are generated from environmental noise collected from device drivers and sources such as the time between keystrokes. Some /dev/random output. This command ran for about 7 seconds before termination. All bytes were printed at once. Code root@arccotangent-kali:/dev# hexdump /dev/random/dev/sd** - Disks sorted by letters (eg. /dev/sda, /dev/sdb), and each partition on said disks sorted by numbers (eg. /dev/sda0, /dev/sda1, /dev/sda2). These files allow raw I/O to disks, and as such, are often used to create bootable USB drives. Generally shouldn't be tampered with unless creating bootable drives. WARNING: Writing data to the wrong disk will corrupt data on it and may prevent your system from booting properly, if at all. /dev/stdout | /dev/stdin | /dev/stderr - Standard output, input, and error streams, respectively. /dev/tty* - Terminals. You should know what a terminal is if you use Linux. /dev/urandom - Similar to /dev/random. When read from, will produce a continuous stream of random bytes with potentially less entropy. To save some random bytes to a file, run dd if=/dev/urandom of=<output file> bs=<byte count> count=1. Some /dev/urandom output, trimmed. This command ran for about 7 seconds before termination. Output was an continuous stream of random data. Code root@arccotangent-kali:/dev# hexdump /dev/urandom/dev/video* - Video devices such as webcams. /dev/watchdog - When read from, will reboot your system. Can only be read by root. /dev/zero - When written to, will destroy all data written to it like /dev/null. When read from, will produce a continuous stream of zero value bytes. Useful if you need a file of arbitrary size but don't care about its contents. Copying from /dev/zero is much faster than others, as seen below. /dev/zero output. Same as /dev/full, and ran for about 3 seconds before termination. Code root@arccotangent-kali:/dev# hexdump /dev/zeroCopying from /dev/zero vs /dev/urandom to /dev/null. Note the write speed difference. Code root@arccotangent-kali:/dev# dd if=/dev/zero of=/dev/null bs=32M count=1Code root@arccotangent-kali:/dev# dd if=/dev/urandom of=/dev/null bs=32M count=1* - tuki - Oct 2, 2015 Sweet overview. Since you mentioned /dev/block you should also add /dev/char. |