Linux users typically edit configuration files with terminal-based tools such as
vim . If you want to graphically edit a file – even a system file – you can edit it easily and effortlessly with the text editor
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 ̵
What does "Everything is a file" mean in Linux?
gedit from the command line, type
gedit and press Enter  Command gedit in a terminal window "width =" 642 "height =" 75 "/>
The text editor
gedit will be displayed shortly.
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 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.
gedit a space, an Et character
. & then press Enter – as follows:
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.
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  Open a file from the command line
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.
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.
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.
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.
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.
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
geditand loads the Samba configuration file for editing
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
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
lsyou can check the file attributes and see what file-mode permissions it has and who the file owner is.ls -l new_fstab
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 / fstababout the newly created file. We then check the file attributes to see if they have changed.sudo cp / etc / fstab new_fstabls -l new_fstab
fstabwas over the
new_fstabFile copied. The file attributes of
new_fstabhave not been changed. Let's review the file attributes of the original file
fstab.ls -l / etc / fstab
As we can see, owner is
rootand the file-mode permissions are different. The group permissions are Read and Write. The group permissions for
new_fstabare read-only. We need to fix these two attributes before we copy the file back.
First, we start
geditand edit the file
new_fstabto make the necessary changes.  gedit new_fstab
After editing the file and saving our changes, we need to reset the file ownership and file mode permissions to the desired value.  We can do this with the option
- referenceof the commands
- ReferenceTakes a filename as a parameter. It forces
chownto 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_fstabsudo chown - reference = / etc / fstab new_fstabls -l new_fstab
The File permissions and ownership are now correct. We can copy the
new_fstabover the existing
fstaband our changes were made.
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:  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
geditis a fast and simple editor that does not provide you with too many options overwhelmed and yet has enough features to do your job.