command line pearls 2 - TODO

目录

  • 热身

    • tee

    • find

    • grep

  • 忘记sudo

  • PHP扩展

  • 替换指定行

  • 添加指定行

热身

tee

tee tee.txt

hello tee # Ctrl+ C

cat tee.txt # hello tee

互动: tee和echo有何区别?

man tee
# The tee utility copies standard input to standard output, making a copy in zero or more files

find

find /etc/nginx -name "nginx.conf" # /etc/nginx/nginx.conf

互动: 打印文件树还可以使用什么命令?

man find
# walk a file hierarchy

man tree
# tree - list contents of directories in a tree-like format.

grep

grep -rn console.zhgcloud.com
man grep
# grep, egrep, fgrep, zgrep, zegrep, zfgrep -- file pattern searcher

忘了sudo

:w !sudo tee % > /dev/null
:w !{cmd} # 执行外部命令{cmd} 并将当前缓冲区内容从标准输入传入

sudo tee > /dev/null # 将标准输入输入输出到文件并忽略标准输出

% # %是vim中保存当前编辑文件路径的只读寄存器

PHP扩展

echo 'extension=swoole.so' >> $(php  -i | grep 'Loaded Configuration File' | awk -F '=>' '{print $2}')
php  -i | grep 'Loaded Configuration File' # 筛选php配置信息: Loaded Configuration File => /Users/kevin/.phpbrew/php/php-7.1.15/etc/php.ini

| awk -F '=>' '{print $2}' # 指定'=>'分隔符打印第二个元素

echo 'extension=swoole.so' >> # 将字符串追加输出到指定文件
man awk
# awk - pattern-directed scanning and processing language

替换指定行

添加指定行

参考

  • How does :w !sudo tee % work

  • 如何在vim保存时获得sudo权限

  • AWK 简明教程

你可能感兴趣的:(command line pearls 2 - TODO)