Dec 23, 2008

unix/linux 命令

1. To search files containing "some text" using grep
grep -rn "text to find" *
-r descends into subdirectories.
-n print line number

Other options:
-i switch ignores the case
-l switch outputs only the names of files in which the text occurs (instead of each line containing the text),

grep 特殊字符(比如查找 -d)
使用 --
在 unix shell 和其他很多命令中,-- 表示其后面没有options (options 指 -d, --data,  --data=file 等)了,也就是剩下的都是 positional parameters
所以查找 -d 用
grep -- -d

2. find and remove files with one find command on fly
To remove multiple files such as *.jpg or *.sh with one command find, use

find . -name "FILE-TO-FIND"-exec rm -rf {} \;

OR

find . -type f -name "FILE-TO-FIND" -exec rm -f {} \;

The only difference between above two syntax is that first command can remove directories as well where second command only removes files.

0 comments: