运维必备命令之tldr

本文介绍了如何在MacOS和Linux系统中安装tldr命令,提供详细的使用方法,包括更新缓存、查看帮助及平台特定操作。重点展示了tldr命令在编辑文件方面的Linux和macOS区别,适合开发者快速查阅命令用法。
摘要由CSDN通过智能技术生成

1. 安装tldr

macOS

brew install tldr

Ubuntu

apt install tldr

CentOS

yum install tldr

2. 使用帮助

由于目前的主力生产设备是MacBook Pro,因此以下所有的测试都是针对macOS,与其他OS可能有所不同,望周知。

$ tldr -h       
usage: tldr [-v] [OPTION]... SEARCH

available commands:
    -v                   print verbose output          
    --version            print version and exit        
    -h, --help           print this help and exit      
    -u, --update         update local database         
    -c, --clear-cache    clear local database          
    -l, --list           list all entries in the local database
    -p, --platform=PLATFORM select platform, supported are linux / osx / sunos / windows / common
    --linux              show command page for Linux   
    --osx                show command page for OSX     
    --sunos              show command page for SunOS   
    -r, --render=PATH    render a local page for testing purposes

3. 更新缓存

tldr --update 或 tldr -u

如果想要清除缓存

tldr --clear-cache 或 tldr -c

3. 使用帮助

如果想要获取命令的使用方法,可以使用tldr 命令 的格式,如:

$ tldr sed         

sed

Edit text in a scriptable manner.
More information: <https://ss64.com/osx/sed.html>.

- Replace the first occurrence of a string in a file, and print the result:
    sed 's/find/replace/' filename

- Replace all occurrences of an extended regular expression in a file:
    sed -E 's/regular_expression/replace/g' filename

- Replace all occurrences of a string [i]n a file, overwriting the file (i.e. in-place):
    sed -i '' 's/find/replace/g' filename

- Replace only on lines matching the line pattern:
    sed '/line_pattern/s/find/replace/' filename

- Print only text between n-th line till the next empty line:
    sed -n 'line_number,/^$/p' filename

- Apply multiple find-replace expressions to a file:
    sed -e 's/find/replace/' -e 's/find/replace/' filename

- Replace separator `/` by any other character not used in the find or replace patterns, e.g. `#`:
    sed 's#find#replace#' filename

- [d]elete the line at the specific line number [i]n a file, overwriting the file:
    sed -i '' 'line_numberd' filename

由于sed 命令的特殊性,以上操作是针对Linux OS的使用方法,如果限定macOS,可以使用tldr sed -p osx 或者 tldr sed --osx(仅macOS生效):

$ tldr sed -p osx

sed

Edit text in a scriptable manner.
More information: <https://ss64.com/osx/sed.html>.

- Replace the first occurrence of a string in a file, and print the result:
    sed 's/find/replace/' filename

- Replace all occurrences of an extended regular expression in a file:
    sed -E 's/regular_expression/replace/g' filename

- Replace all occurrences of a string [i]n a file, overwriting the file (i.e. in-place):
    sed -i '' 's/find/replace/g' filename

- Replace only on lines matching the line pattern:
    sed '/line_pattern/s/find/replace/' filename

- Print only text between n-th line till the next empty line:
    sed -n 'line_number,/^$/p' filename

- Apply multiple find-replace expressions to a file:
    sed -e 's/find/replace/' -e 's/find/replace/' filename

- Replace separator `/` by any other character not used in the find or replace patterns, e.g. `#`:
    sed 's#find#replace#' filename

- [d]elete the line at the specific line number [i]n a file, overwriting the file:
    sed -i '' 'line_numberd' filename

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值