Detailed Linux / dev directory
Under Linux , the / dev directory is very important, and various devices are below . Here is a brief summary:
dev is the abbreviation of device. The / dev directory is very important to all users. Because this directory contains all external devices used in the Linux system . But here is not the driver of the external device , which is different from the windows and DOS operating systems. It is actually a port to access these external devices . We can access these external devices very conveniently, no different from accessing a file or a directory.
Linux follows the Unix style and considers all devices as one file.
Regarding some special equipment, I have summarized some:
/ dev / null and / dev / zero: http://www.51testing.com/index.php?uid-225738-action-viewspace-itemid-235339
/dev/tty、/dev/console、/dev/pty、/dev/pts等:http://www.51testing.com/index.php?uid-225738-action-viewspace-itemid-212419
There are two types of device files : block device files (b) and character device files (c)
Device files are generally stored in the / dev directory, and the common device files are explained as follows:
/ dev / hd [at]: IDE device
/ dev / sd [az]: SCSI device
/ dev / fd [0-7]: Standard floppy drive
/ dev / md [0-31]: soft raid device
/ dev / loop [0-7]: local loopback device
/ dev / ram [0-15]: memory
/ dev / null: unlimited data receiving device, equivalent to a black hole
/ dev / zero: unlimited zero resources
/ dev / tty [0-63]: virtual terminal
/ dev / ttyS [0-3]: serial port
/ dev / lp [0-3]: parallel port
/ dev / console: console
/dev/fb[0-31]:framebuffer
/dev/cdrom => /dev/hdc
/dev/modem => /dev/ttyS[0-9]
/dev/pilot => /dev/ttyS[0-9]
/ dev / random: random number device
/ dev / urandom: random number device
(PS: Random number device, I will write a blog to summarize later)
How are the nodes in the / dev directory created?
devf or udev will automatically create it for you.
kobject is the basis of the sysfs file system. udev monitors and detects sysfs to obtain newly created devices.
The role of various directories in the Linux system
/
This is the root directory. There is only one root directory for your computer. Everything, I mean everything starts here. For example: when you type "/ home" in the terminal, you are actually telling the computer to start with / (root directory) before entering the home directory.
/root
This is the directory of the system administrator (root user). For the system, the system administrator is like a god, it can do anything to the system, even including deleting your files. Therefore, please use the root account carefully.
/bin
这里存放了标准的(或者说是缺省的)linux的工具,比如像“ls”、“vi”还有“more”等等。通常来说,这个目录已经包含在你的“path”系统变量里面了。什么意思呢?就是:当你在终端里输入ls,系统就会去/bin目录下面查找是不是有ls这个程序。
/etc
这里主要存放了系统配置方面的文件。举个例子:你安装了samba这个套件,当你想要修改samba配置文件的时候,你会发现它们(配置文件)就在/etc/samba目录下。
/dev
这里主要存放与设备(包括外设)有关的文件(unix和linux系统均把设备当成文件)。想连线打印机吗?系统就是从这个目录开始工作的。另外还有一些包括磁盘驱动、USB驱动等都放在这个目录。
/home
这里主要存放你的个人数据。具体每个用户的设置文件,用户的桌面文件夹,还有用户的数据都放在这里。每个用户都有自己的用户目录,位置为:/home/用户名。当然,root用户除外。
/tmp
这是临时目录。对于某些程序来说,有些文件被用了一次两次之后,就不会再被用到,像这样的文件就放在这里。有些linux系统会定期自动对这个目录进行清理,因此,千万不要把重要的数据放在这里。
/usr
在这个目录下,你可以找到那些不适合放在/bin或/etc目录下的额外的工具。比如像游戏阿,一些打印工具拉等等。/usr目录包含了许多子目录:/usr/bin目录用于存放程序;/usr/share用于存放一些共享的数据,比如音乐文件或者图标等等;/usr/lib目录用于存放那些不能直接运行的,但却是许多程序运行所必需的一些函数库文件。你的软件包管理器(应该是“新立得”吧)会自动帮你管理好/usr目录的。
/opt
这里主要存放那些可选的程序。你想尝试最新的firefox测试版吗?那就装到/opt目录下吧,这样,当你尝试完,想删掉firefox的时候,你就可以直接删除它,而不影响系统其他任何设置。安装到/opt目录下的程序,它所有的数据、库文件等等都是放在同个目录下面。
举个例子:刚才装的测试版firefox,就可以装到/opt/firefox_beta目录下,/opt/firefox_beta目录下面就包含了运行firefox所需要的所有文件、库、数据等等。要删除firefox的时候,你只需删除/opt/firefox_beta目录即可,非常简单。
/usr/local
这里主要存放那些手动安装的软件,即不是通过“新立得”或apt-get安装的软件。它和/usr目录具有相类似的目录结构。让软件包管理器来管理/usr目录,而把自定义的脚本(scripts)放到/usr/local目录下面,我想这应该是个不错的主意。
/media
有些linux的发行版使用这个目录来挂载那些usb接口的移动硬盘(包括U盘)、CD/DVD驱动器等等。
这个文件包含了由md设备驱动程序控制的RAID设备信息。 示例: [root@localhost ~]# cat /proc/mdstat Personalities : unused devices: <none> -------------------------------------------------------------------------------- / proc/meminfo文件 这 个文件给出了内存状态的信息。它显示出系统中空闲内存,已用物理内存和交换内存的总量。它还显示出内核使用的共享内存和缓冲区总量。这些信息的格式和free命令显示的结果类似。 示例: [root@localhost ~]# cat /proc/meminfo MemTotal: 223812 kB MemFree: 3764 kB Buffers: 9148 kB Cached: 92112 kB SwapCached: 364 kB Active: 183640 kB Inactive: 17196 kB HighTotal: 0 kB HighFree: 0 kB LowTotal: 223812 kB LowFree: 3764 kB SwapTotal: 626524 kB SwapFree: 620328 kB Dirty: 12 kB Writeback: 0 kB Mapped: 142880 kB Slab: 12668 kB Committed_AS: 376732 kB PageTables: 2336 kB VmallocTotal: 3907576 kB VmallocUsed: 2968 kB VmallocChunk: 3904224 kB HugePages_Total: 0 HugePages_Free: 0 Hugepagesize: 4096 kB -------------------------------------------------------------------------------- /proc/misc文件 这个文件报告用内核函数misc_register登记的设备驱动程序。 示例: [root@localhost ~]# cat /proc/misc 63 device-mapper 175 agpgart 135 rtc -------------------------------------------------------------------------------- / proc/modules文件 这个文件给出可加载内核模块的信息。lsmod程序用这些信息显示有关模块的名称,大小,使用数目方面的信息。 示例: [root@localhost /]# cat /proc/modules md5 4033 1 - Live 0x10a7f000 ipv6 232577 8 - Live 0x10b0c000 parport_pc 24705 1 - Live 0x10a8b000 lp 11565 0 - Live 0x10a7b000 parport 41737 2 parport_pc,lp, Live 0x10a55000 autofs4 24005 0 - Live 0x10a74000 i2c_dev 10433 0 - Live 0x109d2000 i2c_core 22081 1 i2c_dev, Live 0x10a6d000 sunrpc 160421 1 - Live 0x10a9d000 ipt_REJECT 6465 1 - Live 0x109da000 ipt_state 1857 5 - Live 0x109eb000 ip_conntrack 40693 1 ipt_state, Live 0x10a62000 iptable_filter 2753 1 - Live 0x10896000 ip_tables 16193 3 ipt_REJECT,ipt_state,iptable_filter, Live 0x109ed000 dm_mod 54741 0 - Live 0x109f8000 button 6481 0 - Live 0x10905000 battery 8517 0 - Live 0x109d6000 ac 4805 0 - Live 0x10908000 uhci_hcd 31449 0 - Live 0x109dd000 ehci_hcd 31557 0 - Live 0x10949000 snd_via82xx 27237 2 - Live 0x10953000 snd_ac97_codec 64401 1 snd_via82xx, Live 0x10912000 snd_pcm_oss 47609 0 - Live 0x1093c000 snd_mixer_oss 17217 2 snd_pcm_oss, Live 0x1090c000 snd_pcm 97993 2 snd_via82xx,snd_pcm_oss, Live 0x10923000 snd_timer 29765 1 snd_pcm, Live 0x108ec000 snd_page_alloc 9673 2 snd_via82xx,snd_pcm, Live 0x108bd000 gameport 4801 1 snd_via82xx, Live 0x108a6000 snd_mpu401_uart 8769 1 snd_via82xx, Live 0x108b9000 snd_rawmidi 26725 1 snd_mpu401_uart, Live 0x108e4000 snd_seq_device 8137 1 snd_rawmidi, Live 0x1083b000 snd 54053 11 snd_via82xx,snd_ac97_codec,snd_pcm_oss,snd_mixer_oss,snd_pcm,snd_timer,snd_mpu401_uart,snd_rawmidi,snd_seq_device, Live 0x108f6000 soundcore 9889 2 snd, Live 0x1089b000 via_rhine 23497 0 - Live 0x1089f000 mii 4673 1 via_rhine, Live 0x10893000 floppy 58609 0 - Live 0x108a9000 ext3 116809 1 - Live 0x10875000 jbd 74969 1 ext3, Live 0x10861000 lsmod命令显示结果如下: [root@localhost /]# lsmod Module Size Used by md5 4033 1 ipv6 232577 8 parport_pc 24705 1 lp 11565 0 parport 41737 2 parport_pc,lp autofs4 24005 0 i2c_dev 10433 0 i2c_core 22081 1 i2c_dev sunrpc 160421 1 ipt_REJECT 6465 1 ipt_state 1857 5 ip_conntrack 40693 1 ipt_state iptable_filter 2753 1 ip_tables 16193 3 ipt_REJECT,ipt_state,iptable_filter dm_mod 54741 0 button 6481 0 battery 8517 0 ac 4805 0 uhci_hcd 31449 0 ehci_hcd 31557 0 snd_via82xx 27237 2 snd_ac97_codec 64401 1 snd_via82xx snd_pcm_oss 47609 0 snd_mixer_oss 17217 2 snd_pcm_oss snd_pcm 97993 2 snd_via82xx,snd_pcm_oss snd_timer 29765 1 snd_pcm snd_page_alloc 9673 2 snd_via82xx,snd_pcm gameport 4801 1 snd_via82xx snd_mpu401_uart 8769 1 snd_via82xx snd_rawmidi 26725 1 snd_mpu401_uart snd_seq_device 8137 1 snd_rawmidi snd 54053 11 snd_via82xx,snd_ac97_codec,snd_pcm_oss,snd_mixer_oss,snd_pcm,snd_timer,snd_mpu401_uart,snd_rawmidi,snd_seq_device soundcore 9889 2 snd via_rhine 23497 0 mii 4673 1 via_rhine floppy 58609 0 ext3 116809 1 jbd 74969 1 ext3 -------------------------------------------------------------------------------- / proc/mounts文件 这个文件以/etc/mtab文件的格式给出当前系统所安装的文件系统信息。这个文件也能反映出任何手工安装从而在/etc/mtab文件中没有包含的文件系统。 示例: [root@localhost /]# cat /proc/mounts rootfs / rootfs rw 0 0 /proc /proc proc rw,nodiratime 0 0 none /dev tmpfs rw 0 0 /dev/root / ext3 rw 0 0 none /dev tmpfs rw 0 0 none /selinux selinuxfs rw 0 0 /proc /proc proc rw,nodiratime 0 0 /proc/bus/usb /proc/bus/usb usbfs rw 0 0 /sys /sys sysfs rw 0 0 none /dev/pts devpts rw 0 0 none /dev/shm tmpfs rw 0 0 none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0 sunrpc /var/lib/nfs/rpc_pipefs rpc_pipefs rw 0 0 -------------------------------------------------------------------------------- /proc/pci文件 这个文件给出PCI设备的信息。用它可以方便地诊断PCI问题。你可以从这个文件中检索到的信息包括诸如IDE接口或USB控制器这样的设备,总线,设备和功能编号,设备延迟以及IRQ编号。 示例: [root@localhost /]# cat /proc/pci PCI devices found: Bus 0, device 0, function 0: Class 0600: PCI device 1106:3116 (rev 0). Master Capable. Latency=8. Prefetchable 32 bit memory at 0xe0000000 [0xe7ffffff]. Bus 0, device 1, function 0: Class 0604: PCI device 1106:b091 (rev 0). Master Capable. No bursts. Min Gnt=12. Bus 0, device 16, function 2: Class 0c03: PCI device 1106:3038 (rev 12. IRQ 5. Master Capable. Latency=32. I/O at 0xec00 [0xec1f]. Bus 0, device 16, function 1: Class 0c03: PCI device 1106:3038 (rev 12. IRQ 3. Master Capable. Latency=32. I/O at 0xe800 [0xe81f]. Bus 0, device 16, function 0: Class 0c03: PCI device 1106:3038 (rev 12. IRQ 11. Master Capable. Latency=32. I/O at 0xe400 [0xe41f]. Bus 0, device 16, function 3: Class 0c03: PCI device 1106:3104 (rev 130). IRQ 10. Master Capable. Latency=32. Non-prefetchable 32 bit memory at 0xdfffff00 [0xdfffffff]. Bus 0, device 17, function 0: Class 0601: PCI device 1106:3177 (rev 0). Bus 0, device 17, function 1: Class 0101: PCI device 1106:0571 (rev 6). IRQ 255. Master Capable. Latency=32. I/O at 0xfc00 [0xfc0f]. Bus 0, device 17, function 5: Class 0401: PCI device 1106:3059 (rev 80). IRQ 5. I/O at 0xe000 [0xe0ff]. Bus 0, device 18, function 0: Class 0200: PCI device 1106:3065 (rev 116). IRQ 11. Master Capable. Latency=32. Min Gnt=3.Max Lat=8. I/O at 0xdc00 [0xdcff]. Non-prefetchable 32 bit memory at 0xdffffe00 [0xdffffeff]. Bus 1, device 0, function 0: Class 0300: PCI device 5333:8d04 (rev 0). IRQ 11. Master Capable. Latency=32. Min Gnt=4.Max Lat=255. Non-prefetchable 32 bit memory at 0xdfe80000 [0xdfefffff]. Prefetchable 32 bit memory at 0xd0000000 [0xd7ffffff]. -------------------------------------------------------------------------------- / proc/stat文件 这个文件包含的信息有CPU利用率,磁盘,内存页,内存对换,全部中断,接触开关以及赏赐自举时间(自1970年1月1日起的秒数)。 示例: [root@localhost /]# cat /proc/stat cpu 31994 3898 7161 381600 15254 451 0 cpu0 31994 3898 7161 381600 15254 451 0 intr 4615930 4404290 3364 0 0 12 0 7 0 2 0 0 12618 112114 0 44142 39381 ctxt 1310498 btime 1148891913 processes 4249 procs_running 4 procs_blocked 0 -------------------------------------------------------------------------------- /proc/uptime文件 这个文件给出自从上次系统自举以来的秒数,以及其中有多少秒处于空闲。这主要供uptime程序使用。比较这两个数字能够告诉你长期来看CPU周期浪费的比例。 示例: [root@localhost /]# cat /proc/uptime 4477.04 4021.10 -------------------------------------------------------------------------------- / proc/version文件 这个文件只有一行内容,说明正在运行的内核版本。可以用标准的编程方法进行分析获得所需的系统信息。 示例: [root@localhost /]# cat /proc/version Linux version 2.6.9-1.667 ( [email protected]) (gcc version 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)) #1 Tue Nov 2 14:41:25 EST 2004 proc/net子目录 此目录下的文件描述或修改了联网代码的行为。可以通过使用arp,netstat,route和ipfwadm命令设置或查询这些特殊文件中的许多文件。 示例: [root@localhost /]# ls /proc/net anycast6 ip_conntrack mcfilter6 rt6_stats tcp arp ip_conntrack_expect netlink rt_acct tcp6 dev ip_mr_cache netstat rt_cache udp dev_mcast ip_mr_vif packet snmp udp6 dev_snmp6 ip_tables_matches psched snmp6 unix if_inet6 ip_tables_names raw sockstat wireless igmp ip_tables_targets raw6 sockstat6 igmp6 ipv6_route route softnet_stat ip6_flowlabel mcfilter rpc stat -------------------------------------------------------------------------------- 以下摘要介绍此目录下文件的功能: arp 转储每个网络接口的arp表中dev包的统计 dev 来自网络设备的统计 dev_mcast 列出二层(数据链路层)多播组 igmp 加入的IGMP多播组 netlink netlink套接口的信息 netstat 网络流量的多种统计。第一行是信息头,带有每个变量的名称。接下来的一行保存相应变量的值 raw 原始套接口的套接口表 route 静态路由表 rpc 包含RPC信息的目录 rt_cache 路由缓冲 snmp snmp agent的ip/icmp/tcp/udp协议统计;各行交替给出字段名和值 sockstat 列出使用的tcp/udp/raw/pac/syc_cookies的数量 tcp TCP连接的套接口 udp UDP连接的套接口表 unix UNIX域套接口的套接口表 -------------------------------------------------------------------------------- 示例:[root@localhost /]# cat /proc/net/route Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window IRTT eth0 0035C2DA 00000000 0001 0 0 0 80FFFFF0 eth0 0000FEA9 00000000 0001 0 0 0 0000FFF0 eth0 00000000 0135C2DA 0003 0 0 0 00000000 -------------------------------------------------------------------------------- [root@localhost /]# cat /proc/net/tcp sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode 0: 00000000:8000 00000000:0000 0A 00000000:00000000 00:00000000 00000000 29 0 9525 1 0dde7500 3000 0 0 2 -1 1: 00000000:006F 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 9484 1 0dde79e0 3000 0 0 2 -1 2: 0100007F:0277 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 10049 1 0a8e3a00 3000 0 0 2 -1 3: 0100007F:14D7 00000000:0000 0A 00000000:00000000 00:00000000 00000000 99 0 9847 1 0dde7020 3000 0 0 2 -1 4: 0100007F:0019 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 10286 1 0a8e3520 3000 0 0 2 -1 -------------------------------------------------------------------------------- [root@localhost /]# cat /proc/net/arp IP address HW type Flags HW address Mask Device 218.194.53.1 0x1 0x2 00:0D:BC:78:07:3F * eth0 -------------------------------------------------------------------------------- [root@localhost /]# cat /proc/net/udp sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode 0: 00000000:8000 00000000:0000 07 00000000:00000000 00:00000000 00000000 29 0 9520 2 0b4ef7c0 105: 00000000:14E9 00000000:0000 07 00000000:00000000 00:00000000 00000000 99 0 10284 2 0b4ef040 111: 00000000:006F 00000000:0000 07 00000000:00000000 00:00000000 00000000 0 0 9483 2 0b4efcc0 116: 00000000:02F4 00000000:0000 07 00000000:00000000 00:00000000 00000000 0 0 9511 2 0b4efa40 119: 00000000:0277 00000000:0000 07 00000000:00000000 00:00000000 00000000 0 0 10050 2 0b4ef2c0 -------------------------------------------------------------------------------- /proc/scsi子目录 此目录下包含一个列出了所有检测到的SCSI设备的文件,并且为每种控制器驱动程序提供一个目录,在这个目录下又为已安装的此种控制器的每个实例提供一个子目录。 示例: 由于本人的机器没有SCSI设备,顾暂时无法提供示例。 -------------------------------------------------------------------------------- /proc/sys子目录 在此目录下有许多子目录。此目录中的许多项都可以用来调整系统的性能。这个目录包含信息太多,无法介绍全部。只在示例中展示目录下的一些文件。 示例:[root@localhost /]# ls /proc/sys debug dev fs kernel net proc sunrpc vm -------------------------------------------------------------------------------- [root@localhost ~]# ls /proc/sys/fs aio-max-nr dentry-state file-nr lease-break-time overflowgid aio-nr dir-notify-enable inode-nr leases-enable overflowuid binfmt_misc file-max inode-state mqueue quota -------------------------------------------------------------------------------- [root@localhost ~]# ls /proc/sys/kernel acct hotplug panic sem cad_pid modprobe panic_on_oops shmall cap-bound msgmax pid_max shmmax core_pattern msgmnb print-fatal-signals shmmni core_uses_pid msgmni printk sysrq ctrl-alt-del ngroups_max printk_ratelimit tainted domainname osrelease printk_ratelimit_burst threads-max exec-shield ostype pty vdso exec-shield-randomize overflowgid random version hostname overflowuid real-root-dev -------------------------------------------------------------------------------- [root@localhost ~]# ls /proc/sys/net core ethernet ipv4 ipv6 unix -------------------------------------------------------------------------------- [root@localhost sys]# ls /proc/sys/vm block_dump laptop_mode nr_pdflush_threads dirty_background_ratio legacy_va_layout overcommit_memory dirty_expire_centisecs lower_zone_protection overcommit_ratio dirty_ratio max_map_count page-cluster dirty_writeback_centisecs min_free_kbytes swappiness hugetlb_shm_group nr_hugepages vfs_cache_pressure -------------------------------------------------------------------------------- [root@localhost sys]# ls /proc/sys/net/ipv4 conf tcp_fack icmp_echo_ignore_all tcp_fin_timeout icmp_echo_ignore_broadcasts tcp_frto icmp_ignore_bogus_error_responses tcp_keepalive_intvl icmp_ratelimit tcp_keepalive_probes icmp_ratemask tcp_keepalive_time igmp_max_memberships tcp_low_latency igmp_max_msf tcp_max_orphans inet_peer_gc_maxtime tcp_max_syn_backlog inet_peer_gc_mintime tcp_max_tw_buckets inet_peer_maxttl tcp_mem inet_peer_minttl tcp_moderate_rcvbuf inet_peer_threshold tcp_no_metrics_save ip_autoconfig tcp_orphan_retries ip_conntrack_max tcp_reordering ip_default_ttl tcp_retrans_collapse ip_dynaddr tcp_retries1 ip_forward tcp_retries2 ipfrag_high_thresh tcp_rfc1337 ipfrag_low_thresh tcp_rmem ipfrag_secret_interval tcp_sack ipfrag_time tcp_stdurg ip_local_port_range tcp_synack_retries ip_nonlocal_bind tcp_syncookies ip_no_pmtu_disc tcp_syn_retries neigh tcp_timestamps netfilter tcp_tso_win_divisor route tcp_tw_recycle tcp_abort_on_overflow tcp_tw_reuse tcp_adv_win_scale tcp_vegas_alpha tcp_app_win tcp_vegas_beta tcp_bic tcp_vegas_cong_avoid tcp_bic_fast_convergence tcp_vegas_gamma tcp_bic_low_window tcp_westwood tcp_dsack tcp_window_scaling tcp_ecn tcp_wmem -------------------------------------------------------------------------------- [root@localhost sys]# cat /proc/sys/kernel/shmall 2097152 -------------------------------------------------------------------------------- [root@localhost sys]# cat /proc/sys/kernel/osrelease 2.6.9-1.667 -------------------------------------------------------------------------------- 总结:/proc文件系统包含了大量的有关当前系统状态的信息。proc的手册页中也有对这些文件的解释文档。把文件和分析这些文件的工具产生的输出进行比较能够更加清晰地了解这些文件。 |