Merge remote-tracking branch 'LCTT/master'

This commit is contained in:
Xingyu.Wang
2019-02-17 15:26:56 +08:00
4 changed files with 359 additions and 362 deletions

View File

@@ -1,8 +1,8 @@
[#]: collector: (lujun9972)
[#]: translator: (wxy)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: reviewer: (wxy)
[#]: publisher: (wxy)
[#]: url: (https://linux.cn/article-10544-1.html)
[#]: subject: (4 Unique Terminal Emulators for Linux)
[#]: via: (https://www.linux.com/blog/learn/2018/12/4-unique-terminals-linux)
[#]: author: (Jack Wallen https://www.linux.com/users/jlwallen)
@@ -14,13 +14,13 @@
![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/terminals_main.jpg?itok=e6av-5VO)
让我们面对现实,如果你是 Linux 管理员那么你要用命令行来工作。为此你将使用终端模拟器LCTT 译注:常简称为“终端”,与终端本身的原意不同)。最有可能的是,你选择发行版预先安装了一个可以完成工作的默认终端模拟器。但这是有很多选择可供选择的 Linux所以这种思想自然也适用于终端模拟器。实际上如果你打开发行版的图形界面的包管理器或从命令行搜索你将找到大量可能的选择。其中许多是非常简单的工具然而有些是真正独特的。
让我们面对现实,如果你是 Linux 管理员那么你要用命令行来工作。为此你将使用终端模拟器LCTT 译注:常简称为“终端”,与终端本身的原意不同)。最有可能的是,你选择发行版预先安装了一个可以完成工作的默认终端模拟器。但这是有很多选择可供选择的 Linux所以这种思想自然也适用于终端模拟器。实际上如果你打开发行版的图形界面的包管理器或从命令行搜索你将找到大量可能的选择。其中许多是非常简单的工具然而有些是真正独特的。
在本文中,我将重点介绍四个这样的终端模拟器,它们不仅可以完成工作,而且可以使工作变得更有趣或更有趣。 那么,让我们来看看这些终端。
在本文中,我将重点介绍四个这样的终端模拟器,它们不仅可以完成工作,而且可以使工作变得更有趣或更好玩。那么,让我们来看看这些终端。
### Tilda
[Tilda][1] 是为Gtk设计的是一种酷炫的下拉终端。这意味着该终端始终在后台运行,随时准备从显示器顶部拉下来(例如 Guake 和 Yakuake。让 Tilda 超越许多其他产品的原因是该终端可用的配置选项数量(图 1
[Tilda][1] 是为 Gtk 设计的,是一种酷炫的下拉终端。这意味着该终端始终运行在后台,可以随时从显示器顶部拉下来(就像 Guake 和 Yakuake。让 Tilda 超越许多其他产品的原因是该终端可用的配置选项数量(图 1
![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/terminals_1.jpg?itok=bra6qb6X)
@@ -30,7 +30,7 @@
sudo apt-get install tilda -y
```
安装完成后,从桌面菜单中打开 Tilda这也将打开其配置窗口。根据你的喜好配置应用程序然后关闭配置窗口。然后你可以通过点击 `F1` 热键来打开和关闭 Tilda。对使用 Tilda 的一个警告是,在第一次运行后,你将找不到有关如何找到配置向导的任何提示。别担心。只要运行命令 `tilda -C`,它将打开配置窗口,同时仍保留你之前设置的选项。
安装完成后,从桌面菜单中打开 Tilda这也将打开其配置窗口。根据你的喜好配置应用程序然后关闭配置窗口。然后你可以通过点击 `F1` 热键来打开和关闭 Tilda。对使用 Tilda 的一个警告是,在第一次运行后,你将找不到有关如何打开配置向导的任何提示。别担心。只要运行命令 `tilda -C`,它将打开配置窗口,同时仍保留你之前设置的选项。
可用选项包括:
@@ -43,13 +43,13 @@ sudo apt-get install tilda -y
* 透明度
* 动画
* 滚动
* 和更多
* 等等
我喜欢这些类型的终端是因为当你不需要它们时它们很容易就会消失,只需按一下按钮即可。对于那些不断进出终端的人来说,像 Tilda 这样的工具是理想的选择。
我喜欢这些类型的终端是因为当你不需要时它们很容易就会消失,只需按一下按钮即可。对于那些不断进出终端的人来说,像 Tilda 这样的工具是理想的选择。
### Aterm
Aterm 在我心中占有特殊的位置,因为它是我第一次使用的终端之一,它让我意识到 Linux 的灵活性。 这要回到 AfterStep 成为我选择的窗口管理器时(用了太久而且那时我是命令行新手。Aterm 提供的是一个高度可定制的终端仿真器,同时帮助我了解使用终端的细节(如何添加选项和切换到命令)。“你觉得怎么样?”。因为 Aterm 从未有过用于定制的图形界面。要使用任何特殊选项运行 Aterm必须以命令选项的方式运行。例如,假设你要启用透明度、绿色文本、白色高亮和无滚动条。为此,请运行以下命令:
Aterm 在我心中占有特殊的位置,因为它是我第一次使用的终端之一,它让我意识到 Linux 的灵活性。 这要回到 AfterStep 成为我选择的窗口管理器时(用了太久而且那时我是命令行新手。Aterm 提供的是一个高度可定制的终端仿真器,同时帮助我了解使用终端的细节(如何给命令添加选项和开关)。或许你会问:“你觉得怎么样?”。因为 Aterm 从未有过用于定制选项的图形界面。要使用任何特殊选项运行 Aterm必须以命令选项的方式运行。例如假设你要启用透明度、绿色文本、白色高亮和无滚动条。为此请运行以下命令
```
aterm -tr -fg green -bg white +xb
@@ -67,16 +67,17 @@ aterm -tr -fg green -bg white +xb
sudo apt-get install aterm -y
```
如果你想总是用这些选项打开 Aterm最好的办法是在 `~/.bashrc` 文件中创建一个别名,如下所示:
如果你想总是用这些选项打开 Aterm最好的办法是在 `~/.bashrc` 文件中创建一个别名,如下所示:
```
alias=”aterm -tr -fg green -bg white +sb”
```
保存该文件,当你运行命令 `aterm` 时,它将始终打开这些选项。有关创建别名的更多信息,请查看[这个教程][5]。
### Eterm
Eterm 是第二个真正告诉我 Linux 命令行可以带来多少乐趣的终端。Eterm 是 Enlightenment 桌面的默认终端模拟器。当我最终从 AfterStep 迁移到 Enlightenment 时(那时早在 20 世纪初),我担心我会失去所有那些很酷的美学选择。结果并非如此。 实际上Eterm 提供了许多独特的选项,同时使用终端工具栏使任务更容易。使用 Eterm你可以通过从 “Background > Pixmap”菜单条目中轻松地从大量背景图像中选择一个背景如果你需要一个的话图 3
Eterm 是第二个真正告诉我 Linux 命令行可以带来多少乐趣的终端。Eterm 是 Enlightenment 桌面的默认终端模拟器。当我最终从 AfterStep 迁移到 Enlightenment 时(那时早在 20 世纪初我担心我会失去所有那些很酷的美学选择。结果并非如此。实际上Eterm 提供了许多独特的选项,同时使用终端工具栏使任务变得更容易。使用 Eterm你可以通过从 “Background > Pixmap” 菜单条目中轻松地从大量背景图像中选择一个背景(如果你需要一个的话,图 3
![Eterm][7]
@@ -92,7 +93,7 @@ sudo apt-get install eterm
### Extraterm
[Extraterm][8] 应该可以赢得今天任何终端窗口项目最酷功能集的一些奖项。Extraterm 最独特的功能是能够以彩色框来包装命令(蓝色表示成功命令,红色表示失败命令。图 4
[Extraterm][8] 应该可以赢得今终端窗口项目最酷功能集的一些奖项。Extraterm 最独特的功能是能够以彩色框来包装命令(蓝色表示成功命令,红色表示失败命令。图 4
![Extraterm][10]
@@ -100,27 +101,27 @@ sudo apt-get install eterm
在运行命令时Extraterm 会将命令包装在一个单独的颜色框中。如果该命令成功,则该颜色框将以蓝色轮廓显示。如果命令失败,框将以红色标出。
无法通过标准软件库安装 Extraterm。事实上在 Linux 上运行 Extraterm目前的唯一方法是从项目的 GitHub 页面[下载预编译的二进制文件][11],解压缩文件,切换到新创建的目录,然后运行命令 `./extraterm`
无法通过标准软件库安装 Extraterm。事实上在 Linux 上运行 Extraterm目前的唯一方法是从项目的 GitHub 页面[下载预编译的二进制文件][11],解压缩文件,切换到新创建的目录,然后运行命令 `./extraterm`
当该应用程序运行后,要启用颜色框,你必须首先启用 bash 集成。为此,请打开 Extraterm然后右键单击窗口中的任意位置以显示弹出菜单。滚动直到看到 “Inject Bash shell Integration”的条目图 5。选择该条目然后你可以开始使用这个颜色框选项。
当该应用程序运行后,要启用颜色框,你必须首先启用 Bash 集成功能。为此,请打开 Extraterm然后右键单击窗口中的任意位置以显示弹出菜单。滚动直到看到 “Inject Bash shell Integration” 的条目(图 5。选择该条目然后你可以开始使用这个颜色框选项。
![Extraterm][13]
*图 5为 Extraterm 插入 Bash 集成。。*
如果你运行了一个命令,并且看不到颜色框,则可能必须为该命令创建一个新的颜色框(因为 Extraterm 仅附带一些默认颜色框)。为此,请单击 “Extraterm” 菜单按钮窗口右上角的三条水平线选择“Settings”然后单击“Frames”选项卡。在此窗口中向下滚动并单击“New Rule”按钮。 然后,你可以添加要使用颜色框的命令(图 6
如果你运行了一个命令,并且看不到颜色框,则可能必须为该命令创建一个新的颜色框(因为 Extraterm 仅附带一些默认颜色框)。为此,请单击 “Extraterm” 菜单按钮(窗口右上角的三条水平线),选择 “Settings”然后单击 “Frames” 选项卡。在此窗口中,向下滚动并单击 “New Rule” 按钮。 然后,你可以添加要使用颜色框的命令(图 6
![frames][15]
*图 6为颜色框添加新规则。*
如果在此之后仍然没有看到框出现,请从[下载页面][11]下载 `extraterm-commands` 文件,解压缩该文件,切换到新创建的目录,然后运行命令 `sh setup_extraterm_bash.sh`。这应该可以为 Extraterm 启用颜色框。
如果在此之后仍然没有看到颜色框出现,请从[下载页面][11]下载 `extraterm-commands` 文件,解压缩该文件,切换到新创建的目录,然后运行命令 `sh setup_extraterm_bash.sh`。这应该可以为 Extraterm 启用颜色框。
还有更多可用于 Extraterm 的选项。我相信,一旦你开始在终端窗口上玩这个新花,你就不会想回到标准终端。希望开发人员尽快将这个应用程序提供给标准软件库(因为它很容易就可以成为最常用的终端窗口之一)。
还有更多可用于 Extraterm 的选项。我相信,一旦你开始在终端窗口上玩这个新花,你就不会想回到标准终端。希望开发人员可以尽快将这个应用程序提供给标准软件库(因为它很容易就可以成为最流行的终端窗口之一)。
### 更多
正如你可能预期的那样Linux 有很多可用的终端。这四个代表(至少对我来说)四个独特的终端,每个都可以帮助你运行每个 Linux 管理员需要运行的命令。如果你对其中一个不满意,请让你的包管理员查看可用的软件包。你一定会找到适合你的东西。
正如你可能预期的那样Linux 有很多可用的终端。这四个代表四个独特的终端(至少对我来说),每个都可以帮助你运行 Linux 管理员需要运行的命令。如果你对其中一个不满意,你的包管理器找找有什么可用的软件包。你一定会找到适合你的东西。
--------------------------------------------------------------------------------
@@ -129,7 +130,7 @@ via: https://www.linux.com/blog/learn/2018/12/4-unique-terminals-linux
作者:[Jack Wallen][a]
选题:[lujun9972][b]
译者:[wxy](https://github.com/wxy)
校对:[校对者ID](https://github.com/校对者ID)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@@ -1,34 +1,32 @@
[#]: collector: (lujun9972)
[#]: translator: (jdh8383)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: reviewer: (wxy)
[#]: publisher: (wxy)
[#]: url: (https://linux.cn/article-10543-1.html)
[#]: subject: (Toyota Motors and its Linux Journey)
[#]: via: (https://itsfoss.com/toyota-motors-linux-journey)
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
[#]: author: (Malcolm Dean https://itsfoss.com/toyota-motors-linux-journey)
丰田汽车的Linux之旅
丰田汽车的 Linux 之旅
======
**这篇文章来自 It's FOSS 的读者 Malcolm Dean的投递。**
我之前跟丰田汽车北美分公司的 Brian.R.Lyons丰田发言人聊了聊话题是关于 Linux 在丰田和雷克萨斯汽车的信息娱乐系统上的实施方案。我了解到一些汽车制造商使用了 Automotive Grade LinuxAGL
我之前跟丰田汽车北美分公司的 Brian.R.Lyons丰田发言人聊了聊话题是关于Linux在丰田和雷克萨斯汽车的信息娱乐系统上的实施方案。我了解到一些汽车制造商使用了 Automotive Grade Linux (AGL)
然后我写了一篇短文,记录了我和 Brian 的讨论内容,谈及了丰田和 Linux 的一些渊源。希望 Linux 的狂热粉丝们能够喜欢这次对话
然后我写了一篇短文,记录了我和 Brian 的讨论内容,就是丰田和 Linux 的一些渊源。希望 Linux 的狂热粉丝们能够喜欢这次对话。
全部[丰田和雷克萨斯汽车都将会使用 Automotive Grade Linux][1] (AGL),主要是用于车载信息娱乐系统。这项措施对于丰田集团来说是至关重要的,因为据 Lyons 先生所说:“作为技术的引领者之一,丰田认识到,赶上科技快速进步最好的方法就是拥抱开源理念”。
全部的[丰田和雷克萨斯汽车都将会使用 Automotive Grade LinuxAGL][1],主要是用于车载信息娱乐系统。这项措施对于丰田集团来说是至关重要的,因为据 Lyons 先生所说:“作为技术的引领者之一,丰田认识到,赶上科技快速进步最好的方法就是接受开源发展的理念。”
丰田和众多汽车制造公司都认为,与使用非自由软件相比,采用基于 Linux 的操作系统在更新和升级方面会更加廉价和快捷。
这简直太棒了! Linux 终于跟汽车结合起来了。我每天都在电脑上使用 Linux能看到这个优秀的软件在一个完全不同的产业领域里大展拳脚真是太好了。
这简直太棒了Linux 终于跟汽车结合起来了。我每天都在电脑上使用 Linux能看到这个优秀的软件在一个完全不同的产业领域里大展拳脚真是太好了。
我很好奇丰田是什么时候开始使用 [Automotive Grade Linux][2] (AGL) 的。按照 Lyons 先生的说法,这要追溯到 2011 年。
我很好奇丰田是什么时候开始使用 [Automotive Grade LinuxAGL][2]的。按照 Lyons 先生的说法,这要追溯到 2011 年。
>“自 AGL 项目在五年前启动之始,作为活跃的会员和贡献者,丰田与其他顶级制造商和供应商展开合作,着手开发一个基于 Linux 的强大平台,并不断地增强其功能和安全性。”
> “自 AGL 项目在五年前启动之始,作为活跃的会员和贡献者,丰田与其他顶级制造商和供应商展开合作,着手开发一个基于 Linux 的强大平台,并不断地增强其功能和安全性。”
![丰田信息娱乐系统][3]
[丰田于2011年加入了 Linux 基金会][4],与其他汽车制造商和软件公司就 IVI车内信息娱乐系统展开讨论最终在 2012 年Linux 基金会内部成立了 Automotive Grade Linux 工作组。
[丰田于 2011 年加入了 Linux 基金会][4],与其他汽车制造商和软件公司就 IVI车内信息娱乐系统展开讨论最终在 2012 年Linux 基金会内部成立了 Automotive Grade Linux 工作组。
丰田在 AGL 工作组里首先提出了“代码优先”的策略这在开源领域是很常见的做法。然后丰田和其他汽车制造商、IVI 一线厂家,软件公司等各方展开对话,根据各方的技术需求详细制定了初始方向。
@@ -48,14 +46,14 @@
via: https://itsfoss.com/toyota-motors-linux-journey
作者:[Abhishek Prakash][a]
作者:[Malcolm Dean][a]
选题:[lujun9972][b]
译者:[jdh8383](https://github.com/jdh8383)
校对:[校对者ID](https://github.com/校对者ID)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/abhishek/
[a]: https://itsfoss.com/toyota-motors-linux-journey
[b]: https://github.com/lujun9972
[1]: https://www.linuxfoundation.org/press-release/2018/01/automotive-grade-linux-hits-road-globally-toyota-amazon-alexa-joins-agl-support-voice-recognition/
[2]: https://www.automotivelinux.org/

View File

@@ -1,325 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (dianbanjiu )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (10 Methods To Create A File In Linux)
[#]: via: (https://www.2daygeek.com/linux-command-to-create-a-file/)
[#]: author: (Vinoth Kumar https://www.2daygeek.com/author/vinoth/)
10 Methods To Create A File In Linux
======
As we already know that everything is a file in Linux, that includes device as well.
Linux admin should be performing the file creation activity multiple times (It may 20 times or 50 times or more than that, its depends upon their environment) in a day.
Navigate to the following URL, if you would like to **[create a file in a specific size in Linux][1]**.
Its very important. how efficiently are we creating a file. Why im saying efficient? there is a lot of benefit if you know the efficient way to perform an activity.
It will save you a lot of time. You can spend those valuable time on other important or major tasks, where you want to spend some more time instead of doing that in hurry.
Here im including multiple ways to create a file in Linux. I advise you to choose few which is easy and efficient for you to perform your activity.
You no need to install any of the following commands because all these commands has been installed as part of Linux core utilities except nano command.
It can be done using the following 6 methods.
* **`Redirect Symbol (>):`** Standard redirect symbol allow us to create a 0KB empty file in Linux.
* **`touch:`** touch command can create a 0KB empty file if does not exist.
* **`echo:`** echo command is used to display line of text that are passed as an argument.
* **`printf:`** printf command is used to display the given text on the terminal window.
* **`cat:`** It concatenate files and print on the standard output.
* **`vi/vim:`** Vim is a text editor that is upwards compatible to Vi. It can be used to edit all kinds of plain text.
* **`nano:`** nano is a small and friendly editor. It copies the look and feel of Pico, but is free software.
* **`head:`** head is used to print the first part of files..
* **`tail:`** tail is used to print the last part of files..
* **`truncate:`** truncate is used to shrink or extend the size of a file to the specified size.
### How To Create A File In Linux Using Redirect Symbol (>)?
Standard redirect symbol allow us to create a 0KB empty file in Linux. Basically it used to redirect the output of a command to a new file. When you use redirect symbol without a command then its create a file.
But it wont allow you to input any text while creating a file. However, its very simple and will be useful for lazy admins. To do so, simple enter the redirect symbol followed by the filename which you want.
```
$ > daygeek.txt
```
Use the ls command to check the created file.
```
$ ls -lh daygeek.txt
-rw-rw-r-- 1 daygeek daygeek 0 Feb 4 02:00 daygeek.txt
```
### How To Create A File In Linux Using touch Command?
touch command is used to update the access and modification times of each FILE to the current time.
Its create a new file if does not exist. Also, touch command doesnt allow us to enter any text while creating a file. By default it creates a 0KB empty file.
```
$ touch daygeek1.txt
```
Use the ls command to check the created file.
```
$ ls -lh daygeek1.txt
-rw-rw-r-- 1 daygeek daygeek 0 Feb 4 02:02 daygeek1.txt
```
### How To Create A File In Linux Using echo Command?
echo is a built-in command found in most operating systems. It is frequently used in scripts, batch files, and as part of individual commands to insert a text.
This is nice command that allow users to input a text while creating a file. Also, it allow us to append the text in the next time.
```
$ echo "2daygeek.com is a best Linux blog to learn Linux" > daygeek2.txt
```
Use the ls command to check the created file.
```
$ ls -lh daygeek2.txt
-rw-rw-r-- 1 daygeek daygeek 49 Feb 4 02:04 daygeek2.txt
```
To view the content from the file, use the cat command.
```
$ cat daygeek2.txt
2daygeek.com is a best Linux blog to learn Linux
```
If you would like to append the content in the same file, use the double redirect Symbol (>>).
```
$ echo "It's FIVE years old blog" >> daygeek2.txt
```
You can view the appended content from the file using cat command.
```
$ cat daygeek2.txt
2daygeek.com is a best Linux blog to learn Linux
It's FIVE years old blog
```
### How To Create A File In Linux Using printf Command?
printf command also works in the same way like how echo command works.
printf command in Linux is used to display the given string on the terminal window. printf can have format specifiers, escape sequences or ordinary characters.
```
$ printf "2daygeek.com is a best Linux blog to learn Linux\n" > daygeek3.txt
```
Use the ls command to check the created file.
```
$ ls -lh daygeek3.txt
-rw-rw-r-- 1 daygeek daygeek 48 Feb 4 02:12 daygeek3.txt
```
To view the content from the file, use the cat command.
```
$ cat daygeek3.txt
2daygeek.com is a best Linux blog to learn Linux
```
If you would like to append the content in the same file, use the double redirect Symbol (>>).
```
$ printf "It's FIVE years old blog\n" >> daygeek3.txt
```
You can view the appended content from the file using cat command.
```
$ cat daygeek3.txt
2daygeek.com is a best Linux blog to learn Linux
It's FIVE years old blog
```
### How To Create A File In Linux Using cat Command?
cat stands for concatenate. It is very frequently used in Linux to reads data from a file.
cat is one of the most frequently used commands on Unix-like operating systems. Its offer three functions which is related to text file such as display content of a file, combine multiple files into the single output and create a new file.
```
$ cat > daygeek4.txt
2daygeek.com is a best Linux blog to learn Linux
It's FIVE years old blog
```
Use the ls command to check the created file.
```
$ ls -lh daygeek4.txt
-rw-rw-r-- 1 daygeek daygeek 74 Feb 4 02:18 daygeek4.txt
```
To view the content from the file, use the cat command.
```
$ cat daygeek4.txt
2daygeek.com is a best Linux blog to learn Linux
It's FIVE years old blog
```
If you would like to append the content in the same file, use the double redirect Symbol (>>).
```
$ cat >> daygeek4.txt
This website is maintained by Magesh M, It's licensed under CC BY-NC 4.0.
```
You can view the appended content from the file using cat command.
```
$ cat daygeek4.txt
2daygeek.com is a best Linux blog to learn Linux
It's FIVE years old blog
This website is maintained by Magesh M, It's licensed under CC BY-NC 4.0.
```
### How To Create A File In Linux Using vi/vim Command?
Vim is a text editor that is upwards compatible to Vi. It can be used to edit all kinds of plain text. It is especially useful for editing programs.
There are a lot of features are available in vim to edit a single file with the command.
```
$ vi daygeek5.txt
2daygeek.com is a best Linux blog to learn Linux
It's FIVE years old blog
```
Use the ls command to check the created file.
```
$ ls -lh daygeek5.txt
-rw-rw-r-- 1 daygeek daygeek 75 Feb 4 02:23 daygeek5.txt
```
To view the content from the file, use the cat command.
```
$ cat daygeek5.txt
2daygeek.com is a best Linux blog to learn Linux
It's FIVE years old blog
```
### How To Create A File In Linux Using nano Command?
Nanos is a another editor, an enhanced free Pico clone. nano is a small and friendly editor. It copies the look and feel of Pico, but is free software, and implements several features that Pico lacks, such as: opening multiple files, scrolling per line, undo/redo, syntax coloring, line numbering, and soft-wrapping overlong lines.
```
$ nano daygeek6.txt
2daygeek.com is a best Linux blog to learn Linux
It's FIVE years old blog
This website is maintained by Magesh M, It's licensed under CC BY-NC 4.0.
```
Use the ls command to check the created file.
```
$ ls -lh daygeek6.txt
-rw-rw-r-- 1 daygeek daygeek 148 Feb 4 02:26 daygeek6.txt
```
To view the content from the file, use the cat command.
```
$ cat daygeek6.txt
2daygeek.com is a best Linux blog to learn Linux
It's FIVE years old blog
This website is maintained by Magesh M, It's licensed under CC BY-NC 4.0.
```
### How To Create A File In Linux Using head Command?
head command is used to output the first part of files. By default it prints the first 10 lines of each FILE to standard output. With more than one FILE, precede each with a header giving the file name.
```
$ head -c 0K /dev/zero > daygeek7.txt
```
Use the ls command to check the created file.
```
$ ls -lh daygeek7.txt
-rw-rw-r-- 1 daygeek daygeek 0 Feb 4 02:30 daygeek7.txt
```
### How To Create A File In Linux Using tail Command?
tail command is used to output the last part of files. By default it prints the first 10 lines of each FILE to standard output. With more than one FILE, precede each with a header giving the file name.
```
$ tail -c 0K /dev/zero > daygeek8.txt
```
Use the ls command to check the created file.
```
$ ls -lh daygeek8.txt
-rw-rw-r-- 1 daygeek daygeek 0 Feb 4 02:31 daygeek8.txt
```
### How To Create A File In Linux Using truncate Command?
truncate command is used to shrink or extend the size of a file to the specified size.
```
$ truncate -s 0K daygeek9.txt
```
Use the ls command to check the created file.
```
$ ls -lh daygeek9.txt
-rw-rw-r-- 1 daygeek daygeek 0 Feb 4 02:37 daygeek9.txt
```
I have performed totally 10 commands in this article to test this. All together in the single output.
```
$ ls -lh daygeek*
-rw-rw-r-- 1 daygeek daygeek 0 Feb 4 02:02 daygeek1.txt
-rw-rw-r-- 1 daygeek daygeek 74 Feb 4 02:07 daygeek2.txt
-rw-rw-r-- 1 daygeek daygeek 74 Feb 4 02:15 daygeek3.txt
-rw-rw-r-- 1 daygeek daygeek 148 Feb 4 02:20 daygeek4.txt
-rw-rw-r-- 1 daygeek daygeek 75 Feb 4 02:23 daygeek5.txt
-rw-rw-r-- 1 daygeek daygeek 148 Feb 4 02:26 daygeek6.txt
-rw-rw-r-- 1 daygeek daygeek 148 Feb 4 02:32 daygeek7.txt
-rw-rw-r-- 1 daygeek daygeek 148 Feb 4 02:32 daygeek8.txt
-rw-rw-r-- 1 daygeek daygeek 148 Feb 4 02:38 daygeek9.txt
-rw-rw-r-- 1 daygeek daygeek 0 Feb 4 02:00 daygeek.txt
```
--------------------------------------------------------------------------------
via: https://www.2daygeek.com/linux-command-to-create-a-file/
作者:[Vinoth Kumar][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.2daygeek.com/author/vinoth/
[b]: https://github.com/lujun9972
[1]: https://www.2daygeek.com/create-a-file-in-specific-certain-size-linux/

View File

@@ -0,0 +1,323 @@
[#]: collector: (lujun9972)
[#]: translator: (dianbanjiu )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (10 Methods To Create A File In Linux)
[#]: via: (https://www.2daygeek.com/linux-command-to-create-a-file/)
[#]: author: (Vinoth Kumar https://www.2daygeek.com/author/vinoth/)
在 Linux 上创建文件的 10 个方法
======
我们都知道,在 Linux 上,包括设备在内的一切都是文件。
Linux 管理员每天应该会多次执行文件创建活动(可能是 20 次50 次,甚至是更多,这依赖于他们的环境)。
如果你想 **[在Linux上创建一个特定大小的文件][1]**,查看前面的这个链接。
高效创建一个文件是非常重要的。为什么我说高效?如果你了解一些高效进行你当前活动的方式,你就可以事半功倍。
这将会节省你很多的时间。你可以把这些有用的时间用到到其他重要的事情上。
我下面将会介绍多个在 Linux 上创建文件的方法。我建议你选择几个简单高效的来辅助你的工作。
你不必安装下列的任何一个命令,因为它们已经作为 Linux 核心工具的一部分安装到你的系统上了。
创建文件可以通过以下六个方式来完成。
* **`重定向符号 (>):`** 标准重定向符允许我们创建一个 0KB 的空文件。
* **`touch:`** 如果文件不存在的话touch 命令将会创建一个 0KB 的空文件。
* **`echo:`** echo 命令通过一个参数显示文本的某行。
* **`printf:`** printf 命令用于显示在终端给定的文本。
* **`cat:`** 它串联并打印文件到标准输出。
* **`vi/vim:`** Vim 是一个向上兼容 Vi 的文本编辑器。它常用于编辑各种类型的纯文本。
* **`nano:`** nano 是一个简小且用户友好的编辑器。它复制了 Pico 的外观和优点,而且还是免费的。
* **`head:`** head 用于打印一个文件开头的一部分。
* **`tail:`** tail 用于打印一个文件的最后一部分。
* **`truncate:`** truncate 用于缩小或者扩展文件的尺寸到指定大小。
### 在 Linux 上使用重定向符(>>)创建一个文件
标准重定向符允许我们创建一个 0KB 的空文件。它通常用于重定向一个命令的输出到一个新文件中。在没有命令的情况下使用重定向符号时,它会创建一个文件。
但是它不允许你在创建文件时向其中输入任何文本。然而它对于不是很勤劳的管理员是非常简单有用的。只需要输入重定向符后面跟着你想要的文件名。
(译者注:在输入下面的命令回车后,该命令并不会立刻中断,回车后你其实还可以继续输入一些文本,而这些文本都会被记录到你所创建的文章中去。在输入完成后,你可以使用 Ctrl+C 或者 Ctrl+D 来结束输入)
```
$ > daygeek.txt
```
使用 ls 命令查看刚刚创建的文件。
```
$ ls -lh daygeek.txt
-rw-rw-r-- 1 daygeek daygeek 0 Feb 4 02:00 daygeek.txt
```
### 在 Linux 上使用 touch 命令创建一个文件
touch 命令常用于将每个文件的访问和修改时间更新为当前时间。
如果指定的文件名不存在将会创建一个新的文件。touch 不允许我们在创建文件的同时向其中输入一些文本。它默认创建一个 0KB 的空文件。
```
$ touch daygeek1.txt
```
使用 ls 命令查看刚刚创建的文件。
```
$ ls -lh daygeek1.txt
-rw-rw-r-- 1 daygeek daygeek 0 Feb 4 02:02 daygeek1.txt
```
### 在 Linux 上使用 echo 命令创建一个文件
echo 内置于大多数的操作系统中。它常用于脚本,批处理文件,以及作为插入文本的单个命令的一部分。
它允许你在创建一个文件时就向其中输入一些文本。当然也允许你在之后向其中输入一些文本。
```
$ echo "2daygeek.com is a best Linux blog to learn Linux" > daygeek2.txt
```
使用 ls 命令查看刚刚创建的文件。
```
$ ls -lh daygeek2.txt
-rw-rw-r-- 1 daygeek daygeek 49 Feb 4 02:04 daygeek2.txt
```
可以使用 cat 命令查看文件的内容。
```
$ cat daygeek2.txt
2daygeek.com is a best Linux blog to learn Linux
```
你可以使用两个重定向符 (>>) 添加其他内容到同一个文件。
```
$ echo "It's FIVE years old blog" >> daygeek2.txt
```
你可以使用 cat 命令查看添加的内容。
```
$ cat daygeek2.txt
2daygeek.com is a best Linux blog to learn Linux
It's FIVE years old blog
```
### 在 Linux 上使用 printf 命令创建一个新的文件
printf 命令也可以以类似 echo 的方式执行。
printf 命令常用来显示在终端窗口给出的字符串。printf 可以有格式说明符,转义序列或普通字符。
```
$ printf "2daygeek.com is a best Linux blog to learn Linux\n" > daygeek3.txt
```
使用 ls 命令查看刚刚创建的文件。
```
$ ls -lh daygeek3.txt
-rw-rw-r-- 1 daygeek daygeek 48 Feb 4 02:12 daygeek3.txt
```
使用 cat 命令查看文件的内容。
```
$ cat daygeek3.txt
2daygeek.com is a best Linux blog to learn Linux
```
你可以使用两个重定向符 (>>) 添加其他的内容到同一个文件中去。
```
$ printf "It's FIVE years old blog\n" >> daygeek3.txt
```
你可以使用 cat 命令查看这个文件中添加的内容。
```
$ cat daygeek3.txt
2daygeek.com is a best Linux blog to learn Linux
It's FIVE years old blog
```
### 在 Linux 中使用 cat 创建一个文件
cat 表示串联concatenate。在 Linux 经常用于读取一个文件中的数据。
cat 是在类 Unix 系统中最常使用的命令之一。 它提供了三个与文本文件相关的功能:显示一个文件的内容,组合多个文件的内容到一个输出以及创建一个新的文件。
(译者注:如果 cat 命令后如果不带任何文件的话,下面的命令在回车后也不会立刻结束,回车后的操作同上面的重定向符中的注解)
```
$ cat > daygeek4.txt
2daygeek.com is a best Linux blog to learn Linux
It's FIVE years old blog
```
使用 ls 命令查看创建的文件。
```
$ ls -lh daygeek4.txt
-rw-rw-r-- 1 daygeek daygeek 74 Feb 4 02:18 daygeek4.txt
```
使用 cat 命令查看文件的内容。
```
$ cat daygeek4.txt
2daygeek.com is a best Linux blog to learn Linux
It's FIVE years old blog
```
如果你想向同一个文件中添加其他内容,使用两个连接的重定向符(>>)。
```
$ cat >> daygeek4.txt
This website is maintained by Magesh M, It's licensed under CC BY-NC 4.0.
```
你可以使用 cat 命令查看添加的内容。
```
$ cat daygeek4.txt
2daygeek.com is a best Linux blog to learn Linux
It's FIVE years old blog
This website is maintained by Magesh M, It's licensed under CC BY-NC 4.0.
```
### 在 Linux 上使用 vi/vim 命令创建一个文件
Vim 是一个向上兼容 Vi 的文本编辑器。它通常用来编辑所有种类的纯文本。在编辑程序时特别有用。
vim 中有很多功能可以用于编辑单个文件。
```
$ vi daygeek5.txt
2daygeek.com is a best Linux blog to learn Linux
It's FIVE years old blog
```
使用 ls 查看刚才创建的文件。
```
$ ls -lh daygeek5.txt
-rw-rw-r-- 1 daygeek daygeek 75 Feb 4 02:23 daygeek5.txt
```
使用 cat 命令查看文件的内容。
```
$ cat daygeek5.txt
2daygeek.com is a best Linux blog to learn Linux
It's FIVE years old blog
```
### 在 Linux 上使用 nano 命令创建一个文件
Nano 是一个编辑器,它是一个免费的 Pico 的克隆。nano 是一个小且用户友好的编辑器。它复制了 Pico 的外观及优点,并且是一个免费的应用,它添加了 Pico 缺乏的一系列特性,像是打开多个文件,每行滚动,撤销/重做,语法高亮,行号等等。
```
$ nano daygeek6.txt
2daygeek.com is a best Linux blog to learn Linux
It's FIVE years old blog
This website is maintained by Magesh M, It's licensed under CC BY-NC 4.0.
```
使用 ls 命令查看创建的文件。
```
$ ls -lh daygeek6.txt
-rw-rw-r-- 1 daygeek daygeek 148 Feb 4 02:26 daygeek6.txt
```
使用 cat 命令来查看一个文件的内容。
```
$ cat daygeek6.txt
2daygeek.com is a best Linux blog to learn Linux
It's FIVE years old blog
This website is maintained by Magesh M, It's licensed under CC BY-NC 4.0.
```
### 在 Linux 上使用 head 命令创建一个文件
head 命令通常用于输出一个文件开头的一部分。它默认会打印一个文件的开头 10 行到标准输出。如果有多个文件,则每个文件前都会有一个标题,用来表示文件名。
```
$ head -c 0K /dev/zero > daygeek7.txt
```
使用 ls 命令查看创建的文件。
```
$ ls -lh daygeek7.txt
-rw-rw-r-- 1 daygeek daygeek 0 Feb 4 02:30 daygeek7.txt
```
### 在 Linux 上使用 tail 创建一个文件
tail 命令通常用来输出一个文件最后的一部分。它默认会打印每个文件的最后 10 行到标准输出。如果有多个文件,则每个文件前都会有一个标题,用来表示文件名。
```
$ tail -c 0K /dev/zero > daygeek8.txt
```
使用 ls 命令查看创建的文件。
```
$ ls -lh daygeek8.txt
-rw-rw-r-- 1 daygeek daygeek 0 Feb 4 02:31 daygeek8.txt
```
### 在 Linux 上使用 truncate 命令创建一个文件
truncate 命令通常用作将一个文件的尺寸缩小或者扩展为某个指定的尺寸。
```
$ truncate -s 0K daygeek9.txt
```
使用 ls 命令检查创建的文件。
```
$ ls -lh daygeek9.txt
-rw-rw-r-- 1 daygeek daygeek 0 Feb 4 02:37 daygeek9.txt
```
在这篇文章中,我使用这十个命令分别创建了下面的这十个文件。
```
$ ls -lh daygeek*
-rw-rw-r-- 1 daygeek daygeek 0 Feb 4 02:02 daygeek1.txt
-rw-rw-r-- 1 daygeek daygeek 74 Feb 4 02:07 daygeek2.txt
-rw-rw-r-- 1 daygeek daygeek 74 Feb 4 02:15 daygeek3.txt
-rw-rw-r-- 1 daygeek daygeek 148 Feb 4 02:20 daygeek4.txt
-rw-rw-r-- 1 daygeek daygeek 75 Feb 4 02:23 daygeek5.txt
-rw-rw-r-- 1 daygeek daygeek 148 Feb 4 02:26 daygeek6.txt
-rw-rw-r-- 1 daygeek daygeek 148 Feb 4 02:32 daygeek7.txt
-rw-rw-r-- 1 daygeek daygeek 148 Feb 4 02:32 daygeek8.txt
-rw-rw-r-- 1 daygeek daygeek 148 Feb 4 02:38 daygeek9.txt
-rw-rw-r-- 1 daygeek daygeek 0 Feb 4 02:00 daygeek.txt
```
--------------------------------------------------------------------------------
via: https://www.2daygeek.com/linux-command-to-create-a-file/
作者:[Vinoth Kumar][a]
选题:[lujun9972][b]
译者:[dianbanjiu](https://github.com/dianbanjiu)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.2daygeek.com/author/vinoth/
[b]: https://github.com/lujun9972
[1]: https://www.2daygeek.com/create-a-file-in-specific-certain-size-linux/