su-kaiyao translated

This commit is contained in:
su-kaiyao 2014-12-06 21:54:40 +08:00
parent d3bcd51893
commit e69d01e260
2 changed files with 89 additions and 88 deletions

View File

@ -1,88 +0,0 @@
[su-kaiyao] translating
How To Run Linux Programs From The Terminal In Background Mode
================================================================================
![Linux Terminal Window.](http://0.tqn.com/y/linux/1/W/r/G/1/terminal.JPG)
Linux Terminal Window.
This is a short but useful guide to show how to run Linux applications from the terminal whilst allowing the terminal to retain control.
There are various ways of opening a terminal window in Linux and it largely depends on your choice of distribution and the desktop environment.
Using Ubuntu you can open a terminal by using the CTRL + ALT + T key combination. You can also open a terminal window by pressing the super key (Windows Key), on the keyboard, to [bring up the Dash][1] and search for "TERM". Clicking on the "Term" icon will open a terminal window.
For other desktop environments such as XFCE, KDE, LXDE, Cinnamon and MATE you will find the terminal within the menu. Some distributions will have a terminal icon in a dock or as a launcher on a panel.
You can generally start an application from the terminal by simply entering the name of the program. For instance you can start Firefox by typing "firefox".
The benefit of running an application from the terminal is that you can include additional options.
For instance if you type the following a new Firefox browser window will open and the default search engine will be used to search for the term between quotes:
firefox -search "Linux.About.Com"
You will notice that if you run Firefox, the application will open and the control will be returned to the terminal which means you can continue working within the terminal.
Generally if you run an application from within the terminal, the application will open and you won't regain control of the terminal until the application is closed. This is because you opened the program in the foreground.
To be able to open a program in the Linux terminal and return control to the terminal you need to open the application as a background process,
In order to open a program as a background process simply add the ampersand (&) symbol to the command as shown below:
libreoffice &
An application might not run just by providing the program's name in the terminal. If the program doesn't reside in one of the folders set within the PATH variable then you will need to specify the whole path name in order to run the program.
/path/to/yourprogram &
If you aren't sure where a program resides within the Linux folder structure use the find or [locate][2] command to find the application.
The syntax for finding a file is as follows:
find /path/to/start/from -name programname
For instance if you wanted to find the location of Firefox use the following command:
find / -name firefox
The output will whizz past quite quickly and so you will want to pipe the output to either [less][3] or [more][4] as follows:
find / -name firefox | more
find / -name firefox | less
The find command will return a number of permission denied errors for folders that you don't have permissions to search.
You can alway provide the [sudo command to elevate your permissions][5]. If sudo isn't installed you will need to switch to a user that has permissions.
sudo find / -name firefox | more
If you know that the file you are looking for is within the folder structure in which you are currently located then you can replace the forward slash with a period as follows:
sudo find . -name firefox | more
You may or may not need the elevated permissions provided by sudo. If you are looking for something within your home folder structure then it won't be required.
Some applications require elevated permissions to run and you may get a lack of permissions error unless you use either a user with adequate permissions or elevate those permissions using sudo.
Here is a neat trick. If you run an application and it requires elevated permissions to run, type the following:
sudo !!
--------------------------------------------------------------------------------
via: http://linux.about.com/od/commands/fl/How-To-Run-Linux-Programs-From-The-Terminal-In-Background-Mode.htm
作者:[Gary Newell][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[a]:http://linux.about.com/bio/Gary-Newell-132058.htm
[1]:http://linux.about.com/od/howtos/fl/Learn-Ubuntu-The-Unity-Dash.htm
[2]:http://linux.about.com/od/commands/l/blcmdl1_locate.htm
[3]:http://linux.about.com/library/cmd/blcmdl1_less.htm
[4]:http://linux.about.com/library/cmd/blcmdl1_more.htm
[5]:http://linux.about.com/od/commands/l/blcmdl8_sudo.htm

View File

@ -0,0 +1,89 @@
如何从终端以后台模式运行Linux程序
===
![Linux Terminal Window.](http://0.tqn.com/y/linux/1/W/r/G/1/terminal.JPG)
Linux终端窗口。
这是一个简短但是非常有用的教程它向你展示从终端运行Linux应用程序的同时如何保证终端仍然在控制之中。
在Linux中有许多方式可以打开一个终端这主要取决于你分类的选择和桌面环境。
使用Ubuntu你可以使用CTRL + ALT + T组合键打开一个终端。你也可以点击超级键(Windows键)打开一个终端窗口。在键盘上,[打开Ubuntu Dash][1],然后搜索"TERM"。点击"Term"图标将会打开一个终端窗口。
其他诸如XFCE, KDE, LXDE, Cinnamon和MATE的桌面环境你将会在菜单中发现终端。还有一些分类会把终端图标放在入口处或者在面板上放置终端启动器。
你可以在终端输入一个程序的名字来启动一个应用。举例,你可以通过输入"firefox"启动火狐浏览器。
从终端运行程序的好处是一可以包含额外的选项。
举个例子,如果你输入下面的命令,一个新的火狐浏览器将会打开,而且默认的搜索引擎将会搜索引用之间的术语:
firefox -search "Linux.About.Com"
你会发现,如果你运行火狐浏览器,应用程序将被打开,并且控制将会回到终端,这将意味着你可以继续在终端工作。
通常情况下,如果你通过终端运行一个程序,程序将被打开,并且直到那个程序关闭结束,你将不会重新获得终端的控制权。这是因为你是在前台打开程序的。
想要从终端运行一个程序,并且立即将终端的控制权返回给你,你需要以后台进程的方式打开程序。
为了以后台进程的方式打开一个程序,只需要添加符号(&)到命令中,如下面所示:
libreoffice &
在终端中仅仅提供程序的名字,应用程序可能运行不了。如果程序不存在于一个设置了路径变量的文件夹中,你需要指定完成的路径名来运行程序。
/path/to/yourprogram &
如果你并不确定一个程序是否存在于Linux文件结构使用find或者locate命令来查询应用程序。
找一个文件的语法如下:
find /path/to/start/from -name programname
举个例子可以使用下面的命令寻找Firefox的位置
find / -name firefox
输出会很快掠过,所以你可以以管道的方式控制输出的多少:
find / -name firefox | more
find / -name firefox | less
find命令将会返回因权限拒绝而发生错误的文件夹数量这些文件夹你没有权限去搜索。
你可以使用sudo命令提升你的权限。如果sudo没有安装你需要切换到拥有权限的用户
sudo find / -name firefox | more
如果你知道你想寻找的文件在你的当前文件夹结构中,你可以一个点代替先前的斜线,如下:
sudo find . -name firefox | more
你可能不需要sudo来提升权限。如果你在home文件夹结构中寻找文件sudo就不需要。
一些应用程序需要提升用户权限来运行你可能得到一个缺少权限的错误除非你使用一个具有足够权限的用户或者使用sudo提升你的权限。
下面是一个小花招。如果你运行一个程序,而且它需要提升权限来运行,输入下面命令:
sudo !!
---
via: http://linux.about.com/od/commands/fl/How-To-Run-Linux-Programs-From-T
he-Terminal-In-Background-Mode.htm
作者:[Gary Newell][a]
译者:[su-kaiyao](https://github.com/su-kaiyao)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中>
国](http://linux.cn/) 荣誉推出
[a]:http://linux.about.com/bio/Gary-Newell-132058.htm
[1]:http://linux.about.com/od/howtos/fl/Learn-Ubuntu-The-Unity-Dash.htm
[2]:http://linux.about.com/od/commands/l/blcmdl1_locate.htm
[3]:http://linux.about.com/library/cmd/blcmdl1_less.htm
[4]:http://linux.about.com/library/cmd/blcmdl1_more.htm
[5]:http://linux.about.com/od/commands/l/blcmdl8_sudo.htm