Linux
是一个操作系统,一切皆文件:读、写、(权限)
Linux内核:Ubuntu、entOS 、RedHat 可考红帽认证工程师
Kali linux:安全渗透测试使用!
通常服务器使用LAMP(Linux+Apache+MySQL+PHP) 或
LNMP(Linux+Nginx+MySQL+PHP)组合
1.安装CentOS
可本地安装 或 云服务器(阿里云)
本地装在 虚拟机 VMware上面,先安装VMware;
注意:Linux磁盘分区的时候需要自定义分区,注意分区名 /boot /home
Linux开机会启动许多程序,在Windows中叫做服务,在Linux中叫做 守护进程(daemon)
基础命令: Linux中没有错误 就代表操作成功
sync 将数据同步到因盘中
shutdown 关机
reboot 重启
所有的文件都挂在在 / 根目录下
ls / 查看根目录下的所有文件
/bin : bin是Binary的缩写,这个目录存放着最经常使用的命令
/dev : 是Device(设备)的缩写,存放的是Linux的外部设备,在Linux中访问设备的方式和访问文件的方式是相同的,挂载第三方
/home:用户的主目录,在Linux中,每个用户都有一个自己的目录,一般该目录名是以用户名的账号命名的
/lib:这个目录里存放着系统最基本的动态连接共享库,类似于Windows里的DLL文件(基本依赖,不要动)
/mnt:系统提供该目录是为了让用户临时挂载别的文件系统的,我们可以将光驱挂载在/mnt/上,然后进入该目录就可以查看光驱里面的内容。我们可以把一些本地文件挂载在这个目录下。
/proc: 虚拟目录,系统内存的映射(不用管)
/run:是一个临时文件系统,存储系统启动以来的信息,当系统重启时,这个目录下的文件应该被删掉或清除
/srv:该目录存放一些服务启动之后需要提取的数据
/tmp:这个目录是用来存放一些临时文件的。用完即丢的文件,比如安装包
/var:这个目录中存放着在不断扩充的东西,我们习惯将那些经常被修改的目录放在这个目录下,包括各种日志文件
/boot:这里是存放启动Linux时使用的一些核心文件,包括一些连接文件以及镜像文件(不要动)
/etc :用来存放所有的系统管理所需要的配置文件 和子目录。
/media: Linux系统会自动识别一些设备,例如U盘、光驱等等,识别后,linux会把识别的设备挂载到这个目录下
/opt:这是给主机额外安装软件所摆放的目录。比如安装一个ORACLE数据库则可以直接放在这个目录下,默认是空的。
/root: ls -a a代表查看全部文件;该目录为系统管理员,也称作超级权限者的用户主目录
/sbin: s 就是Super User的意思,这里存放的是系统管理员使用的系统管理程序
/sys:这是linux内核的很大变化,该目录下安装了2.6内核中新出现的一个文件系统sysfs
/usr: 非常重要的目录,用户的很多应用程序和文件都放在这个目录下,类似于windows下的program files目录
[root@centos7 local]# cd / [root@centos7 /]# ls bin dev home lib64 mnt proc run srv tmp var boot etc lib media opt root sbin sys usr [root@centos7 /]# cd usr [root@centos7 usr]# ls bin etc games include lib lib64 libexec local sbin share src tmp [root@centos7 usr]# cd local [root@centos7 local]# ls bin etc games include lib lib64 libexec sbin share src [root@centos7 local]#
/usr/bin:系统用户使用的应用程序
/usr/sbin: 超级用户使用较高级的管理程序和系统守护程序
/usr/src:内核源代码默认放置的目录
/lost +found:一般情况下是空的,当系统非法关机后,这里就存放了一些文件(存放突然关机的一些文件)
服务器中的 /www:存放服务器网站相关的资源,环境,网站的项目
常用的基本命令
1.目录管理
绝对路径 都是以 / 开头、相对路径,对于当前目录该如何寻找 .. / ../
cd :切换目录命令
cd .. 返回上一级目录 cd ./ 当前目录 ls:列出目录
-a 参数:all 查看 查看全部文件,包括隐藏文件
-l 参数:列出所有的文件,包含文件的属性和权限,没有隐藏文件
所有的命令可以组合使用
[root@centos7 /]# ls bin dev home lib64 mnt proc run srv tmp var boot etc lib media opt root sbin sys usr [root@centos7 /]# ls -al 总用量 28 dr-xr-xr-x. 17 root root 224 4月 15 23:04 . dr-xr-xr-x. 17 root root 224 4月 15 23:04 .. lrwxrwxrwx. 1 root root 7 4月 15 22:59 bin -> usr/bin dr-xr-xr-x. 5 root root 4096 4月 15 23:05 boot drwxr-xr-x. 20 root root 3300 4月 16 14:52 dev drwxr-xr-x. 145 root root 8192 4月 16 14:52 etc drwxr-xr-x. 4 root root 31 4月 16 21:27 home lrwxrwxrwx. 1 root root 7 4月 15 22:59 lib -> usr/lib lrwxrwxrwx. 1 root root 9 4月 15 22:59 lib64 -> usr/lib64 drwxr-xr-x. 2 root root 6 4月 11 2018 media drwxr-xr-x. 2 root root 6 4月 11 2018 mnt drwxr-xr-x. 2 root root 6 4月 16 15:53 opt dr-xr-xr-x. 216 root root 0 4月 16 14:52 proc dr-xr-x---. 14 root root 4096 4月 16 14:54 root drwxr-xr-x. 42 root root 1260 4月 16 14:53 run lrwxrwxrwx. 1 root root 8 4月 15 22:59 sbin -> usr/sbin drwxr-xr-x. 2 root root 6 4月 11 2018 srv dr-xr-xr-x. 13 root root 0 4月 16 14:52 sys drwxrwxrwt. 20 root root 4096 4月 16 15:46 tmp drwxr-xr-x. 13 root root 155 4月 15 22:59 usr drwxr-xr-x. 21 root root 4096 4月 15 23:05 var [root@centos7 /]#
cd ../home 相对路径
[root@centos7 /]# cd usr [root@centos7 usr]# cd ../home [root@centos7 home]# cd ../usr [root@centos7 usr]# ls bin etc games include lib lib64 libexec local sbin share src tmp [root@centos7 usr]#
cd ~ 进入用户目录 pwd显示当前用户所在的目录
[root@centos7 home]# cd ~ [root@centos7 ~]# pwd /root [root@centos7 ~]# ls anaconda-ks.cfg initial-setup-ks.cfg 公共 模板 视频 图片 文档 下载 音乐 桌面 [root@centos7 ~]#
mkdir 创建一个目录 蓝色的是文件夹 ,白色的是文件
mkdir -p 递归创建目录
[root@centos7 home]# mkdir -p test2/haha/h [root@centos7 home]# ls eric test1 test2 [root@centos7 home]# cd test2 [root@centos7 test2]# ls haha [root@centos7 test2]# cd haha [root@centos7 haha]# ls h [root@centos7 haha]# cd .. [root@centos7 test2]# cd.. bash: cd..: 未找到命令... [root@centos7 test2]# cd .. [root@centos7 home]# ls eric test1 test2 [root@centos7 home]# rm -rf test2 [root@centos7 home]# ls eric test1
rmdir 删除空的目录 如果存在文件 先删除文件,可以递归删除多个目录 rmdir -p test1/test/ha
cp 拷贝文件至目录 到新的地方 如果文件重复就选择覆盖或者放弃
rm 移除文件或者目录 rm -f 忽略不存在的文件,强制删除 不会提示
rm -r 递归删除
rm -i 互动,删除的时候询问是否删除
rm -rf 强制递归删除某文件 或者 rm -rf /根目录下的所有文件
mv 移动文件或目录 也可以重命名文件
-f 强制移动 -u 只替换已经更新过的文件
[root@centos7 home]# ls eric test1 test2 [root@centos7 home]# mv eric test1 [root@centos7 home]# ls test1 test2 [root@centos7 home]# cd test1 [root@centos7 test1]# ls eric [root@centos7 test1]# mv eric home [root@centos7 test1]# ls home [root@centos7 test1]# cd ../ [root@centos7 home]# ls test1 test2 [root@centos7 home]# ls test1 test2 [root@centos7 home]# cd test1 [root@centos7 test1]# ls home [root@centos7 test1]# mv home eric [root@centos7 test1]# ls eric
基本属性
[root@centos7 /]# ls -ll 总用量 28 lrwxrwxrwx. 1 root root 7 4月 15 22:59 bin -> usr/bin dr-xr-xr-x. 5 root root 4096 4月 15 23:05 boot drwxr-xr-x. 20 root root 3300 4月 16 14:52 dev drwxr-xr-x. 145 root root 8192 4月 16 14:52 etc drwxr-xr-x. 5 root root 44 4月 16 21:59 home lrwxrwxrwx. 1 root root 7 4月 15 22:59 lib -> usr/lib lrwxrwxrwx. 1 root root 9 4月 15 22:59 lib64 -> usr/lib64 drwxr-xr-x. 2 root root 6 4月 11 2018 media drwxr-xr-x. 2 root root 6 4月 11 2018 mnt drwxr-xr-x. 2 root root 6 4月 16 15:53 opt dr-xr-xr-x. 217 root root 0 4月 16 14:52 proc dr-xr-x---. 14 root root 4096 4月 16 14:54 root drwxr-xr-x. 42 root root 1260 4月 16 14:53 run lrwxrwxrwx. 1 root root 8 4月 15 22:59 sbin -> usr/sbin drwxr-xr-x. 2 root root 6 4月 11 2018 srv dr-xr-xr-x. 13 root root 0 4月 16 14:52 sys drwxrwxrwt. 20 root root 4096 4月 16 15:46 tmp drwxr-xr-x. 13 root root 155 4月 15 22:59 usr drwxr-xr-x. 21 root root 4096 4月 15 23:05 var
第一个字母是d 表示是一个目录 - 则是文件 ,若是 l 表示为链接文档(link file) 相当于快捷方式,后面会有 ->表示指向的是哪个文件, b 则表示为装置文件里面的可供存储的接口设备 c 则表示为装置文件里面的串行端口设备,例如键盘、鼠标
接下来的字符中,以三个为一组,且均为 rwx , r代表read,w代表write,x代表execute,这三个权限的位置不会改变,如果没有权限就会出现 [-]。每个文件的属性由左边第一部分10个字符来确定:
第一组为 :属主权限(哪个主人),第二组为属组权限(比如 管理组、游客组,可以自己创建各个组),第三组为其他用户权限
l rwx rwx rwx d r-x r-x r-x d rwx r-x r-x d rwx r-x r-x d rwx r-x r-x
后面的数字是文件数量 , 第一个root 是 属主(谁创建的),第二个root 代表是哪个用户组(属组) ,后面是大小 ,时间
chgrp 更改文件属组, 一般不改
charp -R 属组名 文件名 -R 递归更改文件属组 一般不会去更改
chown 更改文件属主,也可以同时更改文件属组
chown -R 属主名 文件名
chown -R 属主名 数组名 文件名
chmod 更改文件9个属性(必须要掌握)
chmod -R xyz 文件或目录
常用数字,或者符号
r:4 w:2 x:1 chmod 777 表示属性都有rwx rwx rwx ;chmod 666 rw-rw-rw-
chmod 770 filename
[root@centos7 home]# ls eric test1 test2 [root@centos7 home]# ls -ll 总用量 0 drwxr-xr-x. 2 root root 6 4月 16 21:59 eric drwxr-xr-x. 2 root root 6 4月 16 21:59 test1 drwxr-xr-x. 3 root root 16 4月 16 21:48 test2 [root@centos7 home]# chmod 777 eric [root@centos7 home]# ll 总用量 0 drwxrwxrwx. 2 root root 6 4月 16 21:59 eric drwxr-xr-x. 2 root root 6 4月 16 21:59 test1 drwxr-xr-x. 3 root root 16 4月 16 21:48 test2
更改回去
[root@centos7 home]# chmod 755 eric [root@centos7 home]# ll 总用量 0 drwxr-xr-x. 2 root root 6 4月 16 21:59 eric drwxr-xr-x. 2 root root 6 4月 16 21:59 test1 drwxr-xr-x. 3 root root 16 4月 16 21:48 test2
文件内容查看
cat : 由第一行开始显示文件内容
tac : 从最后一行开始显示,可以看出tac是cat 倒着写
nl :显示的时候,顺道输出行号
more : 一页一页的显示文件内容
less : 与more 类似,但是比more更好的是,他可以往前翻页
head : 只看头几行
tail 只看尾巴几行
可以使用man 来查看各个命令的使用文档 如:man cp 。