`
wwwzhouhui
  • 浏览: 358802 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

linux 笔记

阅读更多
最近用linux比较多点,把一些工作中的命令记录下来。

1.ls 查看文件目录
   比如进入某个文件夹中,查看多少文件
   [root@as logs]# ls
   debug_1.log  debug_2.log

   列出文件结构
   查看详细信息 可以用 ls -l 或者 ls -all
   结果
  
[root@as logs]# ls -l
    total 8828
    -rw-r--r--  1 root root 1048627 Jul 30 10:11 debug_1.log
    -rw-r--r--  1 root root 1048632 Jul 30 10:11 debug_2.log
    -rw-r--r--  1 root root 1048628 Jul 30 10:11 debug_3.log
  

2.cat 查看某个文件全部内容
  如:
  [root@as logs]# cat warn.log 
   2009.07.30 10:07:19 Admin console: Using RSA certificates but they are not valid for the hosted domain

  如果感觉文件太大 想看一部分可以用 cat info.log |more
  more 后面可以可以跟现实多少行 如 cat info.log |more -100 这样就显示100行
 [root@as logs]# cat info.log |more -100
2009.07.30 10:09:45.294 use end resourceBound::::::::::::::::::::;8723
2009.07.30 10:09:45.295 use start login::::::::::::::::::::;test9350
2009.07.30 10:09:45.295 use login count::::::::::::::::::::;8725

  如果想抓一些文件中关键字显示出来 可以结合grep 实现
  如 我想抓取只显示出use start login 关键字的记录
 
[root@as logs]# cat info.log |grep 'use end resourceBound' |more -5
2009.07.30 10:09:45.294 use end resourceBound::::::::::::::::::::;8723
2009.07.30 10:09:45.296 use end resourceBound::::::::::::::::::::;8724
2009.07.30 10:09:45.297 use end resourceBound::::::::::::::::::::;8725
2009.07.30 10:09:45.297 use end resourceBound::::::::::::::::::::;8726
2009.07.30 10:09:45.298 use end resourceBound::::::::::::::::::::;8727

   如果只想统计多少个数不需要看详细记录 可以 -c 来统计
   如:
 
 [root@as logs]# cat info.log |grep 'use end resourceBound' -c
    1097
   [root@as logs]# 

3.删除不需要的文件 可以使用  rm 命令
  如:
  [root@as logs]# rm info.log 
  rm: remove regular file `info.log'?

  会提示你确定要删除吗?确定就回车执行删除操作
  如果 不需要提示删除 可以使用 rm -f  info.log
  如果 想把文件和文件夹一起删除也不需要提示 可以使用
  rm -rf info.log
4.复制命令 cp
  复制文件
 
[root@s209 20090702-06:06]# cp tsung.log    zzz.log

5.如果监控程序运行查看日志 常用
 [root@s209 20090702-06:06]# tail -f tsung.log

6 查看系统进程
  ps aux
7 杀死一些进程
  kill -9  id
8 linux 文件大小打开有限制 默认好像是1024个
  如果修改文件大小限制 可以如下操作
 
[root@s209 20090702-06:06]# ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 32768
max locked memory       (kbytes, -l) 32

   先查看一下数量 修改的话可以使用
   ulimit -n 65536
   修改成65536个
9 如果想时时观看CPU 内存情况 可以用TOP
 [root@s209 20090702-06:06]# top

top - 11:14:43 up  1:52,  1 user,  load average: 0.17, 0.06, 0.04
Tasks:  96 total,   2 running,  94 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.2%us,  0.2%sy,  0.0%ni, 99.7%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   2075396k total,   540356k used,  1535040k free,   103632k buffers
Swap:  2031608k total,        0k used,  2031608k free,   257064k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                
 2395 root      15   0 29280 4764 3508 S    0  0.2   0:20.08 Xorg                                                                   
 2415 gdm       15   0 12444 3840 3216 S    0  0.2   0:05.81 at-spi-registry                                                        
 4966 root      15   0  2200  996  792 R    0  0.0   0:00.03 top  

10.有时候想记录cpu 内存等信息把他输入到指定的文件中保存下来,方便之后的统计工作
   用sar 命名
 
 sar 5 0 -r -e 15:30:00 > datamem.txt
  

  上述脚本疾苦内存情况输出到datamem.txt文件中, -e 和 时间是 说明到下午3点30结束
   5 是没隔5秒记录一次 -r 指定记录内存情况
 
 sar 5 0  -e 15:30:00 > data.txt

  这个脚本是记录CPU 情况 用法和上面一样。
11 启动定时任务,有时候需要让系统定时帮我们做一些事情用crontab
   编辑crontab -e
  
[root@s208 log]# crontab -e


    */15 * * * *  tsung restart
~

    编写*/15 * * * *  tsung restart 该脚本 每格15分钟执行一次
    启动定时脚本命令
   
/etc/init.d/crond   start

    关闭定时脚本命令
   
 /etc/init.d/crond   stop

定时任务  */15 * * * * 说明可以查看相关别的文档
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics