Linux常用命令基本用法

自己的一些Linux常用的命令的记录

find

可用正则表达式

使用find搜索指定路径下的指定文件

find [path] -name [filename]
# 不忽略大小写
find [path] -iname [filename]
# 忽略大小写

使用find搜索指定路径下的除指定文件外的所有文件

find [path] ! -name [filename]

使用find搜索指定路径下的等于(+为大于,-为小于)指定大小的文件

find [path] -type f -size [size]
find [path] -type f -size +[size]
find [path] -type f -size -[size]

使用find搜索指定路径下的权限为777的文件

find [path] -type f -perm 777

sed

sed -i "1,3"d /root/test
# 删除/root/test的第1到3行
sed -i "/hello/d" /root/test
# 删除/root/test中含有关键词hello的行
sed -i "/hello/a word" /root/test
# 在/root/test中含有关键词hello的行后一行追加一行内容为word
sed -i "/hello/i word" /root/test
# 在/root/test中含有关键词hello的行前一行追加一行内容为word
sed -n "/hello/=" /root/test
# 查找/root/test中关键词hello所在行的行号
sed -i "s/\(hello\).*/\1word/" /root/test
# /root/test中,在关键字hello所在行替换掉关键字hello之后的内容为word
sed -i "s/hello/word/g" /root/test
# 将/root/test中的hello替换为word

posted @ 2018-07-22 23:30  EmrysChe  阅读(128)  评论(0编辑  收藏  举报