mac自带的sed和linux表现不一致
需要安装 gnu-sed
, 推荐 Homebrew 安装
1 2 3 4 5 6 7 8 9 10 11
| brew install gnu-sed
vi ~/.zshrc
export PATH="/usr/local/opt/gnu-sed/libexec/gnubin:$PATH"
source ~/.zshrc
|
再试,就可以了!
1 2 3 4 5
| echo "a,b,c,d" |sed 's/,/\n/g' a b c d
|
npm换源
更换镜像即可解决,以淘宝的镜像为例:
1. 临时使用
1
| npm --registry https://registry.npm.taobao.org install express
|
验证是否成功
2. 持久使用
1
| npm config set registry https://registry.npm.taobao.org
|
验证是否成功
3. 恢复使用官方镜像
1
| npm config set registry https://registry.npmjs.org
|
pip换源
国内的一些源:
1. 临时使用
在使用pip的时候在后面加上-i参数,指定pip源,例如:
1
| pip install scrapy -i https://pypi.tuna.tsinghua.edu.cn/simple
|
2.永久修改
修改 ~/.pip/pip.conf (没有就创建一个), 内容如下:
1 2
| [global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple
|
mac 安装Homebrew报错
安装Homebrew时有时会出现:
1
| Failed to connect to raw.githubusercontent.com port 443: Connection refused
|
这时,解决办法也很简单,就是配置一个代理,把下面的内容配置到你的 /etc/hosts
中即可解决
1
| 199.232.28.133 raw.githubusercontent.com
|
CentOS 相关命令
防火墙相关:
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
| systemctl start firewalld.service
systemctl stop firewalld.service
systemctl enable firewalld.service
systemctl disable firewalld.service
firewall-cmd --reload
firewall-cmd --list-ports
firewall-cmd --query-port=80/tcp
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --remove-port=80/tcp --permanent
|
查看端口访问情况:
1 2 3 4 5 6 7 8 9 10 11
| netstat -ntlp
netstat -lnp|grep 443
ps 1777
kill -9 1777
|
apache命令:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| vim /etc/httpd/conf/httpd.conf
LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_http_module modules/mod_proxy_http.so
ProxyPass /wx http://0.0.0.0:8080/wx ProxyPassReverse /wx http://0.0.0.0:8080/wx
systemctl start httpd
systemctl stop httpd
systemctl restart httpd
status httpd.service
|
后台运行:
1 2 3 4 5
| nohup /root/runoob.sh &
ps -aux | grep "runoob.sh"
|
软链接报错相关
若出现类似下面的报错,可以尝试修复软连接来解决:
1 2
| $ /usr/local/bin/python3 --version no such file or directory: /usr/local/bin/python3
|
解决方法:
1 2 3 4 5 6
| cd /usr/local/bin/ rm python3
ln -s /usr/local/opt/python@3.8/bin/python3 /usr/local/bin/python3
|
测试一下是否可用:
1 2
| $ /usr/local/bin/python3 --version Python 3.8.6
|
Homebrew更新相关
如果你之前折腾过不少导致你的Homebrew有点问题,那么可以尝试使用如下方案:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| brew doctor
cd "$(brew --repo)" git fetch git reset --hard origin/master
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" git fetch git reset --hard origin/master
brew update
|
关闭brew执行命令时自动更新:
1 2
| export HOMEBREW_NO_AUTO_UPDATE=true
|
Crontab定时任务
以定时启动爬虫为例
1 2 3 4 5 6 7
| $which scrapy /usr/local/bin/scrapy
*/5 * * * * cd /home/iSpiders && /usr/local/bin/scrapy crawl iTorrents >>/home/log/iTorrents.log 2>&1
|
命令详解
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| crontab -e
crontab -l
service crond stop
service crond restart
service crond start
|
crontab的命令构成为 时间+动作,其时间有分、时、日、月、周五种,操作符有:
*
取值范围内的所有数字
/
每过多少个数字
-
从X到Z
,
散列数字
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
| * * * * * cmd
3,15 * * * * cmd
3,15 8-11 * * * cmd
3,15 8-11 */2 * * cmd
3,15 8-11 * * 1 cmd
30 21 * * * cmd
45 4 1,10,22 * * cmd
10 1 * * 6,0 cmd
0,30 18-23 * * * cmd
0 23 * * 6 cmd
* */1 * * * cmd
* 23-7/1 * * * cmd
|