一些基本概念
查看当前目录路径命令:pwd
根目录:cd /:此目录称为linux的根目录,余下所有目录都是以根目录向下延伸。根目录是大数的根,后续所有路径都是根的分支路径,类似图X。
用户home目录:cd ~;pwd,即可看到个人的home目录,即个人的家目录,用户可以在自己home目录任意操作。同理到切换到不同用户后,cd ~会到新用户的home目录,比如 /home/zhangsan ,/home/lisi 。
linux支持多用户操作,如果防止冲突,即每个用户有自己独立的home目录,用户只有在自己home下面操作的权限,无在其他用户home操作权限。
绝对路径:以根路径起始的路径,比如/home/zhangsan/xxx/
相对路径:以当前路径起始的路径,比如../zhangsan/xx/; ./zhangsan/xx
基础目录介绍
写在前面,linux启动后存在的目录,均有各自的含义和作用,切不可随意删改或到其目录进行开发。建议新手创建普通账户,到自己home目录下学习和开发,形成良好的习惯,切不可直接使用root操作,防止做出“删库跑路”(例如rm /*; rm /lib64/*)的低端操作。当然以我多年操作系统经验,我会告诉你如何恢复。
初次登陆系统后,会进入到~目录,
$ ls /
bin etc lib lib64 opt root sbin srv usr boot dev home mnt proc sys var
1./bin /sbin /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin
系统命令目录,这里存放着系统命令二进制,比如which mkdir,即可看到/bin/mkdir;
影响:系统命令执行
疑问1:为什么命令可以直接使用,而不是/bin/mkdir执行?因PATH环境变量
echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
执行命令时,系统会从PATH变量目录寻找二进制命令,如果找不到报错
疑问2:有什么区别
bin和sbin的区别:
/sbin 下的命令属于基本的系统命令;/bin下存放一些普通的基本命令,比如/sbin/ifconfig,/bin/ls
/bin,/usr/bin,/usr/local/bin
/bin是系统的一些指令,/usr/bin是普通用户命令 /usr/local/bin是你在后期安装的一些软件的运行命令
比如/bin/ls, /usr/bin/gcc, /usr/local/bin/ccmake(安装cmake)
2./etc
This is the nerve center of your system, it contains all system related configuration files in here or in its sub-directories.
系统配置文件目录,包括文件系统配置,服务配置等等
影响:系统某些服务或基础服务正常启动
比如
/etc/fstab配置fs挂载目录和格式,系统启动时会根据此配置进行目录挂载;
/etc/network/是网络配置,重启network时会根据此配置进行网络初始化;
等等
3./lib /lib64
库目录,所有动态的二进制文件都依赖.so库文件
影响:二进制执行,系统命令也是二进制哦
比如:
ldd /usr/bin/gcc
linux-vdso.so.1 => (0x00007ffdbecc5000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f8d8e559000)
/lib64/ld-linux-x86-64.so.2 (0x00007f8d8e923000)
gcc运行依赖以上库,求别乱动库,比如mv libc.so后,可能再也无法mv回来了,因为mv已经无法执行了。
4./opt
This directory is reserved for all the software and add-on packages that are not part of the default installation.
为后续软件安装预留目录,安装软件默认路径
5./usr
/usr usually contains by far the largest share of data on a system.
/usr通常存放共享、只读的文件或者数据,当然root权限下都是可读,但此目录下文件建议不要改动
比如 /usr/include 存放头文件,编译器依赖
6./root
root账号的home目录
影响:可有可无
7./srv
/srv contains site-specific data which is served by this system.
存放某些特定服务进程数据
8./sys
linux和设备驱动创建交互目录,通过此目录可查看一些设备驱动属性,操作硬件设备(比如enable,disable或参数设置)
比如
/sys/devices/platform/ 对应系统platform设备信息
/sys/devices/system/cpu/ 对应cpu设备信息,可根据此目录对cpu设备进行上下线操作
/sys/devices/system/memory/ 对应内存信息,可根据此目录对内存块进行上下线操作
9./boot
This directory contains everything required for the boot process except for configuration files not needed at boot time (the most notable of those being those that belong to the GRUB boot-loader) and the map installer. Thus, the /boot directory stores data that is used before the kernel begins executing user-mode programs. This may include redundant (back-up) master boot records, sector/system map files, the kernel and other important boot files and data that is not directly edited by hand. Programs necessary to arrange for the boot loader to be able to boot a file are placed in /sbin. Configuration files for boot loaders are placed in /etc. The system kernel is located in either / or /boot (or as under Debian in /boot but is actually a symbolically linked at / in accordance with the FSSTND).
系统启动依赖目录,里面存放了系统镜像、文件系统以及加载启动的grub文件
影响:系统启动
内核镜像:/boot/vmlinuz-xxx
文件系统:/boot/initrdxxx
grub目录:/boot/grub/
10./dev
/dev is the location of special or device files. It is a very interesting directory that highlights one important aspect of the Linux filesystem - everything is a file or a directory. Look through this directory and you should hopefully see hda1, hda2 etc.... which represent the various partitions on the first master drive of the system.
/dev是一个特殊的,设备驱动目录,里面文件大部分都是设备驱动文件。linux中"everything is a file or a directory"在此体现得淋漓尽致。
/dev/cdrom and /dev/fd0 represent your CD-ROM drive and your floppy drive. This may seem strange but it will make sense if you compare the characteristics of files to that of your hardware. Both can be read from and written to.
Take /dev/dsp, for instance. This file represents your speaker device. Any data written to this file will be re-directed to your speaker. If you try 'cat /boot/vmlinuz > /dev/dsp' (on a properly configured system) you should hear some sound on the speaker.
A file sent to /dev/lp0 gets printed.
Sending data to and reading from /dev/ttyS0 will allow you to communicate with a device attached there - for instance, your modem.
比如
/dev/cdrom和/dev/fd0是CD-ROM的驱动文件,你可以通过此接口读写cdrom中内容;
/dev/ttyS0是串口驱动,登陆操作系统界面,即使通过此驱动接口创建;
11./home
Linux is a multi-user environment so each user is also assigned a specific directory that is accessible only to them and the system administrator. These are the user home directories, which can be found under '/home/$USER' (~/). It is your playground: everything is at your command, you can write files, delete them, install programs, etc....
多用户操作环境,每个用户在此创建自己的home目录:'/home/$USER',用户可以在自己目录读写文件、删除文件、安装脚本等等。
12./mnt
This is a generic mount point under which you mount your filesystems or devices. Mounting is the process by which you make a filesystem available to the system. After mounting your files will be accessible under the mount-point.
系统挂载目录,挂载任意镜像或目录均可挂载在此目录,当然不挂也没事~
13./proc
/proc is very special in that it is also a virtual filesystem. It's sometimes referred to as a process information pseudo-file system. It doesn't contain 'real' files but runtime system information (e.g. system memory, devices mounted, hardware configuration, etc).
/proc是一个虚拟文件目录,内部文件均是linux创建的虚拟文件,可以通过这些文件,调用到linux的钩子函数,从而和linux内核进行交互,对应linux fs/proc/目录的.c实现
比如
cat /proc/iomem 可以查看到系统地址划分
说明:因为此目录是linux创建,所以读写权限均已固定,不可更改。
14./var
Contains variable data like system logging files, mail and printer spool directories, and transient and temporary files.
系统数据或临时数据存放目录,包括系统log、mail或其他文件。
比如:
/var/log/kern.log存放内核的日志