grep命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
grep --help                                                               
Usage: grep [OPTION]... PATTERNS [FILE]...
Search for PATTERNS in each FILE.
Example: grep -i 'hello world' menu.h main.c
PATTERNS can contain multiple patterns separated by newlines.

Pattern selection and interpretation:
-E, --extended-regexp PATTERNS are extended regular expressions
-F, --fixed-strings PATTERNS are strings
-G, --basic-regexp PATTERNS are basic regular expressions
-P, --perl-regexp PATTERNS are Perl regular expressions
-e, --regexp=PATTERNS use PATTERNS for matching
-f, --file=FILE take PATTERNS from FILE
-i, --ignore-case ignore case distinctions
-w, --word-regexp match only whole words
-x, --line-regexp match only whole lines
-z, --null-data a data line ends in 0 byte, not newline

Miscellaneous:
-s, --no-messages suppress error messages
-v, --invert-match select non-matching lines
-V, --version display version information and exit
--help display this help text and exit

Output control:
-m, --max-count=NUM stop after NUM selected lines
-b, --byte-offset print the byte offset with output lines
-n, --line-number print line number with output lines
--line-buffered flush output on every line
-H, --with-filename print file name with output lines
-h, --no-filename suppress the file name prefix on output
--label=LABEL use LABEL as the standard input file name prefix
-o, --only-matching show only nonempty parts of lines that match
-q, --quiet, --silent suppress all normal output
--binary-files=TYPE assume that binary files are TYPE;
TYPE is 'binary', 'text', or 'without-match'
-a, --text equivalent to --binary-files=text
-I equivalent to --binary-files=without-match
-d, --directories=ACTION how to handle directories;
ACTION is 'read', 'recurse', or 'skip'
-D, --devices=ACTION how to handle devices, FIFOs and sockets;
ACTION is 'read' or 'skip'
-r, --recursive like --directories=recurse
-R, --dereference-recursive likewise, but follow all symlinks
--include=GLOB search only files that match GLOB (a file pattern)
--exclude=GLOB skip files and directories matching GLOB
--exclude-from=FILE skip files matching any file pattern from FILE
--exclude-dir=GLOB skip directories that match GLOB
-L, --files-without-match print only names of FILEs with no selected lines
-l, --files-with-matches print only names of FILEs with selected lines
-c, --count print only a count of selected lines per FILE
-T, --initial-tab make tabs line up (if needed)
-Z, --null print 0 byte after FILE name

Context control:
-B, --before-context=NUM print NUM lines of leading context
-A, --after-context=NUM print NUM lines of trailing context
-C, --context=NUM print NUM lines of output context
-NUM same as --context=NUM
--color[=WHEN],
--colour[=WHEN] use markers to highlight the matching strings;
WHEN is 'always', 'never', or 'auto'
-U, --binary do not strip CR characters at EOL (MSDOS/Windows)

When FILE is '-', read standard input. With no FILE, read '.' if
recursive, '-' otherwise. With fewer than two FILEs, assume -h.
Exit status is 0 if any line (or file if -L) is selected, 1 otherwise;
if any error occurs and -q is not given, the exit status is 2.

TL-WR800N v1路由器配置

固定电脑IP地址

网络和internet设置,更改适配器选项,然后在WLAN上右键,选择属性(R),然后点击internet协议版本4(TCP/IPv4)选项,然后按下属性(R)按钮,在弹出的窗口上选择使用下面的IP地址(S),
然后设置固IP为192.168.1.200,子网掩码为:255.255.255.0,最后选择确定即可

连接路由器的WiFi

WiFi列表中链接WiFi,这个WiFI的格式为:TP-LINK_xxxxxx

进入路由器后台

http://192.168.1.253/
后台用户名:admin,后台密码:admin

AP模式

AP模式就是将有线信号转成无线信号
参见:https://www.192ly.com/router-settings/tp-link/tl-wr800n-v1-ap.html

中继模式

中继模式用来将弱的无线信号放大,以便扩大无线的覆盖范围
参见:https://service.tp-link.com.cn/detail_article_1131.html

取消固定电脑IP地址

重复第一步的步骤,然后选择**自动获得IP地址(O)**即可.

参考链接

TL-WR800N v1 说明书
TP-Link TL-WR800N V1路由器-AP模式设置
TP-Link TL-WR800N V1路由器中继设置
TP-Link TL-WR800N V1路由器 其他设置
[TL-WR800N V1] 中继放大无线信号-中继模式

下载安装Xshell免费版

进入中文官网

进入Xshell的官网,然后点击顶部导航条上的所有下载家庭/学校免费.
在这里插入图片描述

填写邮箱获取下载链接

然后填写姓名和邮箱,选择要下载的程序,然后点击下载,下载链接会发送到刚才邮箱上。
在这里插入图片描述

接收邮件 并下载

打开邮箱,点击下载链接即可下载Xshell
下载好之后安装Xshell,过程省略..

使用Xshell创建秘钥

Xshell创建秘钥详细过程

打开Xshell,点击工具新建用户密钥生成向导
在这里插入图片描述
然后选择秘钥类型秘钥长度,默认即可,点击下一步
在这里插入图片描述
等待秘钥生成结束后,继续点击下一步.
在这里插入图片描述
输入秘钥名称秘钥密码,继续点击下一步
在这里插入图片描述

保存公钥

此时可以看到公钥了,点击存为文件
在这里插入图片描述
保存到电脑上的用户目录下的.ssh目录下:
在这里插入图片描述

导出私钥并保存

然后就看看到创建好的用户秘钥了.
在这里插入图片描述
导出私钥
在这里插入图片描述
输入密码
在这里插入图片描述

将Xshell创建的秘钥设置到Termux中

Termux 获得存储权限

1
termux-setup-storage

成功拿到存储权限后会在home目录生成storage 目录,并且生成若干目录(软连接),这些软连接都指向外置存储卡的相应目录应目录。

storage目录下的shared目录对应我们手机内部存储的根目录(/storage/emulated/0/),我们通过文件资源浏览器打开的就是这个/storage/emulated/0/目录,只不过在Termux/storage/emulated/0/对应的是storage目录下的shared目录。

将公钥发送到手机上

我这里将公钥通过QQ发送到手机上.
在这里插入图片描述然后打开手机QQ,接收电脑上发送过来的公钥.

复制公钥到.ssh目录下

打开Termux,进入用户home目录下:

1
cd ~

创建手机QQ接收文件的那个目录(tencent/QQfile_recv)的软连接.

1
ln -s /data/data/com.termux/files/home/storage/shared/tencent/QQfile_recv qq

在这里插入图片描述
然后复制qq软连接下的公钥到home目录下的.ssh目录中

1
mv ~/qq/id_rsa_2048.pub ~/.ssh

将公钥写入authorized_keys中

进入home目录下的.ssh目录.

1
cd ~/.ssh

将公钥写入authorized_keys文件中

1
cat id_rsa_2048.pub > authorized_keys

查看公钥

1
2
cat authorized_keys
ssh-rsa AAAAB3Nza.............................................................

在这里插入图片描述

开启sshd

1
sshd

获取链接信息

查看当前Termux用户信息

1
whoami

whoami的输出就是当前用户的信息:

1
u0_a391

查看Termux的ip地址

1
ifcofig

ifcofig运行效果如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
dummy0: flags=195<UP,BROADCAST,RUNNING,NOARP>  mtu 1500
inet6 fe80::bc05:1ff:fe55:4556 prefixlen 64 scopeid 0x20<link>
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 1000 (UNSPEC)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 66 bytes 4620 (4.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
......这里省略部分信息.
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.43.1 netmask 255.255.255.0 broadcast 192.168.137.255
inet6 fe80::76d2:1dff:fe00:73fd prefixlen 64 scopeid 0x20<link>
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 1000 (UNSPEC)
RX packets 1824 bytes 1096921 (1.0 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2529 bytes 366296 (357.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

这里的wlan0中的** inet 192.168.43.1中的192.168.43.1就是当前手机的ip地址**

1
2
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
inet 192.168.43.1 netmask 255.255.255.0 broadcast 192.168.137.255

使用正则取出正确的IP所在的行

ifconfig命令的输出很多,可以使用grep命令从ifconfig命令中筛选出:

1
inet 192.168.43.1  netmask 255.255.255.0  broadcast 192.168.137.255

这一行.

1
ifconfig |grep -E 'inet ([0-9]{1,3}(\.[0-9]{1,3}){3,3})\s.netmask.+broadcast'
1
ifconfig |grep -P '[0-9]{1,3}(?:\.[0-9]{1,3}){3}\s.netmask.+broadcast'

确保手机和电脑在同一个网络下

  • 电脑和手机链接到同一个WiFi下,
    • 这种方式可能会失败,
    • 我在电脑上和手机上分别登录到校园网后,使用Xshell链接不成功,估计是校园网有限制吧,这个问题,浪费我好长时间!,最后发现可以通过热点进行连接
  • 电脑链接到手机热点上
  • 手机链接到电脑的热点上
  • 手机USB线连接电脑,然后打开手机上的USB共享网络

经过我的测试两种热点连接方式都可以通过Xshell连接到手机上的Termux,所以,最好使用热点方式,或者USB共享网络。

使用Xshell链接Termux

在这里插入图片描述

设置链接常规信息

在弹出的窗口左侧点击连接填写上面获取到的的ip地址:
端口填写8020
在这里插入图片描述

设置用户身份验证信息

  • 点击窗口左侧的用户身份验证
  • 方法选择框中选择使用Public key,
  • 在用户名填写上面获取到的Termux用户名,
  • 选择上面创建好的秘钥,
  • 填写创建秘钥时的指定的秘钥密码.
  • 最后点击连接

在这里插入图片描述

链接成功效果

链接成功但是无法操作的情况

如果运行效果如下

1
2
3
Connecting to 192.168.137.191:8022...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.

这说明链接是成功的,但是无法操作,这是因为Termux现在不在前台,把Termux显示在前台即可,也就是显示在屏幕上.

保证Termux显示在手机屏幕最上方

如果Termux没有显示在前台的话Xshell无法操作.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Connecting to 192.168.137.191:8022...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
WARNING! The remote SSH server rejected X11 forwarding request.
Welcome to Termux!
Wiki: https://wiki.termux.com
Community forum: https://termux.com/community
Gitter chat: https://gitter.im/termux/termux
IRC channel: #termux on freenode
Working with packages:
* Search packages: pkg search <query>
* Install a package: pkg install <package>
* Upgrade packages: pkg upgrade
Subscribing to additional repositories:
* Root: pkg install root-repo
* Unstable: pkg install unstable-repo
* X11: pkg install x11-repo
Report issues at https://termux.com/issues
u0_a391@localhost  ~ 

Termux从前台切换到后台后连接失败,需要重新连接。

1
2
3
4
5
6
7
8
9
10
Socket error Event: 32 Error: 10053.
Connection closing...Socket close.

Connection closed by foreign host.

Disconnected from remote host(Termux) at 16:57:47.

Type `help' to learn how to use Xshell prompt.
[F:\~]$

如何重新链接

Termux切换到前台,然后点击Xshell菜单栏面的文件,然后点击重新连接
在这里插入图片描述
在这里插入图片描述

设置Termux常驻后台

一直将Termux显示在前台还是不方便,可以点击手机通知栏上的ACQUIRE WAKELOCK,让Termux常驻后台.这样Termux在后台的时候也可以保持和Xshell的连接。
在这里插入图片描述
常驻后台时的效果:
在这里插入图片描述

参考资料

https://blog.csdn.net/jacka654321/article/details/81145756

Linux执行多个命令

全部执行

使用英文分号将多个命令隔开,这样不管前面的命令执行是否成功,后面的命令都会执行

1
echo hello1;echo hello2;echo hello3

更新软件

1
apt update

查看已安装软件

1
apt list

tree

安装

1
pkg install tree

pstree

rsync

进入项目地址

1
cd blog/blog/

拉取远程分支

1
git pull origin master

查看更新

1
git status

一步到位

1
cd blog/blog/ && git pull origin master && git status

处理冲突或者其他操作

省略….

添加所有文件

1
2
git add .^
git status

提交

提交语句开始

1
git commit -m '

写入提交描述

省略…

描述结束符

1
'

推送到指定分支

1
git push origin master

输入GitHub用户名

1
lanlan2017

输入密码

省略…

首先先下载Termux

从应用商店下载安装即可,属于存储权限

安装proot

1
pkg install proot

获取root权限

1
termux-chroot

安装git并获取atilo

1
2
pkg install git
git clone https://github.com/YadominJinta/atilo

进去atilo下并获取权限

1
2
cd atilo/
chmod +x atilo

查看支持的版本

1
2
~/atilo ./atilo list  
alpine arch centos debian fedora kali opensuse parrot ubuntu ubuntults

安装ubuntu

1
./atilo install ubuntu

启动ubuntu

1
startubuntu

卸载ubuntu

1
./atilo remove ubuntu

安装centos

1
./atilo install centos

通过anLinux安装

先从应用商店下载安装anLinux,然打开anLinux,按提示安装。

安装centos

1
pkg install wget openssl-tool proot tar -y && hash -r && wget https://raw.githubusercontent.com/EXALAB/AnLinux-Resources/master/Scripts/Installer/CentOS/centos.sh && bash centos.sh

系统要求

System requirements:
Android 7.0 - 9.0 (10+ may have issues)
CPU: AArch64, ARM, i686, x86_64.
At least 200 MB of disk space.

安装termux

官网:
https://termux.com/
github仓库:
https://github.com/termux/termux-app

下载termux

f-droid 下载
Google Play 下载

更换国内源

更换Termux清华大学源,加快软件包下载速度.

官方方法

设置默认编辑器

1
export EDITOR=vi

编辑源文件

1
apt edit-sources

将原来的https://termux.net官方源替换为http://mirrors.tuna.tsinghua.edu.cn/termux

直接编辑源文件

上面是官方推荐的方法,其实还有更简单的方法,类似于Linux下直接去编辑源文件:

1
vi  $PREFIX/etc/apt/sources.list

修改效果

1
2
3
4
5
6
u0_a391@localhost~ cat $PREFIX/etc/apt/sources.list
# The main termux repository:
# deb https://termux.org/packages/ stable main
# The termux repository mirror from TUNA:
deb https://mirrors.tuna.tsinghua.edu.cn/termux stable main

更新软件

依次输入如下命令,更新软件:

1
2
pkg update
pkg upgrade

pkg命令介绍

基本命令
Termux除了支持apt命令外,还在此基础上封装了pkg命令,pkg命令向下兼容apt命令.apt命令大家应该都比较熟悉了,这里直接简单的介绍下pkg命令:

1
2
3
4
5
6
7
8
9
10
11
12
13
基本命令
Termux除了支持apt命令外,还在此基础上封装了pkg命令,pkg命令向下兼容apt命令.apt命令大家应该都比较熟悉了,这里直接简单的介绍下pkg命令:

pkg search <query> 搜索包
pkg install <package> 安装包
pkg uninstall <package> 卸载包
pkg reinstall <package> 重新安装包
pkg update 更新源
pkg upgrade 升级软件包
pkg list-all 列出可供安装的所有包
pkg list-installed 列出已经安装的包
pkg shoe <package> 显示某个包的详细信息
pkg files <package> 显示某个包的相关文件夹路径

Termux获取管理员权限

没有 root 的手机是没有 root 权限的。不过 termux 给我们提供了一个解决办法可以模拟 root 权限。
我们下载安装 proot

1
pkg install proot

然后执行下面的命令即可获得 root 权限

1
termux-chroot

root 时输入exit可以退回普通用户

Termux优化

要翻墙,不翻墙无法访问

终端配色

主要使用了zsh来替代bash作为默认shell.
使用一键安装脚本来安装,一步到位,顺便启动了外置存储,可以直接访问SD卡下的目录.

执行下面这个命令确保已经安装好了curl

1
sh -c "$(curl -fsSL https://github.com/Cabbagec/termux-ohmyzsh/raw/master/install.sh)" 

Android6.0以上会弹框确认是否授权,允许授权后Termux可以方便的访问SD卡文件.
脚本允许后先后有如下两个选项:

1
Enter a number, leave blank to not to change: 14 Enter a number, leave blank to not to change: 6

分别选择背景色和字体
想要继续更改挑选配色的话,继续运行脚本来再次筛选:

1
~/termux-ohmyzsh/install.sh

访问外置存储优化

执行过上面的zsh一键配置脚本后,并且授予文件访问权限的话,会在家目录生成storage目录,并且生成若干目录,软连接都指向外置存储卡的相应目录

创建QQ文件夹软连接

手机上一般经常使用手机QQ来接收文件,这里为了方便文件传输,直接在storage目录下创建软链接.

1
ln -s /data/data/com.termux/files/home/storage/shared/tencent/QQfile_recv qq

安装git

1
pkg install git

Termux 上搭建Hexo博客

安装nodejs长期支持版本

注意安装长期支持版的

1
pkg install nodejs-lts

卸载nodejs长期支持版本:

1
pkg unstall nodejs-lts

使用淘宝镜像

1
npm config set registry http://registry.npm.taobao.org

安装hexo

1
npm install hexo-cli -g

创建站点

用户主目录下,输入如下命令创建一个Hexo站点:

1
hexo init blogTest

注意必须在Termux自己的目录下才可以创建站点
如果在非Termux的目录下执行上面的命令,则会报错如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
npm WARN tar EPERM: operation not permitted, futime
npm WARN tar EPERM: operation not permitted, futime
npm WARN tar EPERM: operation not permitted, futime
npm WARN tar EPERM: operation not permitted, futime
npm WARN tar EPERM: operation not permitted, futime
npm WARN tar EPERM: operation not permitted, futime
npm WARN tar EPERM: operation not permitted, futime
npm WARN tar EPERM: operation not permitted, futime
npm ERR! cb() never called!

npm ERR! This is an error with npm itself. Please report this error at:
npm ERR! <https://npm.community>
WARN Failed to install dependencies. Please run 'npm install' manually!

进入站点

1
cd blogTest

启动本地服务器

1
hexo s

手机浏览器上进入网站

http://localhost:4000

在非Termux目录下写博客

虽然在Termux下面可以搭建好Hexo,但是不好的是:手机中无法通过其他markdown软件编辑Termux中的文件。虽然使用进入Termux中使用vim编辑也是可以的,但是很麻烦.

现在我只用git管理博客源码就行了,然后通过markdown编辑软件

1
ln -s /data/data/com.termux/files/home/storage/shared/blog blog
1
cd ~blog

克隆博客源码

1
git clone -b master https://github.com/lanlan2017/blog.git
1
git clone -b master https://github.com/lanlan2017/ReadingNotes.git

题外话

设置npm全局安装路径和全局缓存路径

可以不设置
cd ~
mkdir nodejs_data
cd ~/nodejs_data
mkdir npm_global
mkdir node_cache

1
npm config set cache "~/nodejs_data/node_cache"
1
npm config set prefix "~/nodejs_data/npm_global"

上面配置好的全局安装目录的信息会下载用户home目录下的.npmrc文件中

1
cat .npmrc
1
2
3
4
5
 u0_a391@localhost  ~  cat .npmrc 
registry=http://registry.npm.taobao.org
prefix=/data/data/com.termux/files/home/nodejs_data/npm_global
cache=/data/data/com.termux/files/home/nodejs_data/node_cache

取消自定义个npm全局安装路径

删除用户home目录下的配置文件.npmrc 中的prefixcache即可:

设置Linux环境变量

1
cp /etc/profile /etc/profile.bak
1
vim /etc/profile

在最后添加:

1
source /etc/profile

安装指定版本的nodejs

node有一个模块n,是专门用来管理node.js的版本的。

安装n模块

1
npm install -g n

升级node.js到最新稳定版

先获取root权限

1
termux-chroot
1
n stable

查看Nodejs历史版本

https://nodejs.org/en/about/releases/
点击上面的版本号即可看到安装的版本,例如点击v10,然后拉到最后,可以看到当前最新的nodejs 10的版本为:v10.17.0

1
node-v10.17.0.tar.xz                               22-Oct-2019 16:41            21514260

安装指定版本的nodejs

1
n v10.17.0

切换到指定版本的nodejs

输入

1
n

清除npm缓存

1
npm cache clean --force

参考资料

https://www.sqlsec.com/2018/05/termux.html
https://www.cnblogs.com/anyun/p/8328397.html
https://blog.csdn.net/flw8840488/article/details/90513873

Navicat premium 12 mysql-命令列界面 清屏功能

点击菜单栏上的查看,然后点击清除即可.
这里有一张图片

![这里有一张图片](https://img-blog.csdnimg.cn/20191025163345330.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzIxODA4OTYx,size_16,color_FFFFFF,t_70)