قالب وردپرس درنا توس
Home / Tips and Tricks / How to Edit Text Files Graphically on Linux with gedit

How to Edit Text Files Graphically on Linux with gedit



  gedit text editor on the Ubuntu Linux desktop

Linux users typically edit configuration files with terminal-based tools such as nano and vim . If you want to graphically edit a file – even a system file – you can edit it easily and effortlessly with the text editor gedit .

Files, files everywhere

A frequently repeated sentence on Linux and other Unix operating systems -based operating systems like macOS are "Everything is a file".

Although this is not accurate, text files are often used for system logs and configurations. You can read these files to learn more about how your operating system works, and edit them to change their behavior.

The default GNOME text editor is gedit . So you should find it on Any system with a GNOME desktop environment. These include Ubuntu, Fedora, Debian, CentOS and Red Hat. It's a handy tool for editing files if you only need enough editor to get the job done ̵

1; without the learning curve of some of the leading editors like vim .

What does "Everything is a file" mean in Linux?

Starting gedit

To start gedit from the command line, type gedit and press Enter [19659011] Command gedit in a terminal window "width =" 642 "height =" 75 "/>

The text editor gedit will be displayed shortly.

 Text editor gedit with an empty document under Linux

It is concise and clean Application window You can enter anything you are working on without distraction.

Of course, you can also start gedit from the application menu of your Linux desktop, often referred to as a "text editor." Simply browse the application menu for "gedit."

 Starting gedit from the application menu on Ubuntu's GNOME desktop

Starting gedit as a background task

The terminal window is started Wait until gedit is closed before You return to the command prompt. If you want to use the terminal window while gedit is still open, start instead gedit with this command. This opens gedit as a background task. You will immediately get back the command prompt and can use the terminal window even if gedit is executed.

Enter gedit a space, an Et character . & then press Enter – as follows:

  gedit & 

  gedit & command in a terminal window

open an existing file

To open an existing text file, click the " Open "on the toolbar gedit . You can also press Ctrl + O to open a file.

This will open the Recent Files menu. If you want to reopen one of the listed files, click on the name of the file. If you want to open another file, click the "Other documents …" button at the bottom of the menu.

 Menu for opening files in gedit

This opens a standard dialog for opening files. This option allows you to navigate to the location of the file to be edited.

Click the green Open button after selecting the file to edit.

<img class = "alignnone size-full wp-image-413892" src = "https://www.howtogeek.com/wp-content/uploads/2019/05/xgedit_04.png.pagespeed.gp+jp + jw + pj + ws + js + rj + rp + rw + ri + cp + md.ic.nTfr-iAkiz.png "alt =" Open File dialog box [19659029] Open a file from the command line

can prompt gedit to open a file as soon as it is started by typing the file name on the command line, causing gedit to load the file so that it can be edited, as soon as gedit is displayed.

  gedit ana.c 

  gedit ana.c command in a terminal window

The syntax highlighting function of gedit does editing Program source code files and shell scripts are particularly useful.

Syntax highlighting colors the words in the source file so that variables are reserved. Words, comments, parameters, and more can be used be easily identified.

 gedit with open file ana.c

The name of the file you are editing appears in the toolbar. If you have changed the file, an asterisk * will be displayed next to the file name.

 Changed file in gedit

This way you will learn that changes have been made to the contents of the file. This reminds you that you need to save the file if you want to keep the changes.

Saving changes to a file

Click the Save button on the toolbar to save your changes. You can also press Ctrl + S to save the file.

To save your file under a different name or location, click the menu button on the toolbar and then choose "Save As" from the menu.

 Menu key with markers

This opens a standard dialog for saving files. You can navigate to the directory where you want to save the file, and you can specify a name for the file. Click the green Save button to save the file.

 Dialog box for saving gedit files

Editing system files

To edit a system file, you must normally use sudo because the owner of the file probably root is. To be precise, you can open a system file even if you do not use sudo but you can save changes to the file only if you used ] sudo .

  sudo gedit /etc/samba/smb.conf[19659048)sudogedit-BefehlineeinTerminalwindow"width="644"height="95"/>

Warning : Do not edit system files if you have Do not know exactly what your changes to your system will do. If you mess up the wrong system file, your computer will lock after a restart.

This command opens gedit and loads the Samba configuration file for editing

 gedit Edit the smb.conf File

Replicate the Property and Permissions to a New File

A prudent way to manipulate system files - and therefore a recommended way to manipulate system files - is to copy the file and then edit the copy If you have edited the new file, you can copy it over the original file again If you confused the copied file b wrestling, this can do no harm. Delete them and start over.

When you copy a file, the file ownership may change and the file mode permissions may be changed. You need to make sure that they are the same in your new file as they are in the original file before you copy the new version over the original file. So you can do that.

Let's say we want to edit the file fstab .

To make sure the file owner and mode permissions change, we create a new file and then copy the existing file over it. This step is for demonstration purposes only to ensure that the new file does not have the same mode permissions and ownership as the original file. You do not need to do this when editing your own files.

  Touch new_fstab 

  Touch new fstab in a terminal window

With ls you can check the file attributes and see what file-mode permissions it has and who the file owner is.

  ls -l new_fstab 

  ls -l new_fstab in a terminal window

The file owner is Dave and the file mode permissions are read-only for the file owner and read-only for the group and others.

Now we copy the file / etc / fstab about the newly created file. We then check the file attributes to see if they have changed.

  sudo cp / etc / fstab new_fstab 
  ls -l new_fstab 

  cp / etc / fstab new_fstab in a terminal window [19659005] The fstab was over the new_fstab File copied. The file attributes of new_fstab have not been changed. Let's review the file attributes of the original file fstab .

  ls -l / etc / fstab 

  ls -l / etc / fstab in a terminal window

As we can see, owner is root and the file-mode permissions are different. The group permissions are Read and Write. The group permissions for new_fstab are read-only. We need to fix these two attributes before we copy the file back.

First, we start gedit and edit the file new_fstab to make the necessary changes. [19659020] gedit new_fstab

  gedit new_fstab in a terminal window

After editing the file and saving our changes, we need to reset the file ownership and file mode permissions to the desired value. [19659005] We can do this with the option - reference of the commands chmod and chown .

The option - Reference Takes a filename as a parameter. It forces chmod and chown to inherit the file-mode permissions and file ownership values ​​from this file and copy them to the destination file. We can then use ls to check if the attributes of the edited file are set correctly before copying them back over the original file.

  sudo chmod - reference = / etc / fstab new_fstab 
  sudo chown - reference = / etc / fstab new_fstab 
  ls -l new_fstab 

  - Reference option in a terminal window

The File permissions and ownership are now correct. We can copy the new_fstab over the existing fstab and our changes were made.

 sudo cp new_fstab fstab in a terminal window

As These are changes to the fstab file that will take effect the next time you restart the computer, or immediately if the mount command is used as follows: [19659018] sudo mount -a

Be careful out there

My catchphrase is caution, and I'm not about repeating warnings. If you are not sure how the changes to a system file affect your computer, do not make the changes.

If you need to edit a text file, whether it's a system file or not, you'll find that gedit is a fast and simple editor that does not provide you with too many options overwhelmed and yet has enough features to do your job.




Source link