很实用的Linux常用命令
工作期间常用的linux命令,这些linux常用命令可以帮助提高效率.
- 1) 连接mkdir与cd命令,无需再cd一次,mkdir后直接进入目录
- [root@Centos test]# function MC() { mkdir "$@" && eval cd "\"\$$#\""; }
- 2) 利用alias快速返回上N级目录
- [root@Centos test]# alias ..4="cd ../../../../"
- [root@Centos test]# ..4
- 3) 控制标准输出与错误的流向
- 禁止错误输出 2> /dev/null
- 错误输出至文件 2> out.error
- 禁止标准输出 1> /dev/null
- 禁止错误与标准输出 >/dev/null 2>& 1
- 4) 查看用户登录时间
- [root@Centos test]# ac -d SomeUser
- 总登录时间
- [root@Centos test]# ac -p SomeUser
- 5) 追加key至远程主机
- [root@Centos test]# ssh-copy-id -i ~/.ssh/id_rsa.pub 10.0.0.200
- [root@Centos test]# ssh-copy-id -i ~/.ssh/id_rsa.pub '-p YourPort_here 10.0.0.200' #非默认22端口
- 6) 利用python的simplehttp共享文件
- alias WS='python -c "import SimpleHTTPServer;SimpleHTTPServer.test()"'
- WS命令操作后,本地会开启8000端口监听,成为一个简单的http server.
- 7) 快速创建文件
- touch a{1..10}
- 8) awk快速统计并罗列出所有文件及文件夹大小
- du -sk ./*|sort -n|awk 'BEGIN{a[1]="K";a[2]="M";a[3]="G";}{total=total+$1;x=$1;y=1;while(x>1024){x=(x+1023)/1024;y++;}printf("%g%s\t%s\n",int(x*10)/10,a[y],$2);}END{y=1;while(total>1024){total=(total+1023)/1024;y++;}printf("Total: %g%s\n",int(total*10)/10,a[y]);}'
- 9) curl查看httpd服务类型
- curl -I 10.0.0.200 2> /dev/null|grep Server
- 10) 快速重命名文件
- [root@Centos test]# rename .asp .php *.asp
- 把所有.asp的文件,重命名为.php