Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Linux how to edit file command

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

This article is about how linux edits file commands. The editor thought it was very practical, so I shared it with you as a reference. Let's follow the editor and have a look.

This article is not only for beginners to learn, but also for me to learn Linux. When I write this article, I am also learning and understanding these basic commands, while keeping a memo in the future.

Sed command to view / edit the contents of the file

Introduction parameters:

-I: save the application to the original file after operation (if this parameter is not added, then any changes will not affect the contents of the original file, only the results will be output)-e: only display the processed results # to be written. # more commands can be viewed with sed-- help. Use:

# View the contents of line 3 of log.txt sed-n '3p' log.txt# view the contents of line 2-8 of log.txt sed-n' 2jing8p' log.txt# delete line 1 of log.txt (first line) sed-I '1d' log.txt# delete log.txt line 3-7 sed-I' 3 sed 7d' log.txt# delete log.txt last line (last line) sed-I'$d 'log.txt# delete log. All blank lines in txt sed-I'/ ^ $/ d 'log.txt# delete lines log.txt beginning with doubi sed-I'/ ^ doubi/'d log.txt# Delete lines ending with doubi sed-I'/ doubi$/'d log.txt# Delete all lines in the log.txt file sed-I'/ 233 bind d'log.txt# delete the first 233text sed-I'in the log.txt document Sed-I's log.txt# deletes all 233text in the log.txt file (g represents text that operates all matching rules) sed-I's log.txt# deletes all the 5th 233text in the log.txt file (5g represents the fifth matching rule) sed-I 'log.txt# replaces the first 233in the log.txt file with 666sed-I All / ver in the log.txt file is replaced by all / ver in the log.txt file (g represents the text that manipulates all matching rules) sed-I's ver in the log.txt file replace all / ver in the log.txt file Because there is a slash, you need to use\ escape, but single quotes make it impossible to escape, so change it to double quotes. Sed-I "s /\ / ver/doubi\ / /" log.txt# displays odd lines or even lines in the log.txt file sed-n'pash n'log.txt# odd lines sed-n'ntern log.txt# even lines # more commands can be viewed with sed-- help.

VI, VIM, Nano edit file content

VI introduction:

VI is a great text editor for Linux, but it also has some drawbacks, such as hassle. And vim is equivalent to the enhanced version of VI, mainly introducing VIM.

VIM introduction

# Open the log.txt file in the current directory. If not, a new log.txt file will be created (after installing vim, there is no difference between using vi and vim to open the file) vi log.txtvim log.txt# in command line mode, enter the following symbols and letters directly (case sensitive) # # enter edit mode (insert mode Press the Esc key to return to command line mode) dd## # Delete all contents in the file where the cursor is currently located dddG## copy cursor on the current line yy## paste the line you just copied yy## # undo the last operation (you can restore it with this error) UBG # Save the current file (: is the English colon): yy## # Save the current file content as log2.txt:w log2.txt## exit the current file: Qquit # do not save and force exit the current file: save and exit the current file: wq# more commands can be viewed with vi-- help / vim-- help.

Nano introduction

Nano is more suitable for beginners than VIM.

# Open the log.txt file in the current directory. If not, you can create a new log.txt file and enter the modified text content directly after entering the nano log.txt#. After modification, we can use this button to save the content Ctrl+O#. If you do not need to edit it, you can use this button to exit the current file Ctrl+X#. If you have modified but not saved before you exit, you will be reminded whether to save it. If you save, enter y, do not save n # and then you will be asked to enter the file name you want to save (default original file name, so press Enter enter directly, unless you want to save as another file name) Enter# more commands can be viewed by pressing F1 in the nano editing interface.

Thank you for reading! On linux how to edit the file command to share here, I hope the above content can be of some help to you, so that you can learn more knowledge. If you think the article is good, you can share it and let more people see it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report