Search and replace files in linux
1. How to use child commands with find?find . -name classes -exec rm -r -f {} \;
Please note there is a blank between {} and \;
2. How to use grep?
grep PATTERN
Recursively search
grep -r string_pattern *
3. How to use locate to find file?
updatedb
locate **/*.xml
4. How to find which jar constians the specified file?
find . -name '*.jar' -exec unzip -l {} \; | grep 'Access.java\|Archive:'
find . -name '*.jar' -exec unzip -l {} \; | grep 'Access.java\|Archive:' | sed 's#\(.*Access.java.*\)#\x1b
5.How to replace the text in a file?
sed -in-place -e 's/are/were/g' test.txt
6. How to replace the text in a folder?
find . -name "*.txt" -exec sed -in-place -e 's/are/were/g' {} \;
7. \ is the escape char.So if you want to replace C:\Windows with D:\Windows
sed -in-place -e 's/C:\/windows/D:\/Widnows/g' test.txt
Reference
http://www.linuxsir.org/main/?q=node/137
http://blog.csdn.net/chaiqi/archive/2007/03/05/1521276.aspx
页:
[1]