linux 操作(1)
老男孩教育-python全栈8期-Linux运维基础
李老师
QQ:918391635

1.mkdir
-p 创建多层目录
2.ls list
-l 显示详细信息
3.cd change directory 进入到目录中
4.pwd print working directory 显示当前所在位置
5.touch 摸 创建文件 修改文件的时间戳
6.vi 编辑文件
7.cat 显示文件内容
8.cp copy 复制
9.man 查询命令的帮助
10. mv move 移动
11. rm remove 删除文件或目录
-f 强制删除不提示
-r 递归删除目录
12. find 查找
-type f(file)
d(dir)
-name 名字
13. grep 三剑客老三 擅长 过滤
-v 排除
14. head 显示文件的前几行 默认显示文件的前10行
-n2 === -2 显示文件的前2行
15. tail 显示文件的最后几行 默认显示文件的后10行
-n1 === -1 显示文件的最后1行
-f 实时显示文件的更新
16. sed 三剑客老二 擅长取行
-n 取消默认输出
-i 修改文件的内容
-n '20p'
-n '20,30p'
's#oldboy#oldgirl#g'
's@oldboy@oldgirl@g'
17. tar 创建解压查看压缩包
zcf
tf
xf
-C
特殊符号:
1. * 任何 所有 *.log *.txt
2. .. 当前目录的上一级目录
3. . 当前目录
4. | 管道
find + |xargs
5. > 重定向符号 先清空文件的内容 然后追加
6. >> 追加 把信息追加到文件的结尾
Linux - CentOS 7.4
基础命令
系统优化+定时任务
nginx
nginx+py搭建网站
Linux
vmware fusion(mac) vmware workstation 12.0 (windows)
8.0
远程连接工具:xshell (windows) mac(iterm2)
android juiceSSH
IOS termius
Linux
Fedora
Red Hat Enterprise Linux RHEL 7.5
CentOS 红帽收费去掉,logo去掉
Debian
Ubuntu
SUSE OpenSUSE
https://mirrors.aliyun.com/centos/
F1
F2
F10
F12
intel virtual technology disabled(关闭)
enabled(开启)
intel vt
网卡名称 : eth0
ensxxx
vmware相关服务 要开启
win+r 输入 services.msc
VMware Authorization Service 正在运行/已启动 自动
VMware DHCP Service 正在运行/已启动 自动
VMware NAT Service 正在运行/已启动 自动
远程连接服务器 : 10.0.0.128
Xshell 免费
SecureCRT
putty
屌丝去洗浴中心之路
1.道路是否通畅 你到服务器之间
本地Shell-CMD-windows
2.是否有人劫财劫色
3.是否提供特殊服务
1.道路是否通畅 你到服务器之间
本地Shell-CMD-windows
[d:\~]$ ping 10.0.0.128
正在 Ping 10.0.0.128 具有 32 字节的数据:
来自 10.0.0.128 的回复: 字节=32 时间<1ms TTL=64
来自 10.0.0.128 的回复: 字节=32 时间<1ms TTL=64
来自 10.0.0.128 的回复: 字节=32 时间<1ms TTL=64
来自 10.0.0.128 的回复: 字节=32 时间<1ms TTL=64
10.0.0.128 的 Ping 统计信息:
数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
最短 = 0ms,最长 = 0ms,平均 = 0ms
[d:\~]$ ping 10.0.0.130
正在 Ping 10.0.0.130 具有 32 字节的数据:
来自 10.0.0.1 的回复: 无法访问目标主机。
请求超时。
请求超时。
请求超时。
10.0.0.130 的 Ping 统计信息:
数据包: 已发送 = 4,已接收 = 1,丢失 = 3 (75% 丢失),
2.是否有人劫财劫色
SeLinux
防火墙
3.
服务名称 搓澡 按摩 特殊服务
暗号(端口号) 80 443 22
远程连接服务 sshd 22
telnet 10.0.0.128 22
[d:\~]$ telnet 10.0.0.128 22
Connecting to 10.0.0.128:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
SSH-2.0-OpenSSH_7.4
Protocol mismatch.
Connection closed by foreign host.
Disconnected from remote host(10.0.0.128:22) at 12:17:03.
Type `help' to learn how to use Xshell prompt.
[d:\~]$ telnet 10.0.0.128 25
Connecting to 10.0.0.128:25...
Could not connect to '10.0.0.128' (port 25): Connection failed.
Type `help' to learn how to use Xshell prompt.
道路不通排查过程
1.ip地址
2.vmware 编辑-虚拟网络编辑器
3.windows 服务
vmware相关服务 要开启
win+r 输入 services.msc
VMware Authorization Service 正在运行/已启动 自动
VMware DHCP Service 正在运行/已启动 自动
VMware NAT Service 正在运行/已启动 自动
4.我的电脑/此电脑/文件夹 输入 网络连接
通过安装包修复
CCleaner 把vmware相关信息 清理掉 重新安装
总结:
1.创建虚拟机-部署CentOS 7.4
2.配置VMware虚拟网络编辑器
3.通过Xshell连接虚拟机
4.无法连接服务器排查过程(屌丝去洗浴中心之路)
5.xshell优化
下午:
操作与命令
空格和tab键
[root@oldboyedu-s8 ~]# #mkdir make directory
[root@oldboyedu-s8 ~]# mkdir /data
[root@oldboyedu-s8 ~]# #显示目录的内容
[root@oldboyedu-s8 ~]# #ls list
[root@oldboyedu-s8 ~]# ls /data/
[root@oldboyedu-s8 ~]# ls -l /d
data/ dev/
[root@oldboyedu-s8 ~]# ls -l /data/
total 0
=======================================================================================================================================
老男孩教育-python全栈8期-Linux运维基础
李老师
QQ:918391635
Linux - CentOS 7.4
基础命令
系统优化+定时任务
nginx
nginx+py搭建网站
Linux
vmware fusion(mac) vmware workstation 12.0 (windows)
8.0
远程连接工具:xshell (windows) mac(iterm2)
android juiceSSH
IOS termius
Linux
Fedora
Red Hat Enterprise Linux RHEL 7.5
CentOS 红帽收费去掉,logo去掉
Debian
Ubuntu
SUSE OpenSUSE
https://mirrors.aliyun.com/centos/
F1
F2
F10
F12
intel virtual technology disabled(关闭)
enabled(开启)
intel vt
网卡名称 : eth0
ensxxx
vmware相关服务 要开启
win+r 输入 services.msc
VMware Authorization Service 正在运行/已启动 自动
VMware DHCP Service 正在运行/已启动 自动
VMware NAT Service 正在运行/已启动 自动
远程连接服务器 : 10.0.0.128
Xshell 免费
SecureCRT
putty
屌丝去洗浴中心之路
1.道路是否通畅 你到服务器之间
本地Shell-CMD-windows
2.是否有人劫财劫色
3.是否提供特殊服务
1.道路是否通畅 你到服务器之间
本地Shell-CMD-windows
[d:\~]$ ping 10.0.0.128
正在 Ping 10.0.0.128 具有 32 字节的数据:
来自 10.0.0.128 的回复: 字节=32 时间<1ms TTL=64
来自 10.0.0.128 的回复: 字节=32 时间<1ms TTL=64
来自 10.0.0.128 的回复: 字节=32 时间<1ms TTL=64
来自 10.0.0.128 的回复: 字节=32 时间<1ms TTL=64
10.0.0.128 的 Ping 统计信息:
数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
最短 = 0ms,最长 = 0ms,平均 = 0ms
[d:\~]$ ping 10.0.0.130
正在 Ping 10.0.0.130 具有 32 字节的数据:
来自 10.0.0.1 的回复: 无法访问目标主机。
请求超时。
请求超时。
请求超时。
10.0.0.130 的 Ping 统计信息:
数据包: 已发送 = 4,已接收 = 1,丢失 = 3 (75% 丢失),
2.是否有人劫财劫色
SeLinux
防火墙
3.
服务名称 搓澡 按摩 特殊服务
暗号(端口号) 80 443 22
远程连接服务 sshd 22
telnet 10.0.0.128 22
[d:\~]$ telnet 10.0.0.128 22
Connecting to 10.0.0.128:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
SSH-2.0-OpenSSH_7.4
Protocol mismatch.
Connection closed by foreign host.
Disconnected from remote host(10.0.0.128:22) at 12:17:03.
Type `help' to learn how to use Xshell prompt.
[d:\~]$ telnet 10.0.0.128 25
Connecting to 10.0.0.128:25...
Could not connect to '10.0.0.128' (port 25): Connection failed.
Type `help' to learn how to use Xshell prompt.
道路不通排查过程
1.ip地址
2.vmware 编辑-虚拟网络编辑器
3.windows 服务
vmware相关服务 要开启
win+r 输入 services.msc
VMware Authorization Service 正在运行/已启动 自动
VMware DHCP Service 正在运行/已启动 自动
VMware NAT Service 正在运行/已启动 自动
4.我的电脑/此电脑/文件夹 输入 网络连接
通过安装包修复
CCleaner 把vmware相关信息 清理掉 重新安装
总结:
1.创建虚拟机-部署CentOS 7.4
2.配置VMware虚拟网络编辑器
3.通过Xshell连接虚拟机
4.无法连接服务器排查过程(屌丝去洗浴中心之路)
5.xshell优化
下午:
操作与命令
空格和tab键
[root@oldboyedu-s8 ~]# #mkdir make directory
[root@oldboyedu-s8 ~]# mkdir /data
[root@oldboyedu-s8 ~]# #显示目录的内容
[root@oldboyedu-s8 ~]# #ls list
[root@oldboyedu-s8 ~]# ls /data/
[root@oldboyedu-s8 ~]# ls -l /data/
total 0
相对路径与绝对路径:
绝对路径:从根开始的路径(位置) /data etc/hosts
从根开始的路径就是绝对路径。
[root@oldboyedu-s8 data]# touch /data/oldboy.txt
[root@oldboyedu-s8 data]# ls -l /data/
total 0
-rw-r--r--. 1 root root 0 Apr 25 15:16 oldboy.txt
第1个里程碑-打开文件
vi /data/oldboy.txt
第2个里程碑-编辑文件
按i 进入到编辑模式
第3个里程碑-退出编辑模式
按esc退出编辑模式
第4个里程碑-保存退出
:wq write quit
#保存退出
:q!
#强制退出不保存
第5个里程碑-显示文件内容
[root@oldboyedu-s8 data]# cat /data/oldboy.txt
I am studying linux.
vi/vim 快捷键
复制 yy
粘贴 p
删除、剪切 dd
撤销 u
把光标所在行到文件最后一行删除 dG
移动光标
把光标移动到文件的最后一行 G
把光标移动到文件的第一行 gg
#I am studying linux.I am studying linux.I am studying linux.
#I am studying linux.I am studying linux.I am studying linux.
#I am studying linux.I am studying linux.I am studying linux.
#I am studying linux.I am studying linux.I am studying linux.
批量删除
第1个里程碑-按ctrl + v 进入批量编辑模式
第2个里程碑-选择
第3个里程碑-删除 d
[root@oldboyedu-s8 data]# #copy cp
[root@oldboyedu-s8 data]#
[root@oldboyedu-s8 data]# cp /data/oldboy.txt /tmp/
[root@oldboyedu-s8 data]# ls -l /tmp/
total 8
-rwx------. 1 root root 836 Apr 25 11:03 ks-script-6cg4Xy
-rw-r--r--. 1 root root 183 Apr 25 15:56 oldboy.txt
drwx------. 3 root root 17 Apr 25 11:18 systemd-private-241350d318404b8eb4e0324ead618b12-chronyd.service-tG7NpS
drwx------. 3 root root 17 Apr 25 11:18 systemd-private-241350d318404b8eb4e0324ead618b12-vgauthd.service-bhBRbW
drwx------. 3 root root 17 Apr 25 11:18 systemd-private-241350d318404b8eb4e0324ead618b12-vmtoolsd.service-mHP4YZ
-rw-------. 1 root root 0 Apr 25 10:58 yum.log
2.5 把 /data 移动到 /root目录下面
move mv
[root@oldboyedu-s8 data]# mv /data/ /root/
[root@oldboyedu-s8 data]# ls -l /data
ls: cannot access /data: No such file or directory
[root@oldboyedu-s8 data]# ls -l /r
root/ run/
[root@oldboyedu-s8 data]# ls -l /root/
total 4
-rw-------. 1 root root 1233 Apr 25 11:03 anaconda-ks.cfg
drwxr-xr-x. 2 root root 46 Apr 25 16:00 data
进入/root目录下的data目录,删除oldboy.txt文件
remove
rm
[root@oldboyedu-s8 tmp]# cd /root/
[root@oldboyedu-s8 ~]# ls -l
total 4
-rw-------. 1 root root 1233 Apr 25 11:03 anaconda-ks.cfg
drwxr-xr-x. 2 root root 28 Apr 25 16:32 data
[root@oldboyedu-s8 ~]# pwd
/root
# 我们这里不能删除一个文件夹,系统默认是不允许的,我们要删的话也能硬删,按照下面的指令,
[root@oldboyedu-s8 ~]# rm -f data {这里是常规删除命令}
rm: cannot remove ‘data’: Is a directory {系统弹出提示,不能删除一个文件夹}
[root@oldboyedu-s8 ~]# ls -l
total 4
-rw-------. 1 root root 1233 Apr 25 11:03 anaconda-ks.cfg
drwxr-xr-x. 2 root root 28 Apr 25 16:32 data
[root@oldboyedu-s8 ~]# rm -r data {删除文件夹的指令,它内部实现机制是我们下降到该文件夹,然后再删除这个文件夹,就是先进去然后歼灭它}
rm: descend into directory ‘data’? y {选择y,确认删除}
rm: remove regular file ‘data/oldboy.txt.bak’? n
rm: remove directory ‘data’? n
[root@oldboyedu-s8 ~]# rm -rf data
[root@oldboyedu-s8 ~]# find /root/ -type f -name "oldboy.txt"
/root/oldboy.txt
[root@oldboyedu-s8 ~]#
[root@oldboyedu-s8 ~]#
[root@oldboyedu-s8 ~]#
[root@oldboyedu-s8 ~]# find /root/ -type f -name "*.txt"
/root/oldboy.txt
#*.txt 以.txt 结尾的文件
#find /root/ -type f -name "*.txt"
# 在哪里找 -什么类型 f(file)
# d(dir)
在/etc 找出以eth0结尾的文件
http://blog.51cto.com/lidao/1927347
老男孩教育每日一题-2017年5月18日-说说|(管道)与|xargs(管道xargs)的区别
[root@oldboyedu-s8 ~]# find /root/ -type f -name "*.txt"
/root/oldboy.txt
/root/alex.txt
[root@oldboyedu-s8 ~]# find /root/ -type f -name "*.txt" |xargs ls -l
-rw-r--r--. 1 root root 0 Apr 25 17:01 /root/alex.txt
-rw-r--r--. 1 root root 0 Apr 25 17:01 /root/oldboy.txt
# .. 当前目录的上一级目录
# . 当前目录
[root@oldboyedu-s8 sysconfig]# cd /etc/sysconfig/network-scripts/
[root@oldboyedu-s8 network-scripts]# cd ../../../../../../../../../
[root@oldboyedu-s8 ~]# cat /data/test.txt
test
liyao
oldboy
[root@oldboyedu-s8 ~]# #在文件中过滤
[root@oldboyedu-s8 ~]# #显示出文件中 你想要的或不想要的内容
[root@oldboyedu-s8 ~]# grep "oldboy" /data/test.txt
oldboy
[root@oldboyedu-s8 ~]# grep -v "oldboy" /data/test.txt
test
liyao
[root@oldboyedu-s8 ~]# head -2 /data/test.txt
test
liyao
2.10 已知/tmp下已经存在test.txt文件,如何执行命令才能把/mnt/test.txt拷贝到/tmp下覆盖掉/tmp/test.txt,而让系统不提示是否覆盖(root权限下)。
\cp /tmp/test.txt /mnt/
#cp cp -i
#别名
[root@oldboyedu-s8 ~]# alias
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
#\cp 临时取消cp命令的别名
#别名相当于给命令设置了 昵称 或 快捷键
2.11 只查看ett.txt文件(共100行)内第20到第30行的内容
seq 40 > /oldboy/ett.txt
cat /oldboy/ett.txt
#sed默认输出文件的每一行
[root@oldboyedu-s8 oldboy]# sed -n '20p' ett.txt
20
#-n 取消默认输出
[root@oldboyedu-s8 oldboy]#
[root@oldboyedu-s8 oldboy]# sed -n '20,30p' ett.txt
20
21
22
23
24
25
26
27
28
29
30
2.12 把/oldboy目录及其子目录下所有以扩展名 .sh结尾的文件中,文件包含./hostlists.txt(oldboy)的字符串全部替换为../idctest_iplist(oldgirl)
[root@oldboyedu-s8 oldboy]# find /oldboy/ -type f -name "*.sh"
/oldboy/test/del.sh
/oldboy/test.sh
/oldboy/t.sh
[root@oldboyedu-s8 oldboy]# #把一个文件的oldboy替换为 oldgirl
[root@oldboyedu-s8 oldboy]# #替换
[root@oldboyedu-s8 oldboy]# sed 's#oldboy#oldgirl#g' /oldboy/t.sh
oldgirl
[root@oldboyedu-s8 oldboy]# cat /oldboy/t.sh
[root@oldboyedu-s8 oldboy]# cat /oldboy/t.sh
oldboy
[root@oldboyedu-s8 oldboy]# sed 's#oldboy#oldgirl#g' /oldboy/t.sh
oldgirl
第1个里程碑-找出想要的文件
find /oldboy/ -type f -name "*.sh"
第2个里程碑-替换1个文件的内容
sed 's#oldboy#oldgirl#g' /oldboy/t.sh
第3个里程碑-把find命令找出的文件交给sed
find /oldboy/ -type f -name "*.sh" |xargs sed 's#oldboy#oldgirl#g'
[root@oldboyedu-s8 oldboy]# find /oldboy/ -type f -name "*.sh"
/oldboy/test/del.sh
/oldboy/test.sh
/oldboy/t.sh
[root@oldboyedu-s8 oldboy]# sed 's#oldboy#oldgirl#g' /oldboy/t.sh
oldgirl
[root@oldboyedu-s8 oldboy]# find /oldboy/ -type f -name "*.sh" |xargs sed 's#oldboy#oldgirl#g'
oldgirl
oldgirl
oldgirl
[root@oldboyedu-s8 oldboy]# cat /oldboy/t.sh
oldboy
[root@oldboyedu-s8 oldboy]# find /oldboy/ -type f -name "*.sh" |xargs sed -i 's#oldboy#oldgirl#g'
[root@oldboyedu-s8 oldboy]# find /oldboy/ -type f -name "*.sh" |xargs cat
oldgirl
oldgirl
oldgirl
[root@oldboyedu-s8 network-scripts]# cd /etc/sysconfig/network-scripts/
[root@oldboyedu-s8 network-scripts]# pwd
/etc/sysconfig/network-scripts
[root@oldboyedu-s8 network-scripts]# cd /tmp/
[root@oldboyedu-s8 tmp]# cd -
/etc/sysconfig/network-scripts
[root@oldboyedu-s8 network-scripts]# #cd - 快速进入你上一次的位置 从哪里来回哪里去
[root@oldboyedu-s8 network-scripts]# cd -
/tmp
[root@oldboyedu-s8 tmp]# cat -n /root/oldboy.txt
1 oldboy
2 oldboy
3 oldboy
4 oldboy
5 oldboy
vi/vim
nu==== number
:set nu 显示行号
:set nonu 取消显示行号
windows 创建压缩包
linux 打包压缩
创建一个压缩包
tar zcf /tmp/etc.tar.gz /etc
z=== 通过gzip软件进行压缩
c=== create 创建
f=== file 指定压缩包
[root@oldboyedu-s8 tmp]# tar zcf /tmp/etc.tar.gz /etc/
tar: Removing leading `/' from member names
[root@oldboyedu-s8 tmp]# ll /tmp/etc.tar.gz
-rw-r--r--. 1 root root 9916889 Apr 25 19:20 /tmp/etc.tar.gz
查看压缩包内容
tar tf /tmp/etc.tar.gz
t === list 显示压缩包内容
解压
[root@oldboyedu-s8 tmp]# cd /tmp/
[root@oldboyedu-s8 tmp]# tar xf etc.tar.gz
解压到指定位置
[root@oldboyedu-s8 tmp]# tar xf etc.tar.gz -C /mnt/
[root@oldboyedu-s8 tmp]# ls -l /mnt/
total 12
drwxr-xr-x. 80 root root 8192 Apr 25 16:30 etc
-rw-r--r--. 1 root root 0 Apr 25 18:06 test.txt
2024.11.18补充内容:
grep -rlE "3174.*limtFlag=0"
这是查找当前路径下面所有文件中,同一行内容里面有3174也有limtFlag=0这两个元素的内容,直接把文件内容输出当屏幕中。
总结:
1.创建虚拟机-部署CentOS 7.4
2.配置VMware虚拟网络编辑器
3.通过Xshell连接虚拟机
4.无法连接服务器排查过程(屌丝去洗浴中心之路)
5.xshell优化
6.必知必会命令 根据题目练习
7.find命令
8.打包压缩
9.三剑客 grep sed
预习:
0.ping baidu.com
1.单引号 双引号 区别
2.linux启动过程 运行级别
3.如何关闭Selinux和防火墙
4.定时任务 同步系统时间
5.nginx

浙公网安备 33010602011771号