Linux 常见命令

1.top

http://www.cnblogs.com/xd502djj/archive/2011/03/01/1968041.html

“top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器.”

 2.tail

http://en.wikipedia.org/wiki/Tail_%28Unix%29

File monitoring[edit]

tail has a special command line option -f (follow) that allows a file to be monitored. Instead of just displaying the last few lines and exiting, tail displays the lines and then monitors the file. As new lines are added to the file by another processtail updates the display. This is particularly useful for monitoring log files. The following command will display the last 10 lines of messages and append new lines to the display as new lines are added to messages:   tail -f /var/adm/messages

3.磁盘相关

du -sh * 显示当前目录下各个文件夹的大小

df -lh 磁盘使用情况

4.vim相关

| vim -

5.比较不同

参考http://blog.chinaunix.net/uid-14735472-id-111118.html

[root@localhost ~]# diff -urNa dir1 dir2

-a Treat all files as text and compare them
line-by-line, even if they do not seem to be text.

-N, --new-file
In directory comparison, if a file is found in
only one directory, treat it as present but empty
in the other directory.

-r When comparing directories, recursively compare
any subdirectories found.
-u Use the unified output format.

6.查找文件内容

http://www.cnblogs.com/zhangmo/p/3571735.html

例子:从当前目录开始查找所有扩展名为.in的文本文件,并找出包含”thermcontact”的行

find . -name "*.in" | xargs grep "thermcontact"

 

 grep -r "org.apache.log4j.jdbc.JDBCAppender" --include=*.*

 grep -r --include=*.py "statics_item" ./

 grep CallS -rn *

 grep -E 'str1|str2' filename

7.crontab 任务定时执行

在ubuntu下似乎与centOS下略有不同,网上搜索的资料需辨别使用。

 参考https://help.ubuntu.com/community/CronHowto

在查bug时候可以看系统错误日志/var/log/syslog 

一般如果要不打印错误日志,通过在命令后面加上 >/dev/null 2>&1

 22 SHELL=/bin/sh
 23 PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin
 24 # Order of crontab fields
 25 # minute    hour    mday    month   wday    command
26 */1 * * * * sh /home/<user>/testcrontab.sh >/dev/null 2>&1

在普通user模式下crontab -e 进入编辑模式,进行编辑,要进行最简单的运行测试时,shell脚本内容可以为

echo $(date +'%d.%m.%Y %H:%M')  >> testcrontab.log

,注意需要echo到一个文件,否则输出没法看到。 

修改crontab -e之后其实并不需要restart crontab,系统会自动按新配置执行。(重启的命令为sudo service cron restart)

 

注意/etc/crontab的内容,其中的PATH是否与预期相同,是否缺少了/usr/local/bin

 

rsync -av --exclude xoa-tomcat-temp/temp xoa-tomcat-temp zhengpeng.liu@10.3.17.87:~/

 

8.定期清除log

d=`date +%Y-%m-%d`
log_path=/data/web/nginx/access
i='access'
echo $i
cd $log_path && cp ${i}.log ${i}_log.${d} && echo "" > ${i}.log
find $log_path -name "*_log.*" -mtime +5 |xargs rm -rf {}

注意路径名不要是一个软链接,如果是软链接,需要将log_pass命名为/data/web/nginx/access/

分割文件 split -b 200m filename   newfilenameprefix

posted on 2014-12-12 22:18  majia1949  阅读(196)  评论(0编辑  收藏  举报

导航