리눅스/VIM

VIM(VI) - Readonly파일, 권한오류파일 작성하기.

꿈꾸는 사람_Anthony 2021. 6. 22. 17:25
반응형

사용할 명령

위 명령은 Bash Command({cmd})를 실행한다. 이때 주어진 범위의 내용을 Bash Command의 STDIN으로 넘겨준다.

STDIN/STDOUT/STDERR에 대한 설명은 다음 링크를 참고하자(link)

 

이를 적용하여 다음 상황을 해결할 수 있다.

시나리오

1. 해당 내용을 다른 파일에 저장하고 싶을 때

:w !sudo cat >file
:w !sudo tee file

위 코드 중 마음에 드는 것 아무거나 사용해도 된다.

2. 해당 내용을 현재 파일에 저장하고 싶을 때

:w !sudo tee %
:w !sudo cat >%

이때 %는 현재 파일을 가리킨다.

 

참고

https://www.layerstack.com/resources/tutorials/How-to-save-a-file-in-Vim-Vi-without-Root-Permission-with-sudo-on-Linux-Cloud-Servers

 

https://vimhelp.org/editing.txt.html#%7Bfile%7D

 

Vim: editing.txt

editing.txt For Vim version 8.2. Last change: 2021 May 27 VIM REFERENCE MANUAL by Bram Moolenaar Editing files edit-files 1. Introduction edit-intro 2. Editing a file edit-a-file 3. The argument list argument-list 4. Writing writing 5. Writing and quitting

vimhelp.org

https://www.lesstif.com/lpt/linux-tee-89556049.html

반응형