【Linux命令解密—tee】轻松解决无权保存vim已修改文件的尴尬!

tee—轻松解决无权保存vim已修改文件的尴尬!

一、背景

在类Linux环境下工作的小伙伴们,肯定都有过这种尴尬:就是在修改一个高权限的文件(比如系统配置文件)的时候,最后提交的时候,发现无权修改此文件!然后只能灰溜溜的保存一份,再次用管理员权限打开,再复制一遍!!!是不是感觉非常不爽。。。

但是今天呢,介绍一种优雅搞定此问题的方法!如下:

二、解决方法

那就是 tee 命令。
其实tee命令是可以用来提高写入文件的权限等级的。

具体的操作就是在文件保存的时候输入:w !sudo tee %,这时候vim会提醒你输入sudo密码,输入之后,文件就保存了。是不是很方便呢。

三、命令详解

下面是 Mac 环境下的 man 手册信息!

# man tee

TEE(1)                    BSD General Commands Manual     

NAME
     tee -- pipe fitting
SYNOPSIS
     tee [-ai] [file ...]

DESCRIPTION
     The tee utility copies standard input to standard output, making a copy in zero or more files.  The output is unbuffered.

     The following options are available:

     -a      Append the output to the files rather than overwriting them.

     -i      Ignore the SIGINT signal.

     The following operands are available:

     file  A pathname of an output file.

     The tee utility takes the default action for all signals, except in the event of the -i option.

     The tee utility exits 0 on success, and >0 if an error occurs.

STANDARDS
     The tee function is expected to be POSIX IEEE Std 1003.2 (``POSIX.2'') compatible.

BSD                              June 6, 1993

参数:
-a  附加到既有文件的后面,而非覆盖它。
-i  忽略中断信号。

示例:

// 将用户输入的数据同时保存到文件"file1""file2"# tee file1 file2
// 追加写入"file"# tee -a file

——2020-04-16——

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值