Linux基本命令

1、将用户权限授权:chown 用户名 文件名

2、ls /dev/ | grep sd 查看磁盘

3、gparted 磁盘分区工具

4、sudo mount -r /dev/sda6 /mnt/window1 挂在磁盘

5、sudo mount -t cifs -o username="Administrator" //192.168.1.102/G /home/sky/person/ 将windows共享后的文件挂在linux目录下,进行文件共享

6、ps aux | grep idea.sh 查看idea.sh进程

7、sudo vi /etc/hosts 配置本机ip

8、全局搜索 find . -name '*.java'|xargs grep default.his

9、vi /etc/rc.local 添加开机启动

10、iconv -f gbk -t utf8 mysql.txt > mysql.txt.utf8 linux显示windows正常文本

11、使用正则表达式查询 find . -name "[a]*.txt"

12、mysql 连接 http://jingyan.baidu.com/article/363872ec3263236e4ba16f07.html

13、设置终端中使用vim :set -o vi

14、sudo mount -t ntfs-3g /dev/sda3 /mnt/ -ro force

15、python -m SimpleHTTPServer 80 开启文件服务

16、查看win详细进程路径:wmic process where caption="java.exe" get caption,commandline /value

17、转换文件编码 iconv -f gb2312 -t utf-8 aaa.txt >bbb.txt  忽略其中无效字符 iconv -c  -f gb2312 -t utf8 test.txt  

18、杀死对应目录的进程   ps -ef |grep java|grep tp8480 |awk '{print $2}' |xargs kill 

19、截取文本文件的部分文件

    1)截取1.txt中第20行以后的文件然后再截取30行以后的文件 cat 1.txt | tail -n +20 | head -n 30 >> 2.txt   

           tail -n 1000:显示最后1000行

           tail -n +1000:从1000行开始显示,显示1000行以后的

           head -n 1000:显示前面1000行

    2)wc -l 1.txt 来统计文件行数

    3)sed -n '5,10p' filename 这样你就可以只查看文件的第5行到第10行。 这里的sed表示string edit流编辑器,p表示print打印。

    4) awk 参考 http://www.cnblogs.com/ggjucheng/archive/2013/01/13/2858470.html

    awk -v a='update '\' -F, '{print a $1}' tmp.txt => update 'we //-v变量

20、统计某个字段的出现的次数:grep -o ZYQueryPatientInfo.*mobile frontgateway-params.log |wc -l

 21、cat localhost_access_log.2017-03-29.txt|head -n 1|grep -o ' '|wc -l    统计第一行空格出现的次数

22、awk ' $10 > 30000 ' localhost_access_log.2017-03-29.txt 显示第十个单词大于30000的行

23、alias 显示配置的环境变量 alias vi='vim' 设置简写

24、系统环境变量相关:

1)/etc/profile  设置path、user、mail;hostname、hitsize、umask

2)/etc/bashrc 规划umask功能 可能不同linux在其他路径

3)/etc/profile.d/*.sh 

25、个人环境变量相关:

1)~/.bash_history历史按键命令

2)~/.bashrc 个人环境变量配置

26、sort命令

root@debian:/tmp# cat 1.txt
1 a 11
3 c 33
2 b 22
4 a 22

空格分隔,以第二列字符串排序:

root@debian:/tmp# cat 1.txt |sort -t ' ' -k 2
1 a 11
4 a 22
2 b 22
3 c 33

空格分隔,以第三列整数排序:

root@debian:/tmp# cat 1.txt |sort -t ' ' -k 3 -n
1 a 11
2 b 22
4 a 22
3 c 33

27、find . -type f -exec ls -l {} \;   //{}   花括号代表前面find查找出来的文件名。

-type  查找某一类型的文件,诸如:

- 块设备文件。

- 目录。

- 字符设备文件。

- 管道文件。

- 符号链接文件。

- 普通文件。

28、抓包 主机ip:192.168.137.129 服务器ip220.181.100.243 or  220.181.100.241 or  220.181.100.242 or 220.181.100.244  写入文件dump.pcap

tcpdump -n -i eth0 src 192.168.137.129 and 220.181.100.243 or  220.181.100.241 or  220.181.100.242 or 220.181.100.244 and tcp -w dump.pcap

tcpdump -i any port 6404 -w 1.pcap 不指定网卡,抓本机回环包制定lo

tpcdump --nn -i eth0 port 80 查看tcp握手

tpcdump --nn -i -X eth0 port 80 查看tcp参数

tpcdump --nn -i -X eth0 port 80 or arp 包括arp地址解析协议

 

29、查看抓包数据:wireshark dump.pcap

30、卸载软件 sudo apt-get autoremove --purge 软件名

31、linux 批量杀进程 ps -ef|grep autoacc|grep -v grep | awk '{print "kill -9 " $2}'|sh

32、chsh -s /bin/zsh zsh作为默认bash

33、unzip frontgateway.jar -d tmp  将jar解压到tmp目录

        cd tmp 先切换到tmp目录

        tar xvf frontgateway.jar .  当前目录压缩成jar

34 virtualBox 死机 http://blog.sina.com.cn/s/blog_4c451e0e0100smar.html

VBoxManage controlvm win7 savestate 睡眠

35、查看对应PID的程序执行路径:ll /proc/25075 | grep redis

 

36、查看 bash: cannot create temp file for here-document: No space left on device

文件排序   1)ls -lhS  2)du -h * | sort -n查找最大文件

37、zip file 中的文件内容中含有字符串ABCDEF的文件:

for file in *.zip; do if unzip -p $file | strings | grep "ABCDEF" > /dev/null; then echo $file; fi; done

38、查看压缩文件里面的内容(zip文件)

zgrep “INFO” DPServer*

39、java进程执行时 如果进程有 nohub &,则不能按ctrl + z,执行kill -9会导致僵尸进程。参考:https://www.jianshu.com/p/f0baed94128e

使用此命令杀死所有僵尸进程:ps -e -o ppid,stat | grep Z | cut -d” ” -f2 | xargs kill -9

40、grep 正则

//查看13连续数字
grep -e "\d\{13\}" trace_debug.log

//查看重复出现的单词
grep -e "\(\w\+\) \1" 1.txt

 41、批量修改文件名

#!/bin/bash
for files in `ls trace_debug.2020-05-12*`
do
    # 截取文件名的前两个字符
    fname=${files:0:20}
    # 截取文件的后四个字符
    bname=${files:0-4}
    # 拼接成文件名
    filename=${fname}11${bname}
    # 更改文件名
    mv $files $filename
done

 42、awk 打印 逗号

双引号:

awk '{print "\""}'        #放大:awk '{print "  \"  "}'

使用“”双引号把一个双引号括起来,然后用转义字符\对双引号进行转义,输出双引号。


单引号:

awk '{print "'\''"}'       # 放大: awk '{print  "  '  \  '  '   " }'

使用一个双引号“”,然后在双引号里面加入两个单引号‘’,接着在两个单引号里面加入一个转义的单引号\',输出单引号。

awk -F, '{OFS=","; print "("$1, "'\''"$2"'\''" , $3"),"}' city > cityCopy.txt #
OFS分隔符
统计gc时间大于0.1s的行

awk '{
if(match($10, "^0.") && $10 > 0.1){
print $0
} else if(match($11, "^0.") && $11 > 0.1){
print $0
}
}' gc.log

 

 

posted @ 2016-07-01 23:20  水底的土豆  阅读(393)  评论(0)    收藏  举报