Chinaunix首页 | 论坛 | 博客
  • 博客访问: 188792
  • 博文数量: 45
  • 博客积分: 1657
  • 博客等级: 上尉
  • 技术积分: 765
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-13 12:42
文章分类

全部博文(45)

文章存档

2012年(1)

2011年(4)

2010年(6)

2009年(3)

2008年(31)

分类: IT职场

2008-08-11 19:30:51

grep
指定文件
grep "pattern" afile
当前文件夹
grep "pattern" *
当前文件夹及子文件夹
grep -r "pattern" *

find
当前文件夹
find . -maxdepth 1 -name "patter"
当前文件夹及子文件夹
find . -name "patter"
不查找指定的文件夹
find . -path "the_path_to_neglect" -prune -o -print

sed
替换
sed 's/old/new/g' afile                 没有g的话,仅替换第一次出现
sed -n 's#import#\#include\gp' afile    紧跟s后的字符被认为是新的分隔符,-n和p一起用表示只打印发生变化的行删除
sed '/import/ d' afile                   删除含有import的行

注:
sed 默认把更改的流输到标准输出,不改变参数文件
而我的sed 's/old/new/g' test.c > test.c 出错了,生成临时文件,没有恢复过来
 

find实用命令
find . -type d -exec chmod 700 {} \;            修改当前目录下的所有目录的权限
find . -type f -size +8k -exec ls -l {} \;      查看当前目录及子目录下大于8K普通文件信自息
find / user $LOGNAME                            查看当前用户所有文件和目录

                                                                                               

高级:
find
-print True;  print the full file name on the standard output, followed by a newline.   If
              you are piping the output of find into another program and there  is  the  faintest
              possibility  that  the  files  which you are searching for might contain a newline,
              then you should seriously consider using the ‘-print0’ option instead of  ‘-print’.
              See  the  UNUSUAL FILENAMES section for information about how unusual characters in
              filenames are handled.
-wholename pattern
              File  name  matches  shell pattern pattern.  The metacharacters do not treat ‘/’ or
              ‘.’ specially; so, for example,
                        find . -wholename ’./sr*sc’
              will print an entry for a directory called ’./src/misc’ (if one exists).  To ignore
              a  whole  directory  tree,  use -prune rather than checking every file in the tree.
              For example, to skip the directory ‘src/emacs’ and all files and directories  under
              it, and print the names of the other files found, do something like this:
                        find . -wholename ’./src/emacs’ -prune -o -print
sed
    context address:
    把含有you的行进行world文本替换
    sh$ sed -e '/you/s,world,mom,g' <<" EOF"
    Hello world.
    Hello world. I love you.
    CTRL+D  下面为输出
    Hello world.
    Hello mom. I love you.
    sh$
    其中的,是任意的特殊字符,/you/中的you是addr-pattern
    取反值加!符号
    sh$ sed -e '/you/!s,world,mom,g' <<" EOF"
    Hello world.
    Hello world. I love you.
    CTRL+D  下面为输出
    Hello mom.
    Hello world. I love you.
    sh$
    \(..\)
    保存匹配的字符,如s/\(love\)able/\1rs,loveable被替换成lovers。
    &
    保存搜索字符用来替换其他字符,如s/love/**&**/,love这成**love**。
    \<
    锚定单词的开始,如:/\
阅读(1168) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~