用过的shell命令——持续更新

1,显示文件的各种属性

stat --help

用例:stat -c "%s" abc.txt

注释:显示abc.txt的大小

2,文件编码类型查看

file --help

用例:file -i abc.txt

注释:显示abc.txt的文件编码类型(貌似不是很全)

3,文件编码类型转换

iconv --help

用例:iconv abc.txt -f GBK -t UTF-8 > cba.txt 

注释:将abc.txt从GBK编码转换成为UTF-8编码(有的时候貌似会出问题,用$?检查一下)

 4,控制光标位置

tput --help

用例:tput cup 34 23

注释:将光标移动至34行 23列

扩展阅读:http://www.ibm.com/developerworks/cn/aix/library/au-learningtput/

5,脚本后台运行方法

nohup --help

用例:nohup bash test.sh a b >> /dev/null

注释:将test.sh脚本的输出重定向至null(不输出) a ,b 是脚本参数

bash -c help

用例:bash -c "(bash test.sh)&"

注释:将脚本test.sh后台运行

6,如何截取掉一个字符串的后n个字符

head --help

用例:echo $num | head -c -4

注释:head截取掉了后面3个字符

${value:o0-n}

用例:echo ${a:o0-4}

注释:参见http://www.cnblogs.com/pmars/archive/2013/02/17/2914444.html

7,查看路由连接信息(本地ip-路由-路由-ip2)

traceroute --help

用例:traceroute 61.135.169.105

注释:会列出网络上所有经过的路由节点IP

8,如何删除文件中的一行或者几行

sed --help

用例:sed -i '40d;41d' file

注释:用sed遍历文件,将40和41行删除,分隔符为分号“;”

9,查看已登录用户

w --help

用例:w

注释:查看当前已登录用户信息

10,查看登录历史信息

last --help

用例:last

注释:查看linux的登录历史,记录所有登录过的信息

原文地址:https://www.cnblogs.com/pmars/p/2798530.html