linux chmod

使用权限 : 所有使用者

使用方式 : chmod [-cfvR] [–help] [–version] mode file…

说明 : Linux/Unix 的档案存取权限分为三级 : 档案拥有者、群组、其他。利用 chmod 可以藉以控制档案如何被他人所存取。

把计 :

mode : 权限设定字串,格式如下 : [ugoa…][[+-=][rwxX]…][,…],其中u 表示该档案的拥有者,g 表示与该档案的拥有者属于同一个群体(group)者,o 表示其他以外的人,a 表示这三者皆是。
+ 表示增加权限、- 表示取消权限、= 表示唯一设定权限。
r 表示可读取,w 表示可写入,x 表示可执行,X 表示只有当该档案是个子目录或者该档案已经被设定过为可执行。
-c : 若该档案权限确实已经更改,才显示其更改动作
-f : 若该档案权限无法被更改也不要显示错误讯息
-v : 显示权限变更的详细资料
-R : 对目前目录下的所有档案与子目录进行相同的权限变更(即以递回的方式逐个变更)
–help : 显示辅助说明
–version : 显示版本

范例 :将档案 file1.txt 设为所有人皆可读取 :
chmod ugo+r file1.txt

将档案 file1.txt 设为所有人皆可读取 :
chmod a+r file1.txt

将档案 file1.txt 与 file2.txt 设为该档案拥有者,与其所属同一个群体者可写入,但其他以外的人则不可写入 :
chmod ug+w,o-w file1.txt file2.txt

将 ex1.py 设定为只有该档案拥有者可以执行 :
chmod u+x ex1.py

将目前目录下的所有档案与子目录皆设为任何人可读取 :
chmod -R a+r *

此外chmod也可以用数字来表示权限如 chmod 777 file
语法为:chmod abc file

其中a,b,c各为一个数字,分别表示User、Group、及Other的权限。

r=4,w=2,x=1
若要rwx属性则4+2+1=7;
若要rw-属性则4+2=6;
若要r-x属性则4+1=7。

范例:
chmod a=rwx file


chmod 777 file

效果相同
chmod ug=rwx,o=x file


chmod 771 file

效果相同

若用chmod 4755 filename可使此程式具有root的权限
指令名称 : chown
使用权限 : root

使用方式 : chmod [-cfhvR] [–help] [–version] user[:group] file…

说明 : Linux/Unix 是多人多工作业系统,所有的档案皆有拥有者。利用 chown 可以将档案的拥有者加以改变。一般来说,这个指令只有是由系统管理者(root)所使用,一般使用者没有权限可以改变别人的档案拥有者,也没有权限可以自己的档案拥有者改设为别人。只有系统管理者(root)才有这样的权限。

把计 :

user : 新的档案拥有者的使用者 IDgroup : 新的档案拥有者的使用者群体(group)-c : 若该档案拥有者确实已经更改,才显示其更改动作-f : 若该档案拥有者无法被更改也不要显示错误讯息-h : 只对于连结(link)进行变更,而非该 link 真正指向的档案-v : 显示拥有者变更的详细资料-R : 对目前目录下的所有档案与子目录进行相同的拥有者变更(即以递回的方式逐个变更)–help : 显示辅助说明–version : 显示版本

范例 :
将档案 file1.txt 的拥有者设为 users 群体的使用者 jessie :
chown jessie:users file1.txt

将目前目录下的所有档案与子目录的拥有者皆设为 users 群体的使用者 lamport :
chmod -R lamport:users *
-rw——- (600) — 只有属主有读写权限。

-rw-r–r– (644) — 只有属主有读写权限;而属组用户和其他用户只有读权限。

-rwx—— (700) — 只有属主有读、写、执行权限。

-rwxr-xr-x (755) — 属主有读、写、执行权限;而属组用户和其他用户只有读、执行权限。

-rwx–x–x (711) — 属主有读、写、执行权限;而属组用户和其他用户只有执行权限。

-rw-rw-rw- (666) — 所有用户都有文件读、写权限。这种做法不可取。

-rwxrwxrwx (777) — 所有用户都有读、写、执行权限。更不可取的做法。

以下是对目录的两个普通设定:

drwx—— (700) – 只有属主可在目录中读、写。

drwxr-xr-x (755) – 所有用户可读该目录,但只有属主才能改变目录中的内容
suid的代表数字是4,比如4755的结果是-rwsr-xr-x
sgid的代表数字是2,比如6755的结果是-rwsr-sr-x
sticky位代表数字是1,比如7755的结果是-rwsr-sr-t

MOVE 开发模式

MVC模式在编程中的应用,是一个很了不起的主意。“数据模型(Model)”可以封装与应用程序的业务逻辑相关的数据及对数据的处理方法;“视图层(View)”能够实现数据有目的的显示;“控制器(Controller)”能够在不同层面间起到组织作用,对应用程序的流程进行控制。

不过,可能你在使用这种三层架构模式的过程中会逐渐迷惑。因为有很多代码你不知道把它放哪,就只好把它放到控制层,最后发现在控制层中塞了太多的代码。

LinkedIn的软件工程师Conrad Irwin也遇到同样的问题,于是他开始使用另一种模式:MOVE,即Models(模型)、Operations(操作)、Views(视图)、Events(事件)。

近日Conrad Irwin在个人博客上分享了关于这种模式的一些观点。

概述

Irwin结合上图对MOVE模式先作了简单定义:

  • Models,封装该应用程序中知道的一切;
  • Operations,封装该应用程序要做的一切;
  • Views,帮助用户与应用程序完成交互;
  • Events,用于安全地连接所有这些组件。

为了避免意大利面条式的代码,图中标示出了对哪种类型的对象进行操作是允许的。例如,视图允许监听由模型产生的事件;操作允许修改模型,但模型不应涉及视图或操作。

Models(模型)

这里以一个“User”对象为原型,它至少应用有一个Email地址,也可能有用户名和电话号码。

在一个MOVE模式的Models中只包装知识。这意味着除了Get和Set功能,它们可以包含检查用户密码是否正确这样的方法,但不会包含把密码保存到数据库或传递给外部API这样的功能,因为后面这些工作将由Operations来完成。

Operations(操作)

对应用程序来说,一个常见的操作是用户登陆。这实际上是由两个子操作组成:首先从用户那里获得邮件地址和密码,然后从数据库载入“user”模型并检查密码是否匹配。

Operations是MOVE模式中的行动者。它负责修改模型,在正确的时间显示正确的视图,以及响应由用户交互引发的事件。在一个分解良好的应用程序中,每个子操作都可以独立运行。

采用这种方式的操作有一点很令人振奋,即程序启动后,整个应用本身就可以被当作一个Operations。它会根据需要生成尽可能多的子操作,其中每个子操作都并行地运行。当所有子操作都完成时,程序也便退出。

Views(视图)

登陆页面即是一个视图,它负责显示一些文本框给用户。当用户点击“登陆”按钮时,视图将产生一个“loginAttempt”事件,其中包含用户输入的用户名和密码。

用户能够看到的内容,以及能感受到的互动都由视图提供支持。它们会以一种用户能理解的形式呈现应用反馈,同时还能将简单的用户交互转换成有意义的事件。更重要的是视图不会直接改变模型,它们只是向Operations发起事件,然后通过监听等待由模型发起的事件。

Events(事件)

当用户登陆时,视图会发起“loginAttempt”事件。在登陆操作完成后,“currentUser”模型会发起一个事件通知应用登陆状态已改变。

事件监听让MOVE(及MVC)实现控制反转,允许模型更新视图。这是一种强大的抽象技巧,允许组件互不干扰地耦合在一起。

为什么是现在?

当然,Conrad Irwin并不想被人认为自己是在暗示MVC模式很差,这种大型应用程序架构在过去的几十年里确实非常成功。不过几十年后的今天,新的编程技术已经变得越来越流行,所以你也会在使用过程中逐渐产生一些疑惑。

MVC模式确实很了不起,但它毕竟是几十年前为老的技术而设计。MOVE模式是在其基础上的升级,让你可以更好地利用当前已有的新工具。

monitoring your javaEE application : javamelody

Screenshots

The goal of JavaMelody is to monitor Java or Java EE application servers in QA and production environments. It is not a tool to simulate requests from users, it is a tool to measure and calculate statistics on real operation of an application depending on the usage of the application by users.

JavaMelody is opensource (LGPL) and production ready: in production in an application of 25 person years. JavaMelody is easy to integrate in most applications and is lightweight (no profiling and no database).

JavaMelody is mainly based on statistics of requests and on evolution charts.

It allows to improve applications in QA and production and helps to:

  • give facts about the average response times and number of executions
  • make decisions when trends are bad, before problems become too serious
  • optimize based on the more limiting response times
  • find the root causes of response times
  • verify the real improvement after optimizations

It includes summary charts showing the evolution over time of the following indicators:

  • Number of executions, mean execution times and percentage of errors of http requests, sql requests, jsp pages or methods of business façades (if EJB3, Spring or Guice)
  • Java memory
  • Java CPU
  • Number of user sessions
  • Number of jdbc connections

These charts can be viewed on the current day, week, month, year or custom period.

JavaMelody includes statistics of predefined counters (currently http requests, sql requests, jsp pages and methods of business façades if EJB3, Spring or Guice) with, for each counter :

  • A summary indicating the overall number of executions, the average execution time, the cpu time and the percentage of errors.
  • And the percentage of time spent in the requests for which the average time exceeds a configurable threshold.
  • And the complete list of requests, aggregated without dynamic parameters with, for each, the number of executions, the mean execution time, the mean cpu time, the percentage of errors and an evolution chart of execution time over time.
  • Furthermore, each http request indicates the size of the flow response, the mean number of sql executions and the mean sql time.

It also includes statistics on http errors, on warnings and errors in logs, on data caches if ehcache and on batch jobs if quartz.

An optional and independent collect server may be used if necessary to unload the application of storage management, and of report generation and to centralize the data of clustered applications or of several applications.

 

Site : http://code.google.com/p/javamelody/