قالب وردپرس درنا توس
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 Ubuntu Linux desktop

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

Files, files everywhere

An often repeated phrase on Linux and other Unix based operating systems like macOS is "everything is a file".

Although not strictly accurate, text files are often used for system logs and configurations. You can read these files to learn more about the operating system's internal functions, and you can 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. It includes Ubuntu, Fedora, Debian, CentOS and Red Hat. It's a handy file editing tool when all you need is just enough editor to get the job done ̵

1; without the learning curve for any of the driver editors like vim .

gedit from the command line, type gedit and press Enter. What does "Everything is a file"? 19659011] gedit command in a terminal window "width =" 642 "height =" 75 "/>

The text editor gedit will appear shortly.

 gedit text editor with blank document on Linux

It's a clean and clean application window, you can continue typing whatever you're working on without distractions.

Of course, you can also start gedit from your Linux desktop application menu. It's often called "Text Editor ". Just search the program menu for" gedit. "

 Launch gedit from the application menu on the Ubuntu GNOME desktop

Launch gedit as the background task

The terminal window will wait for gedit for If you want to use the terminal window while gedit is still open, start gedit with this command instead. This opens gedit as a background task. You get the command line back quickly and you can continue to use the terminal window even when gedit is running.

Type gedit a space, an ampersand & then press Enter-like:

  gedit & 

  gedit & command in a terminal window

Open an existing file

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

This opens the menu for latest files. To open one of the listed files, click the name of the file. If you want to open another file, click the "Other documents …" button at the bottom of the menu.

 file menu in gedit

It opens a standard file open dialog. You can use this to browse to the location of the file you want to edit.

Click the green "Open" button after selecting the file you want to edit.

 open dialog with open file

] Open a file from the command line

You can ask gedit to open a file as soon as it is started by specifying the file name of the command line. This causes gedit to load the file so that it is ready to be edited as soon as gedit is displayed.

gedit ana.c command in a terminal window

The syntax illumination function of gedit makes it particularly nice to edit program source code files and shell scripts.

Syntax highlighting marks the colors in the source file so that variables reserved words, comments, parameters and more are easily identifiable.

 gedit with ana.c file open for editing

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

 modified file in gedit

This lets you know that changes have been made to the content of the file. It seems like a reminder that if you want to keep the changes you need to save the file.

Save changes to a file

To save your changes, click the "Save" button on the toolbar. You can also press Ctrl + S to save the file.

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

 menu button with highlights

This opens a standard file saving dialog. You can browse to the directory in which you want to save the file, and you can enter a name for the file. Click on the green "Save" button to save the file.

 hidden file saving dialog

Editing system files

To edit a system file you usually need sudo because the owner of the file will probably be root . To be strictly correct you can open a system file even if you do not use sudo but you will not be able to save any changes back to the file unless you have used sudo .

  sudo gedit /etc/samba/smb.conf

udo gedit command in a terminal window

Warning : Do not change system files if you do not know exactly what your changes will do for your system. Remove the wrong system file and you can find yourself locked out of the computer after a restart.

The command opens gedit and loads the samba config file for editing.

 gedit editing of smb.conf

Replication of ownership and permissions for a new file

A careful way to edit system files and thus an affordable way to edit system files is to copy the file and then edit the copy. Once you have edited the new file, you can copy it back over the original file. If you make a mess to edit the copied file, there is no damage done. Remove it and restart.

When copying a file, the file content can be changed and the file state can be changed. You must ensure that these are exactly the same on your new file as they are on the original file before copying the new version over the original file. Here's how to do it.

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

In order to ensure that we change the file ownership and state license, 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 permission and ownership as the original file. You do not need to do this when editing your own files.

  pointing to new_stab 

  pointing to new fstab in a terminal window

We can use ls to check file properties and see which file location 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 permissions file is read and written for the file owner and read-only for the group and for others.

Now we copy the file / etc / fstab over the new file we just created. 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] fstab has been copied over the file new_fstab . The file attributes of new_fstab have not changed. Let's check the file attributes in the original file fstab .

  ls -l / etc / fstab 

  ls -l / etc / fstab in a terminal window

As we can see the owner is root and the file state is different. Group permissions are read and written. Group permissions for new_fstab are read-only. We must correct these two attributes before copying the file back.

First we start gedit and edit the file new_fstab to make the required changes. 19659020] gedit new_fstab

  gedit new_fstab in a terminal window

Once we have edited the file and saved our changes, we must set the permissions for file owners and file locations back to what they should be. [19659005] We can do this with the option - reference by the commands chmod and chown .

The reference option takes a file name as a parameter. It forces chmod and chown to take file state permissions and file owner values ​​from that file and copy them to the target file. We can then use ls to check that the attributes of the edited file are correctly set before copying it 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

File permissions and ownership is now correct. We can copy new_fstab over the existing fstab and our changes will have been made.

 sudo cp new_fstab fstab in a terminal window

As These are changes in the fstab file, they would take effect when the computer was restarted next time, or if the command command was used as such: [19659018] sudo mount -a

Be careful out there

My watchword was careful, and I'm not over repeated warnings. If you are not at all uncertain about how your changes to a system file will make your computer work, the changes do not.

When you need to edit a text file, whether it is a system file or not, you find gedit is a quick and easy editor who does not tow you with too many options and yet has enough ability to sound You get the job done.




Source link