linux目录结构图

[root@localhost ~]# tree -L 1 /

/

├── bin

├── boot

├── dev

├── etc

├── home

├── lib

├── lost+found

├── media

├── mnt

├── opt

├── proc

├── root

├── sbin

├── selinux

├── srv

├── sys

├── tmp

├── usr

└── var

linux目录结构常用命令详细总结_software

1、/- 根目录

存放系统相关的程序,也就是At&t开发的Unix程序。每一个文件和目录从根目录开始。只有root用户具有该目录下的写权限。

2、/usr 目录

存放Unix系统商(比如IBM 和 HP)开发的程序。有关usr的定义,我们根据存放的数据反推,可以理解为usr,当然有的文章说是unix software resource,但是老师在FHS目录层次标准中未查到以上的两种说法。因此,上述两种说法都是为了记忆而定,纠结到底是哪个无太大意义。

3、/usr/local 目录

存放用户自己安装的程序,相当于c:/program files。一般编译软件的时候默认路径,yum或rpm包安装就不是这里了。

4、/opt 目录

在某些系统,用于存放第三方厂商开发的程序,所以取名为option,意为“选装”。

5、/bin 目录

(Essential user command binaries(for use by all users)),常用二进制命令所在的目录。比如ls、cp、mkdir、rm、cut等命令:/bin目录和/usr/bin类似。

[root@localhost ~]# which cat

/bin/cat

[root@localhost ~]# which mkdir

/bin/mkdir

There must be no subdirectories in /bin

The following commands,or symbolic links to commands,are required in /bin.

Command description

cat      --->concatenate files to standard output

chgrp    --->change file group ownership

chmod    --->change file access permissions

chown    --->change file owner and group

cp       --->copy files and directories

date     --->print or set the system data and time

dd       --->convert and copy a file

df       --->report filesystem disk space usage

dmesg    --->print or control the kernel message buffer

echo     --->display a line of text

false    --->do nothing,unsuccessfully

hostname --->show or set the system's host name

kill     --->send signals to processes

ln       --->make links between files

login    --->begin a session on the system

ls       --->list directory contents

mkdir    --->make directories

mknod    --->make block or character special files

more     --->page through text

mount    --->mount a filesystem

mv       --->move/rename files

ps       --->report process status

pwd      --->print name of current working directory

rm       --->remove files or directories

rmdir    --->remove empty directories

sed      --->The 'sed' stream editor

sh       --->The Bourne command shell

stty     --->change and print terminal line settings

su       --->change user ID

sync     --->flush filesystem buffers

true     --->do nothing, successfully

umount   --->unmount file systems

uname    --->print system information

6、/boot 目录

(Static files of the boot loader)Linux 的内核及引导系统程序所需的文件目录。安装系统分区的时候一般要分一个boot分区。常见分区:/boot 128M  swap内存的1.5倍 /全给。The operating system kernel must be located in eithe /or /boot

[root@localhost man]# ll /boot/
总用量 25597
-rw-r--r--. 1 root root   111786 7月  23 2015 config-2.6.32-573.el6.i686
drwxr-xr-x. 3 root root     1024 3月   8 05:26 efi
drwxr-xr-x. 2 root root     1024 3月   8 05:31 grub
-rw-------. 1 root root 19754536 3月   8 05:31 initramfs-2.6.32-573.el6.i686.img
drwx------. 2 root root    12288 3月   8 05:23 lost+found
-rw-r--r--. 1 root root   202247 7月  23 2015 symvers-2.6.32-573.el6.i686.gz
-rw-r--r--. 1 root root  2034619 7月  23 2015 System.map-2.6.32-573.el6.i686
-rwxr-xr-x. 1 root root  4081728 7月  23 2015 vmlinuz-2.6.32-573.el6.i686
[root@localhost man]# LANG=en
[root@localhost man]# tree /boot

7、/dev 目录

(Device files)设备文件的目录,比如声卡、磁盘、光驱......。The following devices must exist under /dev

/dev/null(cat /dev/null >/oldboy/test.txt 清空文件的方法)

All date written to this.device is discarded. A read from this device will return an EOF condition

/dev/zero

This device is a source of zeroed out data.All data written to this discarded.A read from this

/dev/tty

This device is a synonym for the controlling terninal of a process.Once the device

8、/etc 目录

(Host-specific system configuraation)

(1)二进制安装包(yum,rpm)的配置文件默认路径和

exports     --->NFS filesystem access control list(optional)

fstab       --->Static information about filesystems(optional)

hosts       --->Static information about host names(optional)

inittab     --->Configuration file for init(optional)

issue       --->Pre-login message and identification file(optional)

ld.so.conf  --->List of extra directories to search for shared libraries(optional)

motd        --->Post-login message of the day file(optional)

networks    --->Static information about network names(optional)

passwd      --->The password file(optional)

profile     --->Systemwide initialization file for sh shell logins(optional)

resolv.conf --->Resolver configuration file(optional)

services    --->Port names for network services(optional)

syslog.conf --->Configuration file for syslogd(optional)

(2)服务启动命令存放的目录/etc/init.d/(yum,rpm)。

[root@localhost man]# ls -l /etc/init.d
lrwxrwxrwx. 1 root root 11 Mar  8 05:25 /etc/init.d -> rc.d/init.d

9、/home 目录

(User home directories(optional))普通用户的家目录默认数据存放目录。

10、/lib  目录

(Essential shared libraries and kernel modules)库存文件存放目录

The /lib directory contains those shared library p_w_picpaths needed to boot the system and run the commands in the root filesystem,ie.by binaries in/bin and /sbin

[root@localhost ~]# ll /lib
lib/ lib64
[root@localhost ~]# ll /lib
lib/ lib64

/lib64 and /lib32: 64/32-bit libraries(architecture dependent)

The 64-bit architectures PPC64.sparc64 and AMD64 must place 64-bit libraries in /lib64 and 32-bit

(or 31-bit on s390)libraries in/lib

The 64-BIT ARCHITECTURE la64 MUST PLACE 64-bit libraries in /lib

11、lost+found 目录

在ext3文件系统中,当系统意外崩溃或机器意外关机,会产生一些文件碎片在这里。当系统在开机启动的过程中fsck工具会检查这里,并修复已经损坏的文件系统。当系统发生问题,可能会有文件被移支这个目录中,可能需要用手工的方式来修复,或移到文件到原来的位置上。

12、/mnt 目录

(Mount point for mounting a filesystem temporarily)一般是用于临时挂载目录的,比如有edrom,u盘等目录。直接插入光驱无法使用,要先挂载后使用。挂载点-->文件系统的(设备)入口。

13、/opt(option) 目录

(Add-on application software packages)表示的是可选择的意思,有些软件包也会被安装在这里,也就是自定义软件包,我们自己编译的软件包,就可以安装在这个目录中;通过源码包安装的软件,可以通过./configure --prefix=/opt/目录,非必须这样,视习惯或规范而定。

14、/proc  目录

Kernel and process information virtual filesystem

The proc filesystem is the de-facto standard Linux method for handling process and system information,rather than /dev/kmem and other similar methods. We strongly encourage this for the storage and retrieval of process information as well as other kernel and memory information.

操作系统运行时,进程信息及内核信息(比如cpu、硬盘分区、内存信息等)存放在这里。/proc目录伪装的文件系统proc的挂载目录,proc 并不是真下的文件系统,它的定义可以参见/etc/fstab。

[root@localhost ~]# grep proc /etc/fstab
proc                    /proc                   proc    defaults        0 0
[root@localhost ~]# cat /proc/loadavg
0.00 0.00 0.00 1/137 1785

比较常见的/proc下面的内容:

cat /proc/meminfo
cat /proc/cpuinfo
cat /proc/loadavg

15、/root  目录

(Home directory for the root user (optional))Linux超级权限用户root的家目录;win32管理员administrator。

16、/sbin  目录

(Essential system binaries)大多是涉及系统管理的命令的存放,是超级权限用户root的可执行命令存放地,这个目录和/usr/sbin;/usr/X11R6/sbin或/usr/local/sbin目录是相似的;

Command Description

fdisk       --->Partition table manipulator(optional)

fsck        --->File system check and repair utility(optional)

halt        --->Command to stop the system(optional)

ifconfig    --->Configure a network interface(optional)

init        --->lnitatial process(optional)

mkfs        --->Command to build a filesystem(optional)

mkfs.*      --->Command to build a specific(optional)

mkswap      --->Command to set up a swap area(oaptional)

reboot      --->Command to reboot the system(optional)

route       --->IP routing table utility(optional)

swapon      --->Enable paging and swapping(optional)

swapoff     --->Disable paging and swapping(optional)

Linux systems place these additional files into /sbin

  • Second extended filesystem commands(optiona);

  • badblocks

  • dumpe2fs

  • e2fsck

  • mke2fs

  • mklost+found

  • tune2fs

特别提示:对于5.X的系统,直接ifconfig是无法出结果的。

17、/tmp  目录

(Temporary files)临时文件目录,有时用户运行程序的时候,会产生临时文件。/tmp就用来存放临时文件的,权限比较特殊。/var/tmp目录和这个目录相似。

[root@localhost ~]# ls -ld /tmp/
drwxrwxrwt. 3 root root 4096 Jul 29 22:29 /tmp/

18、/usr  目录

(Secondary hierarchy)这个是系统存放程序的目录,比如命令、帮助文件等。这个目录下有很多的文件和目录。当我们安装一个Linux发行版官方提供的软件包时,大多安装在这里。

/usr is the second major section of the filesystem./usr is shareable,read-only data.That means that /usr should be shareable between various FHS-compliant hosts and must not be written to.Any information that is host-specific or varies with time is stored elsewhere.Large software packages must not use a direct subdirectory under the /usr hierarchy.

如果有涉及服务器配置文件的,会把配置文件安装在/etc 目录中。

Directory Description

/usr/bin        --->Most user commands 用户可执行文件目录

/usr/include    --->Header files included by C programs 程序的头文件存放目录

/usr/lib        --->Libraries

/usr/local      --->Local hierarchy(empty after main installation)

/usr/local/sbin

/usr/local/bin

/usr/sbin       --->Non-vital system binaries

/usr/share      --->Architecture-independent data

/usr/share/fonts  --->字体目录

/usr/share/man    --->帮助目录

/user/src:Source code(optional)<---程序源码目录

19、/var  目录

(Variable data)这个目录的内容是经常变动的,我们可以理解为vary的缩写,/var 下有/var/log 这是用来存放系统日志的目录,系统日志路径/var/log/messages。/var/www目录是定义Apache服务器站点存放目录;/var/lib用来存放一些库文件,比如MySQL的,以及MySQL数据库的存放地;

Directory           Description

/var/cache      --->Application cache data

/var/lib        --->Variable state information

/var/local      --->Variable data for /usr/local

/var/lock       --->Lock files

/var/log        --->Log files and directories

/var/log/lastlog   --->record of last login of eachuser

/var/log/messages   --->system messages form syslogd(系统日志文件)

/var/log/secure  --->system secure messages

/var/log/wtmp      --->record of all logins and logouts

/var/opt        --->Variable data for /opt

/var/run        --->Data relevant to running processes

                --->Run-time variable data

/var/spool      --->Application spool data

/var/spool/cron:cron and at jobs(定时任务的配置文件路径)

This directory contains the cron and at programs.

/var/tmp        --->Temporary files preserved between system reboots

总的小结:

/dev/   设备目录

/etc/   配置文件以及服务启动的目录

/proc   显示内核及进程信息虚拟文件系统

/tmp    临时文件目录

/home   普通用户家目录

/var    变化目录,一般日志文件的目录。

/usr    用户程序,及数据,帮助文件等的目录。

/bin和/sbin和/usr/sbin    用户命令的目录

Directory               Description

bin                     Essential  command binaries

boot                    Static files of the boot loader

dev                     Device files

etc                     Host-specific system configuration

lib                     Essential shared libraries and kernel modules

media                   Mount point for removeable media

mnt                     Mount point for mounting a filesystem temporarily

opt                     Add-on application software packages

sbin                    Essential system binaries

srv                     Data for services provided by this system

tmp                     Temporary files

usr                     Secondary hierarchy

var                     Variable data

网络

  1. ifconfig  显示网络接口以及相应的IP地址。ifconfig可用于设置网络接口

  2. ifup eth0  运行eth0接口

  3. ifdown eth0  关闭eth0接口

  4. iwconfig     显示无线网络接口

  5. route        显示路由表。route还可以用于修改路由表

  6. netstat      显示当前的网络连接状态。

  7. ping IP      发送ping包到地址IP

  8. traceroute IP   探测前往地址IP的路由路径

  9. dhclient      向DHCP主机发送DHCP请求,以获得IP地址以及其他设置信息

  10. host domain   DNS查询,寻找域名domain对应的IP

  11. host IP       反向DNS查询

  12. wget url      使用wget下载url指向的资源

  13. wget -m url    镜像下载

进程

  1. top   显示进程信息,并实时更新

  2. ps    显示当前shell下的进程

  3. ps - lu username  显示用户username的进程

  4. ps - ajx  以比较完整的格式显示所有的进程

  5. kill PID   杀死PID进程(PID为Process ID)

重要子目录的说明                        

1、/etc/sysconfig/network-scripts/ifc-eth0

#->配置网络地址及GW等,使得网卡生效

(1)重启网卡/etc/init.d/network restart (所有网卡)

(2)ifdown eth0&&ifup eth0。只针对eth0网卡

    通过setup-“network configuration” 修改网卡配置就是在改这个文件。

设置文件ifcfg-interface-name包含了初始化接口所需的大部分周详信息。其中interface-name将根据网卡的类型和排序而不同,0表示第一块网卡,1表示第二块网卡,而ppp0则表示第一个point-to-poirt protocol网络接口。在ifcfg文件中定义的各项目取决于接口类型。

下面的值比较常见:

  • DEVICE=name, 其中,name是物理设备名。

  • IPADDR=addr,其中,addr是IP地址。

  • NETMASK=mask,其中,mask是网络掩码值。

  • NETWORK=addr,其中addr是网络地址

  • BROADCAST=addr,其中addr是广播地址

  • GATEWAY=addr,其中addr是网关地址

  • ONBOOT=answer,answer是yes(引导时激活设备)或no(引导时不激活设备)

  • USERCTL=answer,其中answer是yes(非root用户能控制该设备)或no

  • BOOTPROTO=proto,其中proto取下列值之一:none引导时不使用协议;static静态分配地址;bootp,使用BOOTP协议,或dhcp,使用DHCP协议。

2、/etc/resolv.conf

   #--->设置linux本地的客户端DNS的文件,DNS可以实现域名和IP的互相解析。

3、/etc/hosts

   #--->设定用户IP与名字(或域名)的对应解析表,相当于本地LAN内DNS。

   #--->类似C:\WINDOWS\system32\drivers\etc\hosts,LAN内IP域名解析文件。开发、测试   时常用,英文hosts-The static table lookup for host names。host 的解析在机房的服务器互相调用中也会常用,如门户网站的解析真实案例。

   1、用于通过域名测试。

   2、服务器之间的调用可以用域名(内部的DNS).

4、/etc/sysconfig/network

  #--->或修改机器名及网卡启动,网关等配置。

5、/etc/fstab

  #--->记录开机要mount的文件系统的一个文件。/etc/rc.local

6、/etc/rc.local

       存放开机自启动程序命令的文件。(chkconfig只能管理yum/rpm安装的程序的启动服务)

7、/etc/inittab

  #--->设定系统启动时 init 进程将把系统设置成什么样的 runlevel及加载相关的启动文件设置。Linux开机启动流程

8、/etc/exports

  #-->设定NFS网络文件系统用的配置文件。

9、/etc/init.d

  #--->这个目录是用来存放系统或服务器以 System V 模式启动的脚本,这在以 System V 模式启动或初始化的系统中常见。比如 Centos/RedHat;

[root@localhost ~]# ll /etc/init.d
lrwxrwxrwx. 1 root root 11 3月   8 06:54 /etc/init.d -> rc.d/init.d

10、/etc/xinit.d

   #--->如果服务器是通过xinetd模式运行的,它的脚本要放在这个目录下。有些系统没有这个目录,比如Slackware,有些老的版本也没有。在Rehat/Fedora 中比较新的版本中存在

[root@localhost ~]# ll /etc/init.d
lrwxrwxrwx. 1 root root 11 3月   8 06:54 /etc/init.d -> rc.d/init.d

11、/etc/profile

   #--->系统全局环境变量配置路径

   alias rm=

   PATH变量

12、/etc/profile.d

   #--->加载系统登陆程序一个目录,命令或文件独立存在!