- 查看版本号
- 安装 tree 显示目录结构
- centos7查看mysql状态,开启/停止mysql
- 文本输出命令:cat
- tail 查看文件
- find和grep搜索
- 历史命令
- 后台运行
- 端口
- 查看磁盘空间
- 查看文件夹下的文件
- 文件夹的文件按照时间倒序或者升序排列
- 1 按照时间升序
- 2 按照时间降序(最新修改的排在前面)
- 全局设置使用PHP
- 修改文件夹所属组
- Nginx配置rewrite
- 查看php.ini文件路径
- 修改用户密码
- 查看端口
- 查看80端口
- 查看Redis端口
- 设置Redis密码
- 查看Redis密码
- 查看本机80端口是否已监听
- 查看开放端口
- 监听端口指定字符显示行数
- 查看文件大小
- 查看所有进程
- 返回进程ID
- 查看Redis进程
- 查看所有以安装的包
- MySQL开启远程登录
- 重启PHP
- 查看PHP的Redis扩展
- Linux创建目录并进入目录
- 设置目录访问权限
- linux压缩文件夹
- vim编辑器
- ps命令用于查看系统中的进程状态
- 网络适配器简介
- 关机、重启、登录、注销
- 用户基本语法
- 用户组
- 文件目录类
- 搜索查找类
- 压缩和解压
- 定时任务调度与进程服务管理
# 查看CentOS的版本号:
[root@bogon laravel5]# cat /etc/centos-release
CentOS Linux release 7.9.2009 (Core)
# 查询操作系统内核版本信息为:
[root@bogon laravel5]# uname -r
3.10.0-1160.6.1.el7.x86_64
# 查看操作系统位数
[root@bogon laravel5]# getconf LONG_BIT
64
安装 tree 显示目录结构
[root@bogon ~]# yum -y install tree
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
epel/x86_64/metalink | 7.9 kB 00:00:00
* base: mirrors.huaweicloud.com
* centos-sclo-rh: mirrors.bfsu.edu.cn
* epel: mirrors.bfsu.edu.cn
* extras: mirrors.bfsu.edu.cn
* updates: mirrors.bfsu.edu.cn
base | 3.6 kB 00:00:00
centos-sclo-rh | 3.0 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.6.0-10.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==========================================================================================================================================
Package Arch Version Repository Size
==========================================================================================================================================
Installing:
tree x86_64 1.6.0-10.el7 base 46 k
Transaction Summary
==========================================================================================================================================
Install 1 Package
Total download size: 46 k
Installed size: 87 k
Downloading packages:
tree-1.6.0-10.el7.x86_64.rpm | 46 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : tree-1.6.0-10.el7.x86_64 1/1
Verifying : tree-1.6.0-10.el7.x86_64 1/1
Installed:
tree.x86_64 0:1.6.0-10.el7
Complete!
[root@bogon ~]# tree /home/
/home/
├── esUser
│ ├── Desktop
│ ├── Documents
│ ├── Downloads
│ ├── Music
│ ├── Pictures
│ ├── Public
│ ├── Templates
│ └── Videos
├── fenxiang
├── redis
├── willem
└── www
13 directories, 0 files
[root@bogon ~]# tree /home/
centos7查看mysql状态,开启/停止mysql
查看mysql状态 systemctl status mysqld.service
启动mysql systemctl start mysqld.service
停止mysql systemctl stop mysqld.service
重启mysql
systemctl restart mysqld.service
1:指定文件搜索某个内容,在index.html搜索body
cat index.html | grep 'body'
2:cat的 -A,-B,-C,-v操作
cat index.html | grep 'body' -A 5 #输出body前5行
cat index.html | grep 'body' -B 5 #输出body前5行
cat index.html | grep 'body' -C 5 #输出body前后5行
cat index.html | grep -v 'body' #不输出body行
3:还可以把指定的数据提出来输出到某个文件,比如日志文件很大,我要找用户ID为10086的数据,那么就可以先把该数据找出来,单独保存一个文件,这样,该文件就小的多,便于操作。我们搜索2020.txt,搜索10086的数据,然后保存在当前目录下为10086.txt
cat 2020.txt | grep '10086' > ./10086.txt
tail -n -5 1.txt #输出文件后5行
tail -n +5 1.txt #从第5行开始输出,包括第5行
tail -fn -5 1.txt #实时输出文件后5行
tail -fn 1.txt #实时输出全部内容
touch -f 1.txt #创建1.txt文件
echo "123" > 1.txt # 往1.txt文件里输入内容
tail -f 1.txt #实时输出全部内容
find和grep搜索
1:find 搜索文件,这个命令很简单,在当前目录下搜索 index目录,. 为当前目录
root@ubuntu:~# find . -name index
./.sdrcoin/blocks/index
./.litecoin/blocks/index
2:搜索内容,用cat命令,我们是指定文件中搜索,现在我不知道文件在哪里,但知道文件里面的一些内容,那么就可以这样粗暴的操作。
这里在www目录下搜索 内容为body的文件 -r :递归;-i:忽略大小写;-n:显示查找到的行数
root@ubuntu:/home# grep -rin 'body' www/
www/index.html:7: body {
www/index.html:25:
www/index.html:51:
历史命令
history 查看系统中最近执行过了哪些命令,可以带一个条件,精确搜索,比如搜索下最近有没有使用nginx命令
history | grep nginx
常用的有两种方式后台运行:两则都是后台运行,不同之处在于关闭终端
- command & 关掉终端停止运行
- nohup command & 关掉终端继续运行
比如:我们要后台执行test.php
nohup php test.php & #后台运行,关闭终端不停止
php test.php & #后台运行,退出终端停止
端口
运维工作查看端口比较频繁,程序起不来?查看性能,进程等等都需要用到端口。
netstat和ss两个命令,建议用ss,netstat已经在淘汰的路上了。低版本linux可能没有ss
netstat -a #查看所有端口
netstat -tnlp | grep :80 #查看80端口,也可以-tnap
ss -s #查看网络连接统计
ss -pl #查看所有的端口以及应用程序名称
ss -lntpd | grep :80 #查看80端口
查看磁盘空间
df -h #统计磁盘使用情况
du -lh --max-depth=1 #查看当前目录下一级子文件和子目录占用的磁盘容量
du -h --max-depth=1 |grep 'G' |sort -nr #只统计容量超过G的目录,且按照从大到小排序
查看文件夹下的文件
ls /usr/local/lib | grep fontforge
命令:ls -lrt
详细解释:
-l use a long listing format 以长列表方式显示(详细信息方式)
-t sort by modification time 按修改时间排序(最新的在最前面)
-r reverse order while sorting (反序)
2 按照时间降序(最新修改的排在前面)
命令:ls -lt
详细解释:
-l use a long listing format 以长列表方式显示(详细信息方式)
-t sort by modification time 按修改时间排序(最新的在最前面)
全局设置使用PHP
[root@localhost src]# vi ~/.bash_profile
vi 编辑器
export PATH
alias php7=/usr/local/php7/bin/php
使用source命令使修改立刻生效:
[root@localhost]# source ~/.bash_profile
bash: php: command not found…
[root@localhost bin]# php -v
bash: php: command not found...
[root@localhost bin]# ln -s /usr/local/php7/bin/php /usr/bin/php
[root@localhost bin]# php -v
PHP 7.1.3 (cli) (built: May 28 2019 12:05:25) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
修改文件夹所属组
chown [-R] 账号名称:组群 文件/目录
if (!-e $request_filename) { #如果找不到请求的页面
rewrite ^(.*)$ /index.php?s=/$1 last; #地址作为将参数rewrite到index.php上
break;
}
[root@localhost ~]# php -i | grep php.ini
Configuration File (php.ini) Path => /usr/local/php7/etc
Loaded Configuration File => /usr/local/php7/etc/php.ini
[root@f48b0ba8a05f html]# /usr/local/php7/bin/php -i | grep php.ini PHP根目录执行
Configuration File (php.ini) Path => /usr/local/php7/etc
Loaded Configuration File => /usr/local/php7/etc/php.ini
修改用户密码
[root@localhost init.d]# passwd willem
Changing password for user willem.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
查看端口
[root@localhost exampswoolele]# netstat -anp | grep 8811
tcp 0 0 0.0.0.0:8811 0.0.0.0:* LISTEN 1889/php
tcp 0 0 192.168.11.135:8811 192.168.11.178:58376 ESTABLISHED 1889/php
tcp 0 0 192.168.11.135:8811 192.168.11.178:58389 ESTABLISHED 1889/php
查看80端口
netstat -anp|grep 8080
[root@localhost src]# netstat -nlt | grep 6379
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN
tcp6 0 0 :::6379 :::* LISTEN
设置Redis密码
127.0.0.1:6379> config set requirepass 123456
127.0.0.1:6379> config get requirepass
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth 123456
OK
127.0.0.1:6379> keys *
1) "uid"
2) "username:ycc"
3) "user:6:followers"
4) "user:3:following"
5) "ukey"
查看本机80端口是否已监听
ss -lnt | grep 80
一、安装nmap
yum install nmap #输入y安装
二、使用nmap
nmap localhost #查看主机当前开放的端口
nmap -p 1024-65535 localhost #查看主机端口(1024-65535)中开放的端口
nmap -PS 192.168.21.163 #探测目标主机开放的端口
nmap -PS22,80,3306 192.168.21.163 #探测所列出的目标主机端口
nmap -O 192.168.21.163 #探测目标主机操作系统类型
nmap -A 192.168.21.163 #探测目标主机操作系统类型
nmap --help #更多nmap参数请查询帮助信息
监听端口指定字符显示行数
[root@localhost script]# netstat -anp | grep 8811 | grep LISTEN | wc -l
1
查看文件大小
[root@f48b0ba8a05f html]# du -h 1.1导学\(Av60396329\,P1\).mp4
43M 1.1导学(Av60396329,P1).mp4
[root@f48b0ba8a05f html]# ls -lh
total 43M
-rw-r--r--. 1 root root 43M Jul 29 03:30 1.1导学(Av60396329,P1).mp4
-rw-r--r--. 1 root root 30 Jul 30 07:02 index.php
drwxr-xr-x. 3 root root 22 Jul 29 11:31 tanwei
查看所有进程
[root@f48b0ba8a05f html]# ps -ef
过滤进程
[root@f48b0ba8a05f html]# ps -ef | ffmpeg
返回进程ID
[root@localhost script]# netstat -anp | grep 8811
tcp 0 0 0.0.0.0:8811 0.0.0.0:* LISTEN 5694/live_master
[root@localhost script]# pidof live_master
5694
查看Redis进程
[root@localhost src]# ps -ef | grep redis
root 13385 13382 0 08:56 ? 00:00:00 runsv redis
root 13394 13382 0 08:56 ? 00:00:00 runsv redis-exporter
root 13401 13385 0 08:56 ? 00:00:00 svlogd -tt /var/log/gitlab/redis
gitlab-+ 13406 13385 0 08:56 ? 00:00:04 /opt/gitlab/embedded/bin/redis-server 127.0.0.1:0
root 13408 13394 0 08:56 ? 00:00:00 svlogd -tt /var/log/gitlab/redis-exporter
查看所有以安装的包
rpm -qa | grep httpd
MySQL开启远程登录
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'MyPassword' WITH GRANT OPTION; FLUSH PRIVILEGES;
关闭SELinux防火墙
service php-fpm start|stop|restart
[root@localhost html]# php -m | grep redis
[root@localhost html]# mkdir willem-sass && cd $_
[root@localhost willem-sass]#
设置目录访问权限
setfacl 设置文件访问控制列表
setfacl –m u:www:rwx –R web/
[root@instance-d7uho080 html]# zip -q -r c-plus.cn.zip plus
[root@instance-d7uho080 html]# ll
total 272056
drwxr-xr-x 11 root root 4096 Feb 27 2019 360
-rw-r--r-- 1 vsftpd vsftpd 537 Jan 28 2019 50x.html
-rw-r--r-- 1 root root 278558193 May 30 21:11 c-plus.cn.zip
-rw-r--r-- 1 vsftpd vsftpd 612 Jan 28 2019 index.html
-rw-r--r-- 1 vsftpd vsftpd 17 Jan 29 2019 index.php
drwxr-sr-x 12 vsftpd vsftpd 4096 Apr 9 21:38 plus
vim编辑器
ps aux ps命令用于查看系统中的进程状态
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND ● USER,进程所有者的用户名。 ● PID,进程号,可以唯一标识该进程。 ● %CPU,进程自最近一次刷新以来所占用的CPU时间和总时间的百分比。 ● %MEM,进程使用内存的百分比。 ● VSZ,进程使用的虚拟内存大小,以K为单位。 ● RSS,进程占用的物理内存的总数量,以K为单位。 ● TTY,进程相关的终端名。 ● STAT,进程状态,用(R–运行或准备运行;S–睡眠状态;I–空闲;Z–冻结;D–不间断睡眠;W-进程没有驻留页;T停止或跟踪。)这些字母来表示。 ● START,进程开始运行时间。 ● TIME,进程使用的总CPU时间。 ● COMMAND,被执行的命令行。
桥接模式
桥接模式表示虚拟机与主机在同一网段下,也就相当于局域网,如果IP地址为192.168.100.129,那么网段就是192.168.100,也就是说虚拟机ip最多会有255个,这样就有了局限性,容易造成IP冲突。 NAT模式 虚拟机中是独立的网络,通过代理与主机互通,不会造成IP冲突。
仅主机模式 只有本机能用的虚拟机,不建议使用。
列表的内容写入文件中:ls -l > 文件
列表的内容追加到文件的尾部:ls -al >> 文件
将文件1的内容覆盖到文件2:cat 文件1 > 文件2
echo "内容" >> 文件
ln软链接,也成符号链接,类似于Windows里的快捷方式ln -s [原文件或目录][软链接名],例如:ln -s /root/ myroothistory查看已经执行过的历史命令1、显示所有的历史命令:history
2、显示最近使用过的10条指令:history 10
3、执行历史编号为5的指令:!5
搜索查找类 指令描述备注find将从指定目录向下递归遍历其子目录,将满足条件的文件或目录显示在终端。基本语法:find [搜索范围][选项]
例子:
1、find /home -name hello.txt
2、find /opt -user jack
分页显示:find /home -user jack | more
3、查找整个Linux下大于200M的文件
find / -size +200M
locate快速定位文件路径需先执行updatedb创建locate数据库which查看某个指令在哪个目录下例如:which lsgrep过滤查找基本语法:grep [选项] 查找内容 源文件
选项:-n 显示行号;-i 忽略大小写
例如:
1、cat /home/hello.txt |grep "yes"
2、grep -n "yes" /home/helo.txt
|管道 压缩和解压 指令描述备注zip压缩文件-r:递归压缩;-d:指定压缩文件的存放目录
例如:zip -r myhome.zip /home/
unzip解压文件例如:unzip -d /opt/temp /home/myhome.ziptar压缩和解压文件基本语法:tar [选项] xxx.tar.gz 打包的内容
选项说明:
解包.tart文件
例如:
1、将/home的文件夹压缩成myhome.tar.gz
tar -zcvf myhome.tar.gz /home/
2、解压myhome.tar.gz到opt/tmp目录下
(1)mkdir opt/tmp
(2)tar -zxvf /home/myhome.tar.gz -C /opt/tmp
定时任务调度与进程服务管理crond相关指令:
1 crontab -r :终止任务调度 2 crontab -l:列出当前有哪些任务调度 3 service crontab restart:重启任务调度
-e编辑crondtab定时任务-l查询crondtab任务-r删除当前用户所有的crondtab任务举例说明
*/1 * * * * ls -l /etc/ > /tmp/to.txt
定时每分钟执行,将etc的ls内容重定向到tmp下to.txt文件中。
项目含义第一个*一小时中的第几分钟第二个*一天中的第几小时第三个*一个月中的第几天第四个*一年中的第几月第五个*一周中的星期几
特殊字符含义*代表时间,比如第一个*,代表每小时中的每分钟都执行一次,代表不连续的时间,比如0 8,12,16 * * * 代表每天的8点0分,12点0分,16点0分都执行一次
-代表连续的时间范围,比如0 5 * * 1-6 代表在周一到周六的凌晨5点0分执行命令*/n代表每隔多久执行一次,比如*/10 * * * * 代表每隔十分钟执行一遍命令