Merge pull request #556 from SteveArcher/master

[Translated]7 Tips For Becoming A Linux Terminal Power User
This commit is contained in:
Xingyu.Wang 2013-12-11 22:13:47 -08:00
commit e2258a21f7
2 changed files with 63 additions and 63 deletions

View File

@ -1,63 +0,0 @@
Translate by SteveArcher╮(╯▽╰)╭
7 Tips For Becoming A Linux Terminal Power User
================================================================================
The Linux terminal is much more than merely entering commands into it. If you master the basic tricks, it will assist you in mastering the Bash shell that is used as default on a number of Linux distributions.
As stated on howtogeek.com, here are some tips for new users as well as advanced users who may have missed out on something along the way-
**1. Tab Completion** This saves time and is also handy if youre unsure of a file or commands exact name. For instance, theres a file named “really long file name” in the current directory and you wish to delete it. You can type the entire file name, however, you will have to ensure that you escape the space characters properly. In case of multiple files in the current directory which start with the letter r, Bash will not be aware of the one you want.
In the event you have another file named “really very long file name” in the current directory and you hit Tab. Bash will fill in the “really\ “ part for both the files start with that. Post that press Tab again and youll find a list of matching file names.
**2. Pipes** This permits you to transmit the output of a command to another command. In the UNIX philosophy, every program is a small utility that performs one thing well. For instance, the ls command lists out the files in the current directory and the grep command searches its input for a specified term.
You can combine these with pipes (the | character) and search for a file in the current directory. The command given below searches for the word “word”:
ls | grep word
**3. Wild Cards** - The * (asterisk) character is a wild card for matching anything. For instance, if you want to delete both “really long file name” and “really very long file name” from the current directory, you can run the following command:
rm really*name
This command deletes all files with file names starting with “really” and ending with “name.” However, in case you ran rm * instead, you would end up deleting every file in the current directory.
**4. Output Redirection** - The > character redirects a commands output to a file in place of another command. For instance, the following line runs the ls command to list the files in the current directory and in lieu of printing that list to the terminal, it prints to a file named “file1” in the current directory:
ls > file1
**5. Command History** Bash memorizes history of the commands you enter into it. The up and down arrow keys can be used to scroll through recent commands used by you. The history command prints out a list of these commands for piping it to grep in order to search for commands used by you recently.
~, . & ..
The ~ character also called the tilde is used to show the current users home directory. So in lieu of typing cd /home/name for going to your home directory, you can type cd ~. This also functions with relative paths cd ~/Desktop to go to the current users desktop.
In the same way, the . is for the current directory and the .. is for the directory above the current directory. So, cd .. goes up a directory. It functions with relative paths for instance when you are in your Desktop folder and wish to go to the Documents folder, that is in the same directory as the Desktop folder, you can make use of the cd ../Documents command.
**6. Running a Command in the Background** Bash by default executes every command that is run by you in the current terminal. Its normally okay but what if you wish to launch an application and maintain utilizing the terminal? By typing firefox for launching Firefox, it will take charge of your terminal and show error messages and other output till you have closed it. You can use the & operator to the end of the command for Bash to execute the program in the backdrop.
firefox &
**7. Conditional Execution** Bash can also run two commands sequentially. The second command can only execute when the first command is completed with success. For doing this, you can put both commands on the same line segregated by a &&, or double ampersand. The command given below will wait for five seconds, and start the gnome-screenshot tool:
sleep 5 && gnome-screenshot
--------------------------------------------------------------------------------
via: http://www.efytimes.com/e1/fullnews.asp?edid=123564
译者:[译者ID](https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[1]:
[2]:
[3]:
[4]:
[5]:
[6]:
[7]:
[8]:
[9]:
[10]:
[11]:
[12]:

View File

@ -0,0 +1,63 @@
成为 Linux 终端高手的 7 个基本点
================================================================================
Linux 终端不仅是一个键入命令的地方。如若你能熟谙基本操作,那么你将掌握绝大多数 Linux 发行版的默认配置 Bash shell。
howtogeek.com 对初级用户,以及那些学习过程中或多或少有一些遗漏的高级用户提出几个基本点——
**1.Tab 补全** 这样能节省时间并且对于输入那些你不确定其具体名称的文件和命令来说很方便。比如当前目录下有一个名为“really long file name”的文件你想要删除它。你可以输入完整的文件名但是你必须确保正确地输入了空格。若当前目录下还有许多以字母“r”开头的文件(如果你没有正确地输入空格) Bash 将不知道你想要删除哪一个文件。
如果在当前目录下存在着另一个名为“really very long file name”的文件你敲击了Tab键。Bash
将为所有以“r”开头的文件自动填充“really\”部分。此时继续敲击Tab键你将得到匹配所有文件名的列表。
**2.管道机制** 这种机制允许你把一条命令的输出传送到另一条命令。按照 UNIX 哲学每个程序都足够小只做一件事并将之做到最好。例如ls命令列出当前目录下的所有文件grep命令搜索输入其中的指定检索项。
你可以通过管道机制(|字符把二者结合起来在当前目录下搜索文件。以下给出的命令在当前文件夹下搜索关键字为“word”的文件
ls | grep word
**3.通配符** “*”星号字符是一种匹配任意长度字符的通配符。比如你想删除当前文件夹下名为“really long file name”和“really very long file name”的文件你可以运行以下命令
rm really*name
这条命令会删除所有以“really”开头以“name”结尾的文件。但是如果你运行的是 rm * 这条命令,你将会删除文件夹下的所有文件。
**4.输出重定向** “>”字符可以把一条命令的输出重定向到一个文件或另一条命令。比如,下面这行命令执行完 ls 后会列出当前文件夹下的所有文件其结果不是在终端显示而是输出到当前文件夹下一个名为“file1”的文件中去:
ls > file1
**5.历史记录** Bash 能记住你以前输入过的命令,上、下方向键可以逐行调出它们。使用 history 命令打印历史记录,以管道机制 grep 选择性地输出你想要的结果。
~, . & ..
“~”,也叫做波浪符,用来表示当前用户的主目录。相比通过 cd /home/name 到达你的主目录,你可以输入 cd ~ 来达到相同效果。这点也可以在相关路径上使用 比如 cd ~/Desktop 能够到达当前用户的 Desktop 目录。
同样,“.”代表当前目录,“..”代表当前目录的父目录。使用 cd .. 可以返回上一级目录。它们也可以用在相关路径上,举例说明:你当前处在 Desktop 文件夹下,通过 cd ../Documents 命令,你可以转到与 Desktop 共有同一父文件夹的 Documents 文件夹去。
**6.后台命令** Bash 默认会在当前终端执行你键入的每条命令。通常没有问题,但是如果你想要在启动应用后继续使用终端呢?通过输入 firefox 启动火狐浏览器,你的终端将被错误提示等各种信息输出占据,直到你关闭火狐浏览器为止。在 Bash 中你可以通过在命令结尾添加“&”操作符来后台执行程序。
firefox &
**7.条件执行** Bash 也可以连续执行两条命令。 第二条命令仅在第一条命令成功执行后才会开始执行。如若如此,你可以通过键入“&&”,也就是两个与字符进行分隔,在同一行输入两条命令。下面给出的命令会在等待 5 秒后运行 gnome-screenshot 工具:
sleep 5 && gnome-screenshot
--------------------------------------------------------------------------------
via: http://www.efytimes.com/e1/fullnews.asp?edid=123564
译者:[SteveArcher](https://github.com/SteveArcher) 校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[1]:
[2]:
[3]:
[4]:
[5]:
[6]:
[7]:
[8]:
[9]:
[10]:
[11]:
[12]: