{"id":21859,"date":"2023-10-01T04:04:47","date_gmt":"2023-10-01T04:04:47","guid":{"rendered":"https:\/\/linuxways.net\/?p=21859"},"modified":"2023-10-01T04:04:47","modified_gmt":"2023-10-01T04:04:47","slug":"how-to-edit-a-file-in-linux-ubuntu-with-sudo","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-edit-a-file-in-linux-ubuntu-with-sudo\/","title":{"rendered":"How to Edit a File in Linux\/Ubuntu with sudo?"},"content":{"rendered":"<p><strong>Editing<\/strong> is a crucial process in writing as it improves the organization, quality, readability, and clarity of the text. Editing improves the quality of text by eliminating punctuation errors, spelling mistakes, grammar issues, etc. In this article, we will demonstrate a few file-handling methods that are useful for editing a file in Linux\/Ubuntu 22.04 LTS.<\/p>\n<h2><a id=\"post-21859-_ljks07h0rocp\"><\/a>Prerequisites<\/h2>\n<p>In order to follow this article, we will require<\/p>\n<ul>\n<li>System with Ubuntu 22.04 LTS Installed.<\/li>\n<li>A user account with sudo privileges.<\/li>\n<li>A text editor (We will use Nano and Vim in this article).<\/li>\n<\/ul>\n<h2><a id=\"post-21859-_vwi4ezl9toa3\"><\/a>What is Sudo?<\/h2>\n<p><strong>Sudo<\/strong> (superuser do) is a command line utility that temporarily elevates regular user accounts to have root privileges. When a user runs the sudo command, they are prompted for a password of the user account, after which the user is granted root privilege.<\/p>\n<h2><a id=\"post-21859-_3bed6nqhhfgp\"><\/a>How to Edit a File in Linux\/Ubuntu with Sudo?<\/h2>\n<p>We will discuss a few file handling methods used for file editing Ubuntu using the below command line editors<\/p>\n<ul>\n<li>Using Nano Text Editor<\/li>\n<li>Using Vim Text Editor<\/li>\n<\/ul>\n<h2><a id=\"post-21859-_bxx8w22b1byi\"><\/a>How to Edit Files in Ubuntu\/Linux Using Nano Text Editor?<\/h2>\n<p>Nano is a powerful, lightweight text editor for Unix-like systems. Nano comes pre-installed and is the default text editor for Ubuntu 22.04 LTS. Nano has pre-defined shortcut keys for effective file handling. We can access a file in Nano by entering the sudo nano command followed by the path of the file that needs to be edited:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">sudo<\/span> <span class=\"kw2\">nano<\/span> <span class=\"sy0\">\/<\/span>etc<span class=\"sy0\">\/<\/span>apt<span class=\"sy0\">\/<\/span>sources.list<\/div><\/div>\n<h1><a id=\"post-21859-_1kpghntoqwvo\"><\/a><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"113\" class=\"wp-image-21860\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-1.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-1.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-1-300x17.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-1-1024x57.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-1-768x42.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-1-1536x85.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/h1>\n<p>We will be prompted for a password and after authentication, we will have access to the file.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"1224\" class=\"wp-image-21861\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-2.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-2.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-2-300x179.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-2-1024x612.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-2-768x459.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-2-1536x918.png 1536w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-2-501x300.png 501w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>Nano editor has short-cut keys on the bottom of the screen which can be useful for file editing. These keys are invoked with the \u201cCtrl\u201d key.<\/p>\n<p>Some ways of text manipulation using Nano Text Editor are discussed below:<\/p>\n<h2><a id=\"post-21859-_awowmmuuon3d\"><\/a>How to Select Particular Text in Nano Text Editor?<\/h2>\n<p>Text can be selected in the Nano Text Editor by pointing the cursor at the line\/word\/paragraph\/word and by pressing \u201cAlt +A\u201d to fix the point. This will set the mark and will be indicated by \u201cMark Set\u201d at the bottom screen as shown below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"1224\" class=\"wp-image-21863\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-3.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-3.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-3-300x179.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-3-1024x612.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-3-768x459.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-3-1536x918.png 1536w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-3-501x300.png 501w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>We can then navigate right and left by using the arrow keys on the keyboard to select text. <img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"1221\" class=\"wp-image-21864\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-4.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-4.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-4-300x179.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-4-1024x611.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-4-768x458.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-4-1536x916.png 1536w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-4-501x300.png 501w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<h2><a id=\"post-21859-_pqmnlptw53yo\"><\/a>How to use Nano Editor to Copy, Cut, or Paste Text?<\/h2>\n<p>Cut, copy, and paste commands are used very frequently while editing Text. We can Copy and Cut text by first navigating to the text and then by selecting text using \u201cAlt+A\u201d. After the selection of text, we can press<\/p>\n<p>Alt+6 and Ctrl+K for copy and Cut respectively. After we either Copy or Cut. the text will not be highlighted anymore. We can then navigate to where we would like to Paste the text and Paste text using Ctrl+U.<\/p>\n<p>For example, below is an example of a whole line copied and pasted to line 1 in a file:<\/p>\n<p>An example of Cut and Paste is shown below. In this example, text is Cut using \u201cCtrl+K\u201d and pasted at the beginning of the file:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"1227\" class=\"wp-image-21865\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-6.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-6.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-6-300x180.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-6-1024x614.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-6-768x460.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-6-1536x920.png 1536w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-6-501x300.png 501w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<h2><a id=\"post-21859-_r7qgmgncto0i\"><\/a>How to Find and Replace Text in Nano Text Editor?<\/h2>\n<p>Find and replace is also used extensively while editing texts. In the Nano text editor, we can use the shortcut \u201cCtrl+\\\u201d to find a word or string pattern. We can enter the string pattern that we want to replace with and press enter as shown below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"1221\" class=\"wp-image-21866\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-7.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-7.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-7-300x179.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-7-1024x611.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-7-768x458.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-7-1536x916.png 1536w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-7-501x300.png 501w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>We will then be prompted to enter the word or string pattern that we want to replace the selected string pattern as shown below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"1225\" class=\"wp-image-21867\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-8.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-8.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-8-300x179.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-8-1024x613.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-8-768x459.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-8-1536x919.png 1536w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-8-501x300.png 501w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>After pressing enter, all the occurrences of the string pattern will be highlighted and we will be prompted for confirmation:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"1224\" class=\"wp-image-21868\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-9.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-9.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-9-300x179.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-9-1024x612.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-9-768x459.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-9-1536x918.png 1536w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-9-501x300.png 501w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>We can Press \u201cy\u201d at the prompt to replace all occurrences of the selected string.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"1221\" class=\"wp-image-21869\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-10.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-10.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-10-300x179.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-10-1024x611.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-10-768x458.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-10-1536x916.png 1536w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-10-501x300.png 501w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>As seen from the above image, the selected string pattern \u201cdemo\u201d is replaced by the string pattern \u201ctest\u201d. Additionally, we will also get a notification of the number of occurrences replaced.<\/p>\n<h2><a id=\"post-21859-_a8z8bbb6be5b\"><\/a>How to Save Text and Exit Nano Editor?<\/h2>\n<p>After editing the file, we can use \u201cCtrl+O\u201d and Ctrl+X to save and exit the nano respectively.<\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"1222\" class=\"wp-image-21870\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-11.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-11.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-11-300x179.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-11-1024x611.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-11-768x458.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-11-1536x917.png 1536w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-11-501x300.png 501w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/strong><\/p>\n<h2><a id=\"post-21859-_yl41169hdfsf\"><\/a>How to Utilize Vim Text Editor for Editing Files in Ubuntu\/Linux?<\/h2>\n<p>Vim is a free-to-use and highly adaptive text editor. Vim editor furnishes three modes to manage files:<\/p>\n<ul>\n<li><strong>Command Mode: <\/strong>Command mode is enabled by default. It supports commands like redo, undo, replace, etc. The \u201cEsc\u201d key is pressed in order to exit command mode.<\/li>\n<li><strong>Insert Mode: <\/strong>is enabled by \u201ci\u201d. It enables text insertion. We can exit command mode by pressing the \u201cEsc\u201d key.<\/li>\n<li><strong>Visual Mode:<\/strong> is enabled by \u201cCtrl+V\u201d. It is used for selecting text for copy, cut, delete, paste, and other operations.<\/li>\n<\/ul>\n<h2><a id=\"post-21859-_927kxaf5v1cz\"><\/a>How to Install Vim Tex Editor on Linux\/Ubuntu?<\/h2>\n<p>Before installing Vim Editor, the apt repository is updated by executing the following sudo command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">sudo<\/span> apt update<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"613\" class=\"wp-image-21871\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-12.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-12.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-12-300x90.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-12-1024x307.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-12-768x230.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-12-1536x460.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>After the apt repository is updated, Vim can be installed by running the following command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">sudo<\/span> apt <span class=\"kw2\">install<\/span> <span class=\"kw2\">vim<\/span><\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"1178\" class=\"wp-image-21872\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-13.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-13.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-13-300x173.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-13-1024x589.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-13-768x442.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-13-1536x884.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"1103\" class=\"wp-image-21873\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-14.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-14.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-14-300x162.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-14-1024x552.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-14-768x414.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-14-1536x827.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>From the above image, it can be seen that Vim is installed successfully.<\/p>\n<p>We can access a file in the Vim text editor by entering the sudo vi command followed by the path of the file that needs to be edited:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">sudo<\/span> <span class=\"kw2\">vi<\/span> <span class=\"sy0\">\/<\/span>Files<span class=\"sy0\">\/<\/span>samplefile1.txt<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1942\" height=\"108\" class=\"wp-image-21874\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-15.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-15.png 1942w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-15-300x17.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-15-1024x57.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-15-768x43.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-15-1536x85.png 1536w\" sizes=\"auto, (max-width: 1942px) 100vw, 1942px\" \/><\/p>\n<p>We will be prompted for a password and after authentication, we will have access to the file. Some ways of text manipulation using Vim Text Editor are discussed below:<\/p>\n<h2><a id=\"post-21859-_42q60fni3m7m\"><\/a>How to Select Particular Text in VimText Editor?<\/h2>\n<p>Text can be selected in Vim Text Editor by first entering \u201cVisual Mode\u201d. \u201cV\u201d can be used to select a complete line while \u201cv\u201d is used to select text. The below example shows the selection of the complete line:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"1088\" class=\"wp-image-21876\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-16.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-16.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-16-300x159.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-16-1024x544.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-16-768x408.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-16-1536x816.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<h2><a id=\"post-21859-_furnro7zzxjv\"><\/a>How to Cut, Copy, and Paste Text in Vim Text Editor?<\/h2>\n<p>In order to Cut, Copy, and Paste text in the Vim text editor, a user is required to switch mode to <strong>visual mode <\/strong>and select text. \u201cY\u201d and \u201cY\u201d are used to copy text and line respectively. Similarly, \u201cd\u201d is selected to cut specific text while \u201cD\u201d is used to cut the entire line. Finally, \u201cp\u201d is used to paste text while \u201cP\u201d is used to paste the entire line. Below is an example of copying a line:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1936\" height=\"1282\" class=\"wp-image-21879\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-17.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-17.png 1936w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-17-300x199.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-17-1024x678.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-17-768x509.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-17-1536x1017.png 1536w\" sizes=\"auto, (max-width: 1936px) 100vw, 1936px\" \/><\/p>\n<p>From the above image, we can see that the complete line \u201cWhat is Network Congestion?\u201d is copied and pasted. An example of \u201cCut and Paste\u201d is shown below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1940\" height=\"1326\" class=\"wp-image-21890\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-18.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-18.png 1940w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-18-300x205.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-18-1024x700.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-18-768x525.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-18-1536x1050.png 1536w\" sizes=\"auto, (max-width: 1940px) 100vw, 1940px\" \/><\/p>\n<p>From the above example, we can see that a complete line \u201cCauses of Network Congestion\u201d is cut and then pasted.<\/p>\n<h2><a id=\"post-21859-_5b94px1max02\"><\/a>How to Find\/Replace Text Using Vim Text Editor?<\/h2>\n<p>We have to enter Visual mode to first select string\/line and then replace text. Vim uses the \u201c%s\u201d parameter for searching while \u201cg\u201d replaces that word. For example, if we want to replace the word \u201cCauses\u201d with \u201cReasons\u201d in the line \u201cCauses of Network Congestion\u201d, we will first select a complete line by pressing \u201cV\u201d:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1940\" height=\"1322\" class=\"wp-image-21891\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-19.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-19.png 1940w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-19-300x204.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-19-1024x698.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-19-768x523.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-19-1536x1047.png 1536w\" sizes=\"auto, (max-width: 1940px) 100vw, 1940px\" \/><\/p>\n<p>Then, for the find and replace operation, we will enter in the \u201cCommand mode\u201d. Then, to replace \u201cCauses\u201d with \u201cReasons\u201d, We will run the following command after entering in command mode:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"sy0\">%<\/span>s<span class=\"sy0\">\/<\/span>Causes<span class=\"sy0\">\/<\/span>Reasons<span class=\"sy0\">\/<\/span>g<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1942\" height=\"1326\" class=\"wp-image-21892\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-20.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-20.png 1942w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-20-300x205.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-20-1024x699.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-20-768x524.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-20-1536x1049.png 1536w\" sizes=\"auto, (max-width: 1942px) 100vw, 1942px\" \/><\/p>\n<p>After entering the above command, we will press enter. This will replace the word \u201cCauses\u201d with \u201cReasons\u201d in the above line only as shown below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1944\" height=\"1324\" class=\"wp-image-21893\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-21.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-21.png 1944w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-21-300x204.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-21-1024x697.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-21-768x523.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-21-1536x1046.png 1536w\" sizes=\"auto, (max-width: 1944px) 100vw, 1944px\" \/><\/p>\n<p>We can see from the image below that the find and replace operation is successfully executed.<\/p>\n<h2><a id=\"post-21859-_jjb9vzif8epz\"><\/a>How to Save Files and Close Files in Vim Text Editor?<\/h2>\n<p>We can save and close the file by entering the \u201cCommand mode\u201d and running the following command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\">:wq<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1940\" height=\"1326\" class=\"wp-image-21894\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-22.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-22.png 1940w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-22-300x205.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-22-1024x700.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-22-768x525.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21859-22-1536x1050.png 1536w\" sizes=\"auto, (max-width: 1940px) 100vw, 1940px\" \/><\/p>\n<h2><a id=\"post-21859-_k4r3ojha6hv3\"><\/a>Conclusion<\/h2>\n<p>File handling operations like text selection, cut, copy, paste, find, and replace, etc., can be performed on files in Linux\/Ubuntu OS by using a text editor like Nano, Vim, etc. In this article, we have discussed a few file-handling methods that are useful for editing a file in Linux\/Ubuntu 22.04 LTS.<\/p>","protected":false},"excerpt":{"rendered":"<p>File handling operations like text selection, cut, copy, paste, find, and replace, etc., can be performed on files in Linux\/Ubuntu OS by using a text editor like Nano, Vim, etc. <\/p>","protected":false},"author":110,"featured_media":21862,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1049,2],"tags":[],"class_list":["post-21859","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux-commands","category-ubuntu"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/21859","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/110"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=21859"}],"version-history":[{"count":1,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/21859\/revisions"}],"predecessor-version":[{"id":21895,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/21859\/revisions\/21895"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/21862"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=21859"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=21859"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=21859"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}