linux 编辑gedit_如何使用gedit在Linux上以图形方式编辑文本文件

标签: linux  java  python  ubuntu  vim

linux 编辑gedit

linux 编辑gedit

gedit text editor on Ubuntu Linux desktop

Linux users normally edit configuration files with terminal-based tools like nano and vim . If you want to edit a file graphically—even a system file—the gedit text editor makes it painless and easy.

Linux用户通常使用基于终端的工具(例如nanovim来编辑配置文件。 如果要以图形方式编辑文件(甚至是系统文件),则gedit文本编辑器将使其变得轻松而轻松。

文件,无处不在的文件 (Files, Files Everywhere)

An oft-repeated phrase concerning Linux and other Unix-based operating systems such as macOS is “everything is a file.”

关于Linux和其他基于Unix的操作系统(例如macOS),经常重复出现的一句话是“ 一切都是文件”

While that’s not strictly accurate, text files are often used for system logs and configuration. You can read these files to learn more about the inner workings of your operating system, and you can edit them to change its behavior.

虽然这不是严格准确的,但文本文件通常用于系统日志和配置。 您可以阅读这些文件以了解有关操作系统内部工作的更多信息,还可以对其进行编辑以更改其行为。

The default GNOME text editor is gedit, so you should find it on any system with a GNOME desktop environment. That includes Ubuntu, Fedora, Debian, CentOS, and Red Hat. It’s a handy tool for editing files when all you need is just enough editor to get the job done—without the learning curve of some of the power-house editors like vim.

缺省的GNOME文本编辑器是gedit ,因此您应该在具有GNOME桌面环境的任何系统上找到它。 其中包括Ubuntu,Fedora,Debian,CentOS和Red Hat。 当您只需要足够的编辑器即可完成工作时,它便是一种编辑文件的便捷工具,而无需像vim这样的强大编辑器的学习曲线。

启动gedit (Launching gedit)

To start gedit from the command line, type gedit and hit Enter.

要从命令行启动gedit ,请键入gedit然后按Enter。

gedit command in a terminal window

The gedit text editor will appear shortly.


gedit text editor with blank document on Linux

It’s an uncluttered and clean application window. You can get on with the task of typing up whatever you’re working on with no distractions.

这是一个整洁干净的应用程序窗口。 您可以轻松完成键入任何工作的任务。

Of course, you can also launch gedit from your Linux desktop’s application menu. It’s often named “Text Editor.” Just search the applications menu for “gedit.”

当然,您也可以从Linux桌面的应用程序菜单启动gedit。 它通常被称为“文本编辑器”。 只需在应用程序菜单中搜索“ gedit”即可。

Launching gedit from the applications menu on Ubuntu's GNOME desktop

启动gedit作为后台任务 (Launching gedit as a Background Task)

The terminal window will wait for gedit to close before it returns you to the command prompt. If you want to use the terminal window while gedit is still open, launch gedit with this command instead. This opens gedit as a background task. You get the command line prompt back straight away and you can carry on using the terminal window even when gedit is running.

终端窗口将等待gedit关闭,然后将其返回到命令提示符。 如果要在gedit仍处于打开状态时使用终端窗口,请改用此命令启动gedit 。 这gedit作为后台任务打开。 您将立即获得命令行提示符,即使在gedit运行时也可以继续使用终端窗口。

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

输入gedit ,一个空格,“& & ,然后按Enter键,如下所示:

gedit &
gedit & command in a terminal window

打开一个现有文件 (Opening 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.

要打开现有的文本文件,请点击gedit工具栏中的“打开”按钮。 您也可以按Ctrl + O打开文件。

This opens the recent files menu. If you want to re-open one of the listed files click on the name of the file. If you wish to open a different file, click the “Other documents…” button at the bottom of the menu.

这将打开“最近的文件”菜单。 如果要重新打开列出的文件之一,请单击文件名。 如果您要打开其他文件,请单击菜单底部的“其他文档…”按钮。

file open menu in gedit

This opens up 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 when you have highlighted the file you wish to edit.


gedit file open dialog

从命令行打开文件 (Opening a File from the Command Line)

You can ask gedit to open a file as soon as it launches by providing the filename on the command line. This makes gedit load the file so that it is ready to be edited as soon as gedit appears.

您可以要求gedit在文件启动后立即打开,方法是在命令行中提供文件名。 这使gedit加载文件,以便在出现gedit就可以对其进行编辑。

gedit ana.c
gedit ana.c command in a terminal window

The syntax highlighting feature of gedit makes it especially nice to edit program source code files and shell scripts.


Syntax highlighting colors the words within 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 is displayed in the toolbar. If you have modified the file, an asterisk * appears beside the file name.

您正在编辑的文件的名称显示在工具栏中。 如果您修改了文件,则文件名旁边会出现一个星号*

modified file in gedit

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

这使您知道已对文件的内容进行了更改。 它提醒您,如果要保留更改,则需要保存文件。

将更改保存到文件 (Saving Changes to a File)

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

要保存更改,请单击工具栏中的“保存”按钮。 您也可以按Ctrl + S保存文件。

To save your file with a different name or in a different location click the menu button on the toolbar and then select “Save As” from the menu.


menu button with highlights

This will open a standard file save dialog. You can browse to the directory you wish to save the file in, and you can provide a name for the file. Click the green “Save” button to save the file.

这将打开一个标准文件保存对话框。 您可以浏览到要保存文件的目录,并可以提供文件名。 单击绿色的“保存”按钮以保存文件。

gedit file save dialog

编辑系统文件 (Editing System Files)

To edit a system file, you will usually need to use sudo because the owner of the file is likely to be root. To be strictly accurate you’ll be able to open a system file even if you don’t use sudo, but you won’t be able to save any changes back to the file unless you have used sudo.

要编辑系统文件,通常需要使用sudo因为文件的所有者可能是root 。 严格来说,即使您不使用sudo ,也可以打开系统文件,但是除非使用sudo否则您将无法将任何更改保存回该文件。

sudo gedit /etc/samba/smb.conf
sudo gedit command in a terminal window

Warning: Don’t edit system files if you don’t know exactly what your changes are going to do to your system. Mess up the wrong system file, and you can find yourself locked out of your computer following a reboot.

警告 :如果您不完全知道对系统所做的更改,请不要编辑系统文件。 弄错了错误的系统文件,重新启动后您会发现自己被锁定在计算机之外。

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


gedit editing smb.conf

将所有权和权限复制到新文件 (Replicating Ownership and Permissions to a New FIle)

A cautious way to edit system files–and therefore a commendable way to edit system files—is to copy the file and then edit the copy. When you’ve finished editing the new file, you can copy it back over the original file. If you make a mess of editing the copied file, there’s no harm done. Delete it and start over.

编辑系统文件的谨慎方法(因此也是值得推荐的编辑系统文件的方法)是复制文件,然后编辑副本。 完成新文件的编辑后,可以将其复制回原始文件。 如果您一头雾水编辑复制的文件,则不会造成任何伤害。 删除并重新开始。

When you copy a file, the file ownership can change, and the file mode permissions can be altered. You need to make sure these are exactly the same on your new file as they are on the original file before you copy the new version over the original file. This is how you can do that.

复制文件时,文件所有权可以更改,文件模式权限也可以更改。 在将新版本复制到原始文件之前,需要确保这些文件在新文件上与在原始文件上完全相同。 这就是您可以做到的。

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


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

为了确保我们拥有文件所有权和模式权限的更改,我们将创建一个新文件,然后在其上复制现有文件。 此步骤仅用于演示目的,以确保新文件不具有与原始文件相同的模式权限和所有权。 在编辑自己的文件时,您不需要这样做。

touch new_fstab
touch new fstab in a terminal window

We can use ls to 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 and write for the file owner and read-only for the group and for others.


Now, we’ll copy the /etc/fstab file over the new file we just created. We’ll then check the file attributes to see if they have changed.

现在,我们将/etc/fstab文件复制到刚刚创建的新文件上。 然后,我们将检查文件属性以查看它们是否已更改。

sudo cp /etc/fstab new_fstab
ls -l new_fstab
cp /etc/fstab new_fstab in a terminal window

The fstab has been copied over the new_fstab file. The file attributes of new_fstab have not changed. Let’s check the file attributes of the original fstab file.

fstab已复制到new_fstab文件上。 new_fstab的文件属性未更改。 让我们检查原始fstab文件的文件属性。

ls -l /etc/fstab
ls -l /etc/fstab in a terminal window

As we can see the 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’ll need to correct these two attributes before we copy the file back.

如我们所见,所有者是root ,文件模式权限不同。 组权限是读写的。 new_fstab的组权限是只读的。 复制文件之前,我们需要更正这两个属性。

First, we’ll launch gedit and edit the new_fstab file to make the required changes.


gedit new_fstab
gedit new_fstab in a terminal window

Once we’ve edited the file and saved our changes we need to set the file ownership and file mode permissions back to what they should be.


We can do this using the --reference option of the chmod and chown commands.


The --reference option takes a filename as a parameter. It forces chmod and chown to take the file mode permissions and file ownership values from that file and to copy them to the target file. We can then use ls to check that the attributes of the edited file are correctly set before we copy that back over the original file.

--reference选项将文件名作为参数。 它强制chmodchown从该文件获取文件模式权限和文件所有权值,并将其复制到目标文件。 然后,我们可以使用ls来检查已编辑文件的属性是否正确设置,然后再将其复制回原始文件。

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 will have been made.

文件权限和所有权现在正确。 我们可以将new_fstab复制到现有的fstab ,我们的更改已完成。

sudo cp new_fstab fstab in a terminal window

As these are changes to the fstab file, they’d take effect when the computer was next rebooted, or immediately if the mount command was used as so:


sudo mount -a

小心点 (Be Careful Out There)

My watchword is caution, and I’m not above repeating warnings. If you’re at all unsure about how your changes to a system file are going to make your computer behave, don’t make the changes.

我的口号是谨慎,我没有重复警告的意思。 如果您完全不确定对系统文件所做的更改将如何使计算机正常运行,请不要进行更改。

When you do need to edit a text file, whether it is a system file or not, you’ll find gedit is a fast and simple editor that doesn’t bog you down with too many options and yet has enough capability to let you get the job done.



linux 编辑gedit

版权声明:本文为culul01313原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。



总结: 1将if语句与数组联合起来判断输入中各组中的最大最小值; 2注意:定义的数组数量是躲多少就要输入多少组数据,少输入就无法输出;...

Bridging signals

Bridging signals Time Limit: 1000MSMemory Limit: 10000K Total Submissions: 10926Accepted: 5982 Description 'Oh no, they've done it again', cries the chief designer at the Waferland chip factory. Once ...

一天一大 leet

一天一大 leet 题目(难度:困难): 示例 抛砖引玉 官方答案 高手在民间 菜鸡的自白 20200606 题目(难度:困难): 给定一个未排序的整数数组,找出最长连续序列的长度。 要求算法的时间复杂度为 O(n)。 示例 示例 抛砖引玉 要求算法的时间复杂度为 O(n),即限制了只能循环一次; 先对数组排序 循环数组记录后一个元素等于前一个元素+1或者等于前一个元素的数量 满足条件++,不然重...

Tensorflow实现的CNN文本分类 原博文, github 在这篇文章中,我们将实现一个类似于Kim Yoon的卷积神经网络语句分类的模型。 本文提出的模型在一系列文本分类任务(如情感分析)中实现了良好的分类性能,并已成为新的文本分类架构的标准基准。 本文假设你已经熟悉了应用于NLP的卷积神经网络的基础知识。 如果没有,建议...


开发工具:idea 数据库:mysql jar包:junit-4.10 mysql-connector-java-8.0.18 junit-4.10下载 mysql-connector-java-8.0.18下载 注意1:jdbc的驱动因为使用的是mysql-connector-java-8.0.18,所以为(“com.mysql.cj.jdbc.Driver”),而不是(...


Lua 排序 table.sort

    正如C#中有Array.Sort(),lua中也有自己的排序方法即table.sort(table,function)。     lua中的排序默认是从大到小的排序;     传入一个方法参数,可以使排序从小到大; 打印结果:  ...


目录 一、SURF算法 1.算法简介 2.SURF与SIFT的具体差异 二、Python代码实践 1.测试环境 2.测试代码 3.核心函数 4.测试结果 一、SURF算法 1.算法简介 SURF(Speeded-Up Robust Features)加速稳健特征,是一种稳健的局部特征点检测和描述算法。 SURF是对SIFT算法的改进,该算子在保持 SIFT 算子优良性能特点的基础上,同时解决了 S...


1. 实现目标 在测试与开发中,经常需要对文件进行各种读取操作。这里介绍针对txt、csv、xml、json文件的读取。 2. 读取TXT文件 2.1 user_info.txt文件 2.2 读取txt文件.py 2.3 实现结果 3. 读取csv文件 3.1 user_info.csv  这里要注意,csv文件本身打开是utf-8的,而不是乱码 3.2 读取csv文件.py 这里,针对...

Flask 介绍

Flask 学习笔记 一、Flask 简介         Flask 是一款非常流行的 Python Web 框架,出生于 2010 年,作者是 Armin Ronacher,本来这个项目只是作者在愚人节的一个玩笑,后来由于非常受欢迎,进而成为一个正式的项目。         Flask 自2010年发布第一个版本以...


Java实现排序算法 其中不理解时间复杂度得可以看一下我的时间复杂度的文章,有助于理解 十大排序算法 1、冒泡排序 2、选择排序 3、插入排序 4、希尔排序 5、归并排序 6、快速排序 7、堆排序 8、计数排序 9、桶排序 10、基数排序 代码git地址: 排序算法说明 1,排序的定义 对一序列对象或者数...