Shell:无比强大的shell之json解析工具jq , Linux命令行解析json, jq解析 json 实例

  JSON是前端编程经常用到的格式,对于PHP或者Python,解析JSON都不是什么大事,尤其是PHP的json_encode和json_decode,干的相当的漂亮。Linux下也有处理处理JSON的神器:jq。 对于JSON格式而言,jq就像sed/awk/grep这些神器一样的方便,而也,jq没有乱七八糟的依赖,只需要一个binary文件jq,就足矣。下面我们看下jq的使用。 1. 安装 官网:https://stedolan.github.io/jq/download/ Linux jq 1.5 is in the official Debian and Ubuntu repositories. Inst… Read More

Linux Shell系列教程之(二十) Shell 脚本中一些特殊符号:# ; ;; . , / \\ ‘string’| ! $ ${} $? $$ $* \”string\”* ** ? : ^ $# $@ `command`{} [] [[]] () (()) || && {xx,yy,zz,…}~ ~+ ~- & \\<...\\> + – %= == !=

在shell中常用的特殊符号罗列如下: # ;   ;; . , / \\ ‘string’| !   $   ${}   $? $$   $* \”string\”* **   ? : ^ $#   $@ `command`{}   [ ()   (()) ||   && {xx,yy,zz,…}~   ~+   ~-   &   \\<…\\>   + – %=   ==   != # 井号 (comments) 这几乎是个满场都有的符号,除了先前已经提过的\”第一行\” #!/bin/bash 井号也常出现在一行的开头,… Read More

Linux Shell系列教程之(十九) Shell test 命令

Shell中的 test 命令用于检查某个条件是否成立,它可以进行数值、字符和文件三个方面的测试。 数值测试 参数 说明 -eq 等于则为真 -ne 不等于则为真 -gt 大于则为真 -ge 大于等于则为真 -lt 小于则为真 -le 小于等于则为真 实例演示: num1=100 num2=100 if test $[num1] -eq $[num2] then echo '两个数相等!' else echo '两个数不相等!' fi 输出结果: 两个数相等! 代码中的 执行基本的算数运算,如: #!/bin/bash a=5 b=6 result=$[a+b] # 注意等号两边不能有空格 echo "result 为: $result" 结果为: result 为: 11 字符串测试 参数… Read More

Linux Shell系列教程之(十八) Shell 基本运算符

Shell 和其他编程语言一样,支持多种运算符,包括: 算数运算符 关系运算符 布尔运算符 字符串运算符 文件测试运算符 原生bash不支持简单的数学运算,但是可以通过其他命令来实现,例如 awk 和 expr,expr 最常用。 expr 是一款表达式计算工具,使用它能完成表达式的求值操作。 例如,两个数相加(注意使用的是反引号 ` 而不是单引号 ‘): #!/bin/bash val=`expr 2 + 2` echo "两数之和为 : $val" 执行脚本,输出结果如下所示: 两数之和为 : 4 两点注意: 表达式和运算符之间要有空格,例如 2+2 是不对的,必须写成 2 + 2,这与我们熟悉的大多数编程语言不一样。 完整的表达式要被 ` ` 包含,注意这… Read More

Linux:SSH 无密码连接到 Google Cloud 实例, FileZilla连接 Google Cloud, IntelliJ IDEA连接 Google Cloud, google cloud compute instance, google cloud platform

1. 通过浏览器连接到实例 直接通过网络浏览器在 Google Cloud Platform 控制台中进行 SSH 连接: In the Cloud Platform Console, go to the VM Instances page.GO TO THE VM INSTANCES PAGE In the list of virtual machine instances, click SSH in the row of the instance that you want to connect to. 通过浏览器连接到实例时需要注意一些事项。如需了解详情,请参阅通过浏览器进行 SSH 连接。   2. 通过命令行连接到实例 您可以使用 gcloud 命令行工具轻松连接到您的… Read More

Shell: 无密码读写Mysql数据库, 无密码被分导出Mysql数据库, mysqldump , Connect to MySQL Without Root Password on Terminal

设置Mysql登录信息 How to Set MySQL Root Password 一般shell连接数据库的方法是: mysqladmin -u root password YOURNEWPASSWORD 无登录链接数据库的方法是创建或者修改 ~/.my.cnf 文件 Now create the config file ~/.my.cnf and add configurations below in it (remember to replace mysqluser and mysqlpasswd with your own values). [mysql] user=user password=password 如果你还是用了mysqldump,那么可… Read More

Linux: shell实现多线程, Forking / Multi-Threaded Processes | Bash, shell 线程池

按照shell语法,后一个前台命令必须等待前一个前台命令执行完毕才能进行,这就是所谓的单线程程序。如果两条命令之间有依赖性还好,否则后一条命令就白白浪费了等待的时间了。 网上查了一遍,shell并没有真正意义上的多进程。而最简单的节省时间,达到“多线程”效果的办法,是将前台命令变成后台进程,这样一来就可以跳过前台命令的限制了。 引用网上例子:   实例一:全前台进程: #!/bin/bash #filename:simple.sh starttime=$(date +%s) for ((i=0;i<5;i++));do { sleep 3;echo 1>>aa && endtime… Read More

Linux:cURL 命令详解,以及实例, curl auth, curl 模拟登陆,快速网站测压, curl 爬虫, curl Command Download File Example, How to quickly stress test a web server

  linux curl是一个利用URL规则在命令行下工作的文件传输工具。它支持文件的上传和下载,所以是综合传输工具,但按传统,习惯称url为下载工具。 一,curl命令参数,有好多我没有用过,也不知道翻译的对不对,如果有误的地方,还请指正。 -a/--append 上传文件时,附加到目标文件 -A/--user-agent <string> 设置用户代理发送给服务器 - anyauth 可以使用“任何”身份验证方法 -b/--cookie <name=string/file> cookie字符串或文件读取位置 - basic 使用HTTP基本验证 -B/--use-ascii 使用ASCII /文… Read More

Linux: SSH报错 WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! 解决方案, Remove key from known_hosts, Fix Offending key in ~/.ssh/known_hosts file

  今天是用google cloud ssh登录的时候,发生以下报错: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! Someone could be eavesdropping on you right now (man-in-the-middle attack)! It i… Read More

Linux: 命令行获取公共 IP 和 私有IP, How To Find My Public IP Address, Determine Your Private and Public IP Addresses, From Command Line On a Linux

  1. 命令行获取私有IP Use dig command for determining my public IP address: 打开 Terminal application. 输入以下命令行:Type the following dig (domain information groper) command on a Linux, OS X, or Unix-like operating systems to see your own public IP address assigned by the ISP: dig +short myip.opendns.com @resolver1.opendns.com 或者 dig TXT +short o-o.myaddr.l… Read More

Linux:命令行git简单使用, git指令, 命令行操作git

开始正文 Git简介 这篇文章不介绍github,介绍git命令行,但是有必要对git和github是什么进行一个说明。你可能听说过github,据说github是世界上最大的同性社交网站。当然是开玩笑的。简单的说,github是一个开放源代码保存的地方,github也是合作项目开发的首选地。 那么git呢,git是一个仓库,一个你用来保存代码的地方。 所以,当我在github上注册了帐号之后,我可以将我的代码上传到git上进行保存,也可以大家合用一个仓库来合作开发。 当然,git本身是开放的,别人可以看到你的源代码,如果是想变成不开放的,那么你就需要像github付费了。你可以去coding看一看,c… Read More

Linux: url打开phpmyadmin, how to access phpmyadmin in lamp

问题: I have installed LAMP on ubuntu, and I want to acced PhpMyAdmin, and I don’t know it’s URL. I tried to access this URL : http://localhost/phpmyadmin 解决方法: Just in case someone doesn’t know this (i didn’t for sometime), after running this command to reconfigure phpmyadmin sudo dpkg-reconfigure -plow phpmyadmin 如果在C… Read More

Ubuntu 17.04 / 17.10 安装 LAMP, Linux Apache2 Mysql PHP, 以及phpmyadmin, INSTALLING LAMP ON UBUNTU 17.04 / 17.10

env.sh #!/usr/bin/env bash # https://websiteforstudents.com/installing-lamp-ubuntu-17-04-17-10/ # https://websiteforstudents.com/install-password-protect-phpmyadmin-ubuntu-17-04-17-10/ # INSTALLING LAMP ON UBUNTU 17.04 / 17.10 # STEP 1: 更新服务器 sudo apt-get update && sudo apt-get dist-upgrade && sudo apt-get autor… Read More

Linux: shell脚本获取网页快照(网页截图)并生成缩略图

获取网页快照并生成缩略图可分两步进行: 1、获取网页快照 2、生成缩略图   获取网页快照 这里我们用 phantomjs 来实现。关于 phantomjs 的详细用法可参考官方网站。   1、安装 我的环境是CentOS6.5,安装时直接下载 tarball 然后解压即可。 最新版参看:https://github.com/ariya/phantomjs,下载地址为: https://phantomjs.org/download.html # wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.8-linux-i686.ta… Read More