【部分转】Linux命令行(1)
[root@localhost test]#pwd 显示当前目录路径
[root@localhost test]# mkdir test 创建文件夹
[root@localhost test]# touch test.txt 创建文件
[root@localhost test]# cp test.txt test2.txt 把test.txt文件当前文件夹下复制出个test2.txt
[root@localhost test]# cp test.txt /hzh/test 将test.txt 复制到/hzh/test 目录下
[root@localhost test]# rm -rf bb 删除bb目录(不对目录下的每个文件提醒删除)
[root@localhost test]# ls *.log | xargs rm -f 批量删除包含某关键字的文件
[root@localhost test]# grep -n "xxx" 1.txt 统计文件中包含某关键字的个数
grep "xxx" 1.txt | wc -l 统计文件中包含某关键字的行数
[root@localhost test]#locate aa.txt
查整个系统中的aa.txt文件,locate\slocate命令后面跟文件或文件夹。不过在执行这个命令之前要先更新数据库,所以选执行 updatedb 命令。
服务器时间:
[root@localhost test]#date 显示服务器当前时间
[root@localhost test]#date -s mm/dd/yyyy
date -s hh:mm:ss 修改服务器时间
[root@localhost test]#ntpdate pool.ntp.org 同步网络时间
切分日志:
[root@localhost test]#tail -n 10000 b.log>a.log
[root@localhost test]#tail -f a.log 显示最新append
列出占用大空间的日志文件:
du -sh * | egrep '^[0-9.]{1,3}G' 正则匹配
查看某个程序进程号和占用资源:
[root@localhost test]#ps -aux|grep NAME
批量关掉包含某关键字进程:
[root@localhost test]#ps -ef|grep NAME |grep -v grep|cut -c 9-15|xargs kill -9
[root@localhost test]#ps x|grep gas|grep -v grep |awk NAME|xarg kill -9
查看磁盘空间:
[root@localhost test]#free -m
根据关键字查找其在某文本中的行数:
[root@localhost test]#grep "STRING" FILENAME | wc -l
远程拷贝
scp -p port user@serverip:/home/user/filename /home/user/filename
目标路径 本地路径
发送一封邮件
grep -B 6 -C 6 error.log > 1.log
cat 1.log | sendEmail -f hehe@jumei.com -t yunpengp@mail.com -u "haha" -s autodiscover.corp.mail.com

浙公网安备 33010602011771号