目录
网编三要素和SSH原理
网编三要素
网络编程三要素: ip地址 端口(端口号) 协议
ip地址: 根据ip地址能够找到对应唯一的网络设备
端口: 应用程序的入口,但是往往要先使用端口号来找到对应的端口,再根据端口连接上对应的进程
协议: 多个进程之间网络传输的规则
tcp: 传输控制协议(TCP,Transmission Control Protocol)是一种面向连接的、可靠的、基于字节流的传输层通信协议
udp: 用户数据报协议(UDP,User Datagram Protocol)是一种无连接的、不可靠的、之间发送封装的 IP 数据包的通信协议
SSH原理
SH协议:文件传输协议secret file transfer protocol, Secure FTP或SFTP是一种数据流连线档案存取、传输和管理功能的网络传输协议。
OpenSSH: 是 SSH (Secure SHell) 协议的免费开源实现。SSH协议族可以用来进行远程控制, 或在计算机之间传送文件。
Secure Shell: (安全外壳协议,简称SSH)是一种加密的网络传输协议,可在不安全的网络中为网络服务提供安全的传输环境。
常用命令: ssh-keygen: 生成公钥(rsa.pub)和私钥(rsa)
服务名称: sshd
基础linux命令
linux目录结构
只有一个根目录: /
多个目录分隔符: /
如何区分根目录和分隔符: 以/开头的是根目录,后面的都是分隔符 举例: /usr/local
基础四大命令
ls: 查看当前目录了下所有内容
cd 目录名: 切换目录
pwd: 查看当前所在位置
clear: 清屏
[root@node1 ~]# cd /
[root@node1 /]# pwd
/
[root@node1 /]# ls
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr
[root@node1 /]# clear
linux命令格式
command [-options] [parameter]
说明:
- command : 命令名, 相应功能的英文单词或单词的缩写
- [-options] : 选项, 可用来对命令进行控制, 也可以省略
- parameter : 传给命令的参数, 可以是 零个、一个 或者 多个
ls命令
ls [-a -l -h] [路径] : 查看指定路径下文件列表 注意: 默认都是当前路径
参数 -a : 展示出隐藏文件 注意: .开头就是隐藏文件
参数 -l : 以详细信息展示文件 注意: ls -l 可以简化为ll
参数 -h : 配合-l使用,人性化展示文件大小[root@node1 ~]# ls anaconda-ks.cfg [root@node1 ~]# ls -a . anaconda-ks.cfg .bash_logout .bashrc .config .tcshrc .. .bash_history .bash_profile .cache .cshrc [root@node1 ~]# ls -l 总用量 4 -rw-------. 1 root root 1270 7月 29 10:01 anaconda-ks.cfg [root@node1 ~]# ls -a -l 总用量 28 dr-xr-x---. 4 root root 164 7月 29 10:20 . dr-xr-xr-x. 17 root root 237 7月 29 10:57 .. -rw-------. 1 root root 1270 7月 29 10:01 anaconda-ks.cfg -rw-------. 1 root root 34 7月 29 10:20 .bash_history -rw-r--r--. 1 root root 18 12月 29 2013 .bash_logout -rw-r--r--. 1 root root 176 12月 29 2013 .bash_profile -rw-r--r--. 1 root root 176 12月 29 2013 .bashrc drwxr-xr-x. 3 root root 18 7月 29 10:02 .cache drwxr-xr-x. 3 root root 18 7月 29 10:02 .config -rw-r--r--. 1 root root 100 12月 29 2013 .cshrc -rw-r--r--. 1 root root 129 12月 29 2013 .tcshrc [root@node1 ~]# ll 总用量 4 -rw-------. 1 root root 1270 7月 29 10:01 anaconda-ks.cfg [root@node1 ~]# ll -h 总用量 4.0K -rw-------. 1 root root 1.3K 7月 29 10:01 anaconda-ks.cfg [root@node1 ~]# ll -a -h 总用量 28K dr-xr-x---. 4 root root 164 7月 29 10:20 . dr-xr-xr-x. 17 root root 237 7月 29 10:57 .. -rw-------. 1 root root 1.3K 7月 29 10:01 anaconda-ks.cfg -rw-------. 1 root root 34 7月 29 10:20 .bash_history -rw-r--r--. 1 root root 18 12月 29 2013 .bash_logout -rw-r--r--. 1 root root 176 12月 29 2013 .bash_profile -rw-r--r--. 1 root root 176 12月 29 2013 .bashrc drwxr-xr-x. 3 root root 18 7月 29 10:02 .cache drwxr-xr-x. 3 root root 18 7月 29 10:02 .config -rw-r--r--. 1 root root 100 12月 29 2013 .cshrc -rw-r--r--. 1 root root 129 12月 29 2013 .tcshrc [root@node1 ~]# ls -l / 总用量 24 -rw-r--r--. 1 root root 12 7月 29 10:57 a.txt lrwxrwxrwx. 1 root root 7 7月 29 09:58 bin -> usr/bin dr-xr-xr-x. 5 root root 4096 7月 29 10:02 boot drwxr-xr-x. 20 root root 3220 7月 29 10:02 dev drwxr-xr-x. 85 root root 8192 7月 29 10:02 etc drwxr-xr-x. 2 root root 6 4月 11 2018 home lrwxrwxrwx. 1 root root 7 7月 29 09:58 lib -> usr/lib lrwxrwxrwx. 1 root root 9 7月 29 09:58 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. 3 root root 16 7月 29 09:59 opt dr-xr-xr-x. 127 root root 0 7月 29 10:02 proc dr-xr-x---. 4 root root 164 7月 29 10:20 root drwxr-xr-x. 32 root root 940 7月 29 10:02 run lrwxrwxrwx. 1 root root 8 7月 29 09:58 sbin -> usr/sbin drwxr-xr-x. 2 root root 6 4月 11 2018 srv dr-xr-xr-x. 13 root root 0 7月 29 10:02 sys drwxrwxrwt. 9 root root 257 7月 29 10:43 tmp drwxr-xr-x. 13 root root 155 7月 29 09:58 usr drwxr-xr-x. 21 root root 4096 7月 29 10:02 var
cd和pwd和clear命令
cd [路径] : 切换到指定路径下
家目录: 普通用户的家目录:/home/普通用户名 root用户的家目录:/root
如何快速回家: cd ~ 注意: ~可以省略pwd : 查看当前路径
clear: 清屏 快捷键: ctrl+L
[root@node1 /]# clear
[root@node1 ~]# ls
anaconda-ks.cfg
[root@node1 ~]# cd home
-bash: cd: home: 没有那个文件或目录
[root@node1 ~]# cd /home
[root@node1 home]# cd /
[root@node1 /]# cd home
[root@node1 home]# cd /
[root@node1 /]# ls
a.txt bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
[root@node1 /]# cd /home
[root@node1 home]# pwd
/home
相对路径和绝对路径
1. 相对路径和绝对路径
绝对路径: 以根目录'/'做起点,描述路径的方式,路径以/开头
相对路径: 以当前目录做起点,描述路径的方式,路径不需以/开头
如无特殊需求,后续学习中,将经常使用相对路径表示2. 特殊路径符有哪些?
. 表示当前目录, 比如: cd . 或 cd ./Desktop
.. 表示上一级目录,比如: cd .. 或 cd ../..
[root@node1 ~]# cd .
[root@node1 ~]# pwd
/root
[root@node1 ~]# cd ..
[root@node1 /]# pwd
/
[root@node1 /]# ls
a.txt boot etc lib media opt root sbin sys usr
bin dev home lib64 mnt proc run srv tmp var
[root@node1 /]# cd /home
[root@node1 home]# cd ..
[root@node1 /]# cd home
[root@node1 home]# cd ..
[root@node1 /]# cd ./home
[root@node1 home]# cd ..
[root@node1 /]# cd /usr/local
[root@node1 local]# cd ../..
[root@node1 /]# cd
[root@node1 ~]# ls
anaconda-ks.cfg
[root@node1 ~]# cd /home
mkdir命令
mkdir [-p] 目录路径 : 创建指定目录
-p:可选,表示自动创建不存在的父目录,适用于创建连续多层级的目录创建一级目录: mkdir 目录路径
创建多个同级目录: mkdir 目录路径1 目录路径2 ...
创建父子嵌套目录: mkdir -p 目录路径1/目录路径2/...
[root@node1 /]# mkdir binzi
[root@node1 /]# ls
bin boot etc lib media opt root sbin sys usr
binzi dev home lib64 mnt proc run srv tmp var
[root@node1 /]# cd binzi
[root@node1 binzi]# cd /
[root@node1 /]# cd /binzi
[root@node1 binzi]# ls
[root@node1 binzi]# mkdir sql/python/java
mkdir: 无法创建目录"sql/python/java": 没有那个文件或目录
[root@node1 binzi]# mkdir -p sql/python/java
[root@node1 binzi]# ls
sql
[root@node1 binzi]# cd sql
[root@node1 sql]# cd python/java
[root@node1 java]# pwd
/binzi/sql/python/java
touch命令
touch 文件路径: 创建指定文件
创建一个文件: touch 文件路径
创建多个文件: touch 文件路径1 文件路径2 ...
[root@node1 java]# cd /binzi
[root@node1 binzi]# ls
sql
[root@node1 binzi]# touch hello.sql
hello.sql sql
[root@node1 binzi]# ll
总用量 0
-rw-r--r--. 1 root root 0 3月 15 15:14 hello.sql
drwxr-xr-x. 3 root root 20 3月 15 15:10 sql
[root@node1 binzi]# cd sql
[root@node1 sql]# ls
python
[root@node1 sql]# touch 1.py 2.py 3.py 4.txt 5.txt 6.txt
[root@node1 sql]# ls
1.py 2.py 3.py 4.txt 5.txt 6.txt python
echo命令
echo 要打印的内容
注意: 默认打印到控制台,但是经常配合重定向符号使用
注意: echo配合反引号``可以先识别出关键字,然后把对应的内容输出
[root@node1 sql]# echo "helloworld"
helloworld
[root@node1 sql]# echo 'helloworld'
helloworld
[root@node1 sql]# echo helloworld
helloworld
[root@node1 test]# echo 'ls'
ls
[root@node1 test]# echo `ls`
1.txt 2.txt 3.py a b c
重定向符号
> : 覆盖写入
>> : 追加写入注意: 一般都是配合echo使用
[root@node1 sql]# echo 'helloworld' > 4.txt
[root@node1 sql]# cat 4.txt
helloworld
[root@node1 sql]# echo '我很帅' > 4.txt
[root@node1 sql]# cat 4.txt
我很帅
[root@node1 sql]# echo '' > 4.txt
[root@node1 sql]# cat 4.txt
[root@node1 sql]# echo '你好' >> 4.txt
[root@node1 sql]# echo '我好' >> 4.txt
[root@node1 sql]# echo '大家好' >> 4.txt
[root@node1 sql]# cat 4.txt
你好
我好
大家好
[root@node1 sql]# pwd
/binzi/sql
[root@node1 sql]# echo 'pwd' >> 4.txt
[root@node1 sql]# cat 4.txt
你好
我好
大家好
pwd
[root@node1 sql]# echo `pwd` >> 4.txt
[root@node1 sql]# cat 4.txt
你好
我好
大家好
pwd
/binzi/sql
[root@node1 sql]# ls
1.py 2.py 3.py 4.txt 5.txt 6.txt python
[root@node1 sql]# echo `ls` >> 4.txt
[root@node1 sql]# cat 4.txt
你好
我好
大家好
pwd
/binzi/sql
1.py 2.py 3.py 4.txt 5.txt 6.txt python
cat_more_less命令
cat [-n] 文件 : cat查看文件内容,一般建议查看小文件
-n :显示行号
more [-num] 文件: more查看文件内容,一般建议查看大文件(可以翻页)
空格: 下一页
b : 上一页
q : 退出
-x : 展示条数 举例: more -10 文件
less [-N] 文件: less查看文件内容,一般建议查看大文件(可以翻页,可以搜索)
-N : 显示行号
空格: 下一页
b : 上一页
q : 退出
/内容: 搜索指定内容
[root@node1 binzi]# cat test.txt
[root@node1 binzi]# cat -n test.txt
[root@node1 binzi]# more test.txt
[root@node1 binzi]# more -10 test.txt
[root@node1 binzi]# less test.txt
[root@node1 binzi]# less -N test.txt
cp命令
copy的英文词 cp [-r] 要复制的文件或者文件夹 目标位置 : 复制文件或者文件夹到指定目标位置
注意: -r 主要用于复制文件夹
注意: cp复制文件后,源文件依然存在
[root@node1 binzi]# cp test.txt sql
[root@node1 binzi]# cd sql
[root@node1 sql]# ls
1.py 2.py 3.py 4.txt 5.txt 6.txt python test.txt
[root@node1 sql]# cp test.txt test2.txt
[root@node1 sql]# ls
1.py 2.py 3.py 4.txt 5.txt 6.txt python python2 test2.txt test.txt
[root@node1 sql]# cat test2.txt
[root@node1 sql]# cd python2
[root@node1 python2]# ls
java
[root@node1 python2]# cd ..
[root@node1 sql]# cp -r python python2
[root@node1 sql]# ls
1.py 2.py 3.py 4.txt 5.txt 6.txt python python2 test2.txt test.txt
[root@node1 sql]# cd python2
[root@node1 python2]# ls
java python
mv命令
move的英文词 mv 要移动的文件或者文件夹 目标位置: 移动文件或者文件夹到指定目标位置
注意: 目标位置是文件,文件不存在就会直接改名 如果想要把文件移动到目录中,此目录一定要存在,否则当成了普通文件改名
注意: mv移动文件后,源文件不存在
[root@node1 sql]# ls
1.py 2.py 3.py 4.txt 5.txt 6.txt python python2 test2.txt test.txt
[root@node1 sql]# mv test.txt test3.txt
[root@node1 sql]# ls
1.py 2.py 3.py 4.txt 5.txt 6.txt python python2 test2.txt test3.txt
[root@node1 sql]# mv test3.txt aaa
[root@node1 sql]# ls
1.py 2.py 3.py 4.txt 5.txt 6.txt aaa python python2 test2.txt
[root@node1 sql]# ll
...
-rw-r--r--. 1 root root 455 3月 15 16:10 aaa
-rw-r--r--. 1 root root 455 3月 15 16:18 test2.txt
[root@node1 sql]# mv test2.txt python
[root@node1 sql]# ls
1.py 2.py 3.py 4.txt 5.txt 6.txt aaa python python2
[root@node1 sql]# cd python
[root@node1 python]# ls
java test2.txt
rm命令
移除的英文单词: ==remove==
rm [-r -f] 要删除的文件或者文件夹: 删除指定的文件或者文件夹
注意: -r 主要用于删除文件夹 -f :主要用于强制删除文件或者文件夹
删除文件(有提示): rm 文件路径
删除文件(无提示): rm -f 文件路径
删除目录(有提示): rm -r 目录路径
删除目录(无提示): rm -rf 文件路径
[root@node1 sql]# ls
1.py 2.py 3.py 4.txt 5.txt 6.txt aaa python python2
[root@node1 sql]# rm 1.py
rm:是否删除普通空文件 "1.py"?y
[root@node1 sql]# rm -f 2.py
[root@node1 sql]# rm -f 3.py 4.txt 5.txt 6.txt
[root@node1 sql]# ls
aaa python python2
[root@node1 sql]# rm python
rm: 无法删除"python": 是一个目录
[root@node1 sql]# rm -r python
rm:是否进入目录"python"? y
rm:是否删除目录 "python/java"?y
rm:是否删除普通文件 "python/test2.txt"?y
rm:是否删除目录 "python"?y
[root@node1 sql]# ls
aaa python2
[root@node1 sql]# rm -rf python2
[root@node1 sql]# ls
aaa
[root@node1 sql]# rm -rf /binzi/
[root@node1 sql]# cd ..
cd: 获取当前目录时出错: getcwd: 无法访问父目录: 没有那个文件或目录
通配符
* : 任意个字符 类似于sql模糊查询中的 %
? : 任意1个字符 类似于sql模糊查询中的 _
[root@node1 /]# mkdir binzi
[root@node1 /]# ls
bin boot etc lib media opt root sbin sys usr
binzi dev home lib64 mnt proc run srv tmp var
[root@node1 /]# touch /binzi/1.txt
[root@node1 /]# touch /binzi/2.txt /binzi/3.txt /binzi/4.txt /binzi/5.txt
[root@node1 /]# cd binzi
[root@node1 binzi]# ls
1.txt 2.txt 3.txt 4.txt 5.txt
[root@node1 binzi]# touch 123.txt 456.txt 789.txt
[root@node1 binzi]# ls
123.txt 1.txt 2.txt 3.txt 456.txt 4.txt 5.txt 789.txt
[root@node1 binzi]# rm 1*
rm:是否删除普通空文件 "123.txt"?y
rm:是否删除普通空文件 "1.txt"?y
[root@node1 binzi]# ls
2.txt 3.txt 456.txt 4.txt 5.txt 789.txt
[root@node1 binzi]# rm -f *5*
[root@node1 binzi]# ls
2.txt 3.txt 4.txt 789.txt
[root@node1 binzi]# rm -f *.txt
[root@node1 binzi]# ls
[root@node1 binzi]# touch 1.txt 2.txt 234.txt 123.txt 456.txt 789.txt
[root@node1 binzi]# ls
123.txt 1.txt 234.txt 2.txt 456.txt 789.txt
[root@node1 binzi]# touch 112.txt 1123.txt
[root@node1 binzi]# ls
1123.txt 112.txt 123.txt 1.txt 234.txt 2.txt 456.txt 789.txt
[root@node1 binzi]# rm -f ?2*
[root@node1 binzi]# ls
1123.txt 112.txt 1.txt 234.txt 2.txt 456.txt 789.txt
[root@node1 binzi]# rm -f ??2*
[root@node1 binzi]# ls
1.txt 234.txt 2.txt 456.txt 789.txt
which和find
which 命令: 查找命令所在位置
主要: find命令也可以结合通配符使用,不加路径代表当前路径下查找
find [查找路径] -name 文件名: 根据文件名查找
find [查找路径] -size [+ -]大小: 根据文件大小查找
+: 大于
-: 小于
find [查找路径] -type [d f] -name 文件名: 根据文件类型查找
d: 文件夹
f: 文件
[root@node1 /]# find / -name 'test'
[root@node1 /]# find -name 'test'
[root@node1 /]# find -name 'test*'
[root@node1 /]# find -name '*test'
[root@node1 /]# find -name '*test*'
[root@node1 /]# find -size +10M
[root@node1 /]# find -type d -name 'test'
[root@node1 /]# find -type f -name 'test'
管道符 |
管道符使用格式: 命令1 | 命令2 | 命令3 ...
解释: 把命令1的结果传递给命令2,然后再把命令2的结果传递给命令3,依次类推...
注意: 管道一般配合grep命令使用较多
sort: 排序
[root@node1 binzi]# touch 3.txt 2.txt 4.txt 1.txt 5.txt
[root@node1 binzi]# mkdir aa bb
[root@node1 binzi]# find -name '*.txt'
[root@node1 binzi]# find -name '*.txt' | sort 技巧: 把所有txt文件查询出来,然后排序,效果明显
[root@node1 binzi]# cat test.txt | less
grep命令
grep [-n] 关键字 文件路径: 在指定文件中搜索指定关键字
注意: -n 主要用于显示搜索到结果的行号
注意: 管道|一般配合grep命令使用较多
[root@node1 binzi]# ls
1.txt 234.txt 2.txt 3.txt 456.txt 789.txt
[root@node1 binzi]# cat 1.txt
python java sql
[root@node1 binzi]# echo `ls` >> 1.txt
[root@node1 binzi]# cat 1.txt
python java sql
1.txt 234.txt 2.txt 3.txt 456.txt 789.txt
[root@node1 binzi]# grep 'sql' 1.txt
python java sql
[root@node1 binzi]# grep '234' 1.txt
1.txt 234.txt 2.txt 3.txt 456.txt 789.txt
[root@node1 binzi]# grep -n '234' 1.txt
2:1.txt 234.txt 2.txt 3.txt 456.txt 789.txt
[root@node1 binzi]# ls
1.txt 234.txt 2.txt 3.txt 456.txt 789.txt
[root@node1 binzi]# ls | grep 234
234.txt
[root@node1 binzi]# find -name '*.txt' | grep 78
./789.txt
[root@node1 binzi]#
wc命令
wc [-l -w] 文件路径: 统计指定文件内容的行数或者单词数
-l : 行数
-w : 单词数 注意:空格分隔
[root@node1 test]# echo 'java sql python' >> test.txt
[root@node1 test]# echo 'linux hadoop hive' >> test.txt
[root@node1 test]# echo 'spark flink' >> test.txt
[root@node1 test]# cat test.txt
java sql python
linux hadoop hive
spark flink
[root@node1 test]# wc test.txt
3 8 46 test.txt
[root@node1 test]# wc -c test.txt
46 test.txt
[root@node1 test]# wc -m test.txt
46 test.txt
[root@node1 test]# wc -l test.txt
3 test.txt
[root@node1 test]# wc -w test.txt
8 test.txt
[root@node1 test]# echo 'helloworld' >> test.txt
[root@node1 test]# wc -w test.txt
9 test.txt
[root@node1 test]#
head和tail
head [-num] 文件路径: 查看文件的头部几行 默认前10行 当然-num可以指定任意行数
tail [-num] 文件路径: 查看文件的尾部几行 默认后10行 当然-num可以指定任意行数
tail -f 文件路径: 持续跟踪查看指定文件内部变化
[root@node1 binzi]# head test.txt
[root@node1 binzi]# head -3 test.txt
[root@node1 binzi]# tail test.txt
[root@node1 binzi]# tail -3 test.txt
[root@node1 binzi]# tail -f test.txt 注意: -f持续跟踪文件内容 可以使用ctrl+c退出
vi编辑器
vi/vim编辑器的三种工作模式
vi操作文件三大步
打开文件: vim 文件名.后缀名 注意: 如果文件存在就打开,不存在就创建
编辑文件: 输入i进入文件进行编辑
保存文件:
1.先进入命令模式: 按ESC键
2.进入底线命令模式: 输入冒号:
3.输入命令: w(保存) q(退出) q!(强制退出) wq(保存并退出) wq!(强制保存并退出)