当前位置: 移动技术网 > 科技>操作系统>Linux > 好玩的Linux命令-1

好玩的Linux命令-1

2019年08月21日  | 移动技术网科技  | 我要评论

邵松高,鲍鱼15p,博狗官方haobc

ag:比grep、ack更快的归递搜索文件内容

1:首先在linux创建个sh文件->ag.sh

2:在ag.sh里面输入如下内容并保存

#!/bin/bash
set -x
temp_dir=$(mktemp -d leslie.guan.xxxxxx)
cd ${temp_dir}
wget https://github.com/ggreer/the_silver_searcher/archive/master.zip
tar_dir=$(unzip *.zip)
tar_dir=${tar_dir%%/*}
tar_dir=${tar_dir##*:}
cd ${tar_dir}
apt-get install -y automake pkg-config libpcre3-dev zlib1g-dev liblzma-dev --force-yes
./build.sh && make install
cd ../../
rm -rf ${temp_dir}
ag -v
set +x

3:执行./ag.sh就会去安装了,完事后可以用ag  "helloword"命令去寻找所有文件中包含helloword的文件并列出所在行数等。主要是带有颜色。

tig:字符模式下交互查看git项目,可以代替git命令

安装

ubuntu环境通过apt-get安装tig

sudo apt-get update
sudo apt-get install tig

centos环境安装通过yum安装tig

sudo yum update
sudo yum install tig

mac环境安装通过brew安装tig

brew update
brew install tig

使用

1、通过man查看tig命令

  //centos、ubuntu
  man tig

  //mac
  man ls tig
2、tig中位置移动是vim命令
3、tig查看所有历史修改

  yanmin:360tmk yanmin$ tig

4、tig show查看某次commit的所有修改

  tig show 65a05ee92c83a5827449d62be42322e1b2a58e39

5、tig filename查看某个文件所有历史修改

  yanmin:360tmk yanmin$ tig pom.xml

mycli:mysql客户端,支持语法高亮和命令补全,效果类似ipython,可以替代mysql命令

  我用的是centos7,版本如果7以下可能会存在问题,比如自带python的原因。

  安装:

  # yum -y install epel-release

  # yum -y install python-pip

  # yum install python-devel

  清除缓存

  # yum clean all

  安装mycli

  # pip install mycli

  中间如出现报错按照指引完成即可

  测试

  输入mysql命令即可进行补全

jq:json文件处理以及格式化显示,支持高亮,可以替换python –m json.tool

  简单介绍:json 数据的书写格式是: 名称/对象。 json的结构基于两点,“名称/值”的集合 ,在不同的语言中,它可以被理解为对象(object),记录(record),结构(struct),字典(dictionary),哈希表(hash table),键列表(keyed list)等 。值的有序列表 多数语言中被理解为数组(array)。

  json的基础结构说明

  对象是属性、值的集合。一个对象开始与”{” ,结束于”}”。每一个属性名和值间用”:”分隔。每个属性间用”,”分隔。
  值可以是字符串,数字,逻辑值,数组,对象,null。
  数字:整数或浮点数
  字符串:在双引号中
  逻辑符:true和false
  数组:在方括号中
  对象:在花括号中
  null: 代表空
  安装:centos:#yum install jq

     ubuntu:#apt-get install jq

  格式:

jq [options] filter [files]
**options:**
--version:输出jq的版本信息并退出
--slurp/-s:读入整个输入流到一个数组。
--raw-input/-r:不作为json解析,将每一行的文本作为字符串输出到屏幕。
--null-input/ -n:不读取任何输入,过滤器运行使用null作为输入。一般用作从头构建json数据。
--compact-output /-c:使输出紧凑,而不是把每一个json对象输出在一行。
--colour-output / -c:打开颜色显示
--monochrome-output / -m:关闭颜色显示

--ascii-output /-a:指定输出格式为ascii

-raw-output /-r :如果过滤的结果是一个字符串,那么直接写到标准输出(去掉字符串的引号)
filter

.   : 默认输出
.foo: 输出指定属性,foo代表属性。
.[foo] :输出指定数组元素。foo代表数组下标。
.[]:输出指定数组中全部元素
, :指定多个属性作为过滤条件时,用逗号分隔
| : 将指定的数组元素中的某个属性作为过滤条件
files:示例文件
[{"hostcompany":"beijing autelan technology","hostmodel":"cs-vic-2000-c","hostsn":"01010730b12014a00477","mac":"00:1f:64:ce:f3:8e","cpumodel":"mips 74kc v4.12","cpusn":"000000","memorymodel":"abcdefg","memorysn":"000000","boardsn":"01010730b12014a00477","networkcardmac":"00:1f:64:ce:f3:8f","lowfremodel":"ar9344","lowfresn":"000000","hignfremodel":"ar9582","hignfresn":"000000","gpsmodel":"abcdefg","gpssn":"000000","meid_3g":"a000004e123abd2","company_3g":"ztemt incorporated","modelof3g":"mc271x","snof3g":"a000004e123abd2","iccid":"89860314400200885980","operators":"ctcc","hardversion":"1.20","firmwareversion":"1.0.6.29"}]

  示例:

$ jq . apinfo.json   
[
  {
    "firmwareversion": "1.0.6.29",
    "hardversion": "1.20",
    "operators": "ctcc",
    "iccid": "data data",
    "snof3g": "a000004e123abd2",
    "modelof3g": "mc271x",
    "company_3g": "ztemt incorporated",
    "meid_3g": "a000004e123abd2",
    "memorysn": "000000",
    "memorymodel": "abcdefg",
    "cpusn": "000000",
    "cpumodel": "mips 74kc v4.12",
    "mac": "00:1f:64:ce:f3:8e",
    "hostsn": "01010730b12014a00477",
    "hostmodel": "cs-vic-1999-c",
    "stcompany": "beijing autelan technology",
    "boardsn": "01010730b12014a00477",
    "networkcardmac": "00:1f:64:ce:f3:8f",
    "lowfremodel": "ar9344",
    "lowfresn": "000000",
    "hignfremodel": "ar9582",
    "hignfresn": "000000",
    "gpsmodel": "abcdefg",
    "gpssn": "000000"
  }
]

jq '.[]' apinfo.json 
{
  "firmwareversion": "1.0.6.29",
  "hardversion": "1.20",
  "operators": "ctcc",
  "iccid": "data data",
  "snof3g": "a000004e123abd2",
  "modelof3g": "mc271x",
  "company_3g": "ztemt incorporated",
  "meid_3g": "a000004e123abd2",
  "memorysn": "000000",
  "memorymodel": "abcdefg",
  "cpusn": "000000",
  "cpumodel": "mips 74kc v4.12",
  "mac": "00:1f:64:ce:f3:8e",
  "hostsn": "01010730b12014a00477",
  "hostmodel": "cs-vic-1999-c",
  "stcompany": "beijing autelan technology",
  "boardsn": "01010730b12014a00477",
  "networkcardmac": "00:1f:64:ce:f3:8f",
  "lowfremodel": "ar9344",
  "lowfresn": "000000",
  "hignfremodel": "ar9582",
  "hignfresn": "000000",
  "gpsmodel": "abcdefg",
  "gpssn": "000000"
}

  测试:

$ jq -r .[].mac apinfo.json 
00:1f:64:ce:f3:8e

$ jq -r '.[] | .mac' apinfo.json 
00:1f:64:ce:f3:8e

$ jq -r '.[] |.mac, .gpssn' apinfo.json 
00:1f:64:ce:f3:8e
000000

jq -r '.[].mac, .[].gpssn' apinfo.json 
00:1f:64:ce:f3:8e
000000

shellcheck:shell脚本静态检查工具,能够识别语法错误和不规范的写法。

  安装:

  在ubuntu里直接apt install shellcheck

  在centos里yum install -y epel-release 

       yum install -y shellcheck

查看某进程的网卡流量

      yum install libpcap nethogs -y

  另一种安装方式:

      yum install cabal-install

  指令安装目录:~/.cabal/bin

      cabal update

      cabal install cabal

      cabal install shellcheck

这样就可以使用如下命令安装

      cabal install shellcheck

fzf:命令行下模糊搜索工具,能够交互式智能搜索并选取文件或者内容,配合终端ctrl+r历史命令搜索

具体使用方法可参考如下

https://www.cnblogs.com/harriszh/p/7616966.html

讲的很不错,可以多学学

pathpicker(fpp):在命令行输出中自动识别目录和文件,支持交互式,配合git非常好用

git diff head-8 --stat| fpp

 

htop:提供更美观,更方便的进程监控工具,替代top命令

  用f2编辑配置,用f9发送信号,用f3搜索进程,用f5切换,通过空格设置颜色标注进程条目

  • -s 选项 : 按指定的列排序。例如,htop -s pid 命令会按 pid 列的大小排序来显示。
  • -u 选项 : 显示指定的用户的进程信息列表。例如,htop -u himanshu 命令会只显示出用户名为 himanshu 的相关进程。
  • -d 选项 : 设置刷新的延迟时间。例如,htop -d 100 命令会使输出在1秒后才会刷新(参数 -d 的单位是10微秒)。

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网