将当前目录下(包括子目录)中所有文件中的apple替换为iPhone
find - search for files in a directory hierarchy
sed - stream editor for filtering and transforming text
{} 代表文件
; 每个文件执行一个command
+ 一共执行一个command
find ./* -exec %cmd% {} \;
find ./* -exec sed -i 's/apple/iphone/g' {} \;
root@25902ace80e2:/home/test# find ./* -exec echo arg: {} \+
arg: ./test.txt ./test2 ./test2/test2.txt
root@25902ace80e2:/home/test# find ./* -exec echo arg: {} \;
arg: ./test.txt
arg: ./test2
arg: ./test2/test2.txt
替换文件中的apple为iPhone
-i 进行文件的修改
sed -i 's/apple/iphone/g'
单引号替换双引号
sed -i s#\'#\"#g test.txt
sed -i "s/'/\"/g" test.txt
删除当前test文件夹中keep文件之外的所有文件
grep print lines matching a pattern
grep -v keep:-v, –invert-match keep文件之外的所有文件
xargs: build and execute command lines from standard input
find ./test/ | grep -v keep | xargs rm -rf