Browse > Home / Archive: 三月 2009

| 订阅RSS

[命令集3.1]linux文件的权限

三月 18th, 2009 | No Comments | Posted in Hacks, Linux

用 chmod 和 chown 更改访问权限和所有权。对于所有用户的默认掩码(umask)可以在 /etc/profile (Linux)
或 /etc/login.conf (FreeBSD) 中修改。其默认掩码(umask)通常为 022。掩码可以和777做减法,从而得到755
的权限。
1 –x 执行 # Mode 764 = 执行/读/写 | 读/写 | 读
2 -w- 写 # |—所有者|—用户组|—其他用户|
4 r– 读
ugo=a u=所有者, g=用户组, o=其他用户, a=所有用户

# chmod [OPTION] MODE[,MODE] FILE    # MODE 可以是 [ugoa]*([-+=]([rwxXst]))
# chmod 640 /var/log/maillog         # 更改 maillog 访问权限为 -rw-r-----
# chmod u=rw,g=r,o= /var/log/maillog # 同上
# chmod -R o-r /home/*               # 递归去除所有其他用户的可读权限
                                       在可执行位设置 SUID (知道你在干什么!13)
# chmod u+s /path/to/prog            #
# find / -perm -u+s -print           # 查找所有设置过 SUID 位的程序
# chown user:group /path/to/file     # 改变文件的所有者和文件关联的组
# chgrp group /path/to/file          # 改变文件关联的组
# chmod 640 `find ./ -type f -print` # Change permissions to 640 for all files
# chmod 751 `find ./ -type d -print` # Change permissions to 751 for all directories
Tags: , , ,

Linux秘笈25.Linux的Cut命令

三月 18th, 2009 | 2 Comments | Posted in Hacks, 软件架构

Cut command can be used to display only specific columns from a text file or
other command outputs.
Following are some of the examples.
Display the 1st field (employee name) from a colon delimited file

  $ cut -d: -f 1 names.txt
  Emma Thomas
  Alex Jason
  Madison Randy
  Sanjay Gupta
  Nisha Singh

Display 1st and 3rd field from a colon delimited file

  $ cut -d: -f 1,3 names.txt
  Emma Thomas:Marketing
  Alex Jason:Sales
  Madison Randy:Product Development
  Sanjay Gupta:Support
  Nisha Singh:Sales

Display only the first 8 characters of every line in a file

  $ cut -c 1-8 names.txt
  Emma Tho
  Alex Jas
  Madison
  Sanjay G
  Nisha Si
Tags: , , ,

Linux秘笈24. Uniq命令

三月 17th, 2009 | No Comments | Posted in Linux

Uniq command is mostly used in combination with sort command, as uniq
removes duplicates only from a sorted file. i.e In order for uniq to work, all
the duplicate entries should be in the adjacent lines. Following are some
common examples.
1. When you have an employee file with duplicate entries, you can do the
following to remove duplicates.

   $ sort namesd.txt | uniq
   $ sort –u namesd.txt

2. If you want to know how many lines are duplicates, do the following. The
first field in the following examples indicates how many duplicates where
found for that particular line. So, in this example the lines beginning with
Alex and Emma were found twice in the namesd.txt file.

   $ sort namesd.txt | uniq –c
             2  Alex Jason:200:Sales
             2  Emma Thomas:100:Marketing
             1  Madison Randy:300:Product Development
             1  Nisha Singh:500:Sales
             1  Sanjay Gupta:400:Support

3. The following displays only the entries that are duplicates.

   $ sort namesd.txt | uniqcd
             2 Alex Jason:200:Sales
             2 Emma Thomas:100:Marketing
Tags: , ,

Kill命令与信号

三月 16th, 2009 | No Comments | Posted in Linux

使用kill 或killall 终止或发送一个信号给进程。
# ping -i 60 cb.vu > ping.log &
[1] 4712
# kill -s TERM 4712 # 同 kill -15 4712
# killall -1 httpd # 发送 HUP 信号终止进程 httpd
# pkill -9 http # 发送 TERM 信号终止包含 http 的进程
# pkill -TERM -u www # 发送 TERM 信号终止 www 所有者进程
# fuser -k -TERM -m /home # 终止所有访问 /home 的进程(卸载该分区前)
下面是一些重要的信号:
1 HUP (挂起)
2 INT (中断)
3 QUIT (退出)
9 KILL (KILL 信号不能被捕捉,不能被忽略。)
15 TERM (软件终止信号)

Tags: , ,

Linux秘笈23.Sort命令

三月 5th, 2009 | No Comments | Posted in Linux

Sort命令能够对一个文本文件的行进行排序,下面的几个实用的样例展示怎么去对样例文本进行排序。样例文本的格式为:employee_name:employee_id:department_name.

$ cat names.txt
Emma Thomas:100:Marketing
Alex Jason:200:Sales
Madison Randy:300:Product Development
Sanjay Gupta:400:Support
Nisha Singh:500:Sales

以一个升序排列文本文件

$ sort names.txt
Alex Jason:200:Sales
Emma Thomas:100:Marketing
Madison Randy:300:Product Development
Nisha Singh:500:Sales
Sanjay Gupta:400:Support

以倒序排列文本文件

$ sort -r names.txt
Sanjay Gupta:400:Support
Nisha Singh:500:Sales
Madison Randy:300:Product Development
Emma Thomas:100:Marketing
Alex Jason:200:Sales

用第二字段排列一个以冒号分隔的文本文件

$ sort -t: -k 2 names.txt
Emma Thomas:100:Marketing
Alex Jason:200:Sales
Madison Randy:300:Product Development
Sanjay Gupta:400:Support
Nisha Singh:500:Sales

以第三个字段排列一个以tab分隔的文本文件,并且禁止重复

$ sort -t: -u -k 3 names.txt
Emma Thomas:100:Marketing
adison Randy:300:Product Development
Alex Jason:200:Sales
Sanjay Gupta:400:Support

通过ip地址来排序/etc/hosts文件

$ sort -t . -k 1,1n -k 2,2n -k 3,3n -k 4,4n /etc/hosts
127.0.0.1 localhost.localdomain localhost
192.168.100.101 dev-db.thegeekstuff.com dev-db
192.168.100.102 prod-db.thegeekstuff.com prod-db
192.168.101.20 dev-web.thegeekstuff.com dev-web
192.168.101.21 prod-web.thegeekstuff.com prod-web

合并sort和其他命令

ps –ef | sort : Sort the output of process list
ls -al | sort +4n : List the files in the ascending order of the file-size. i.e sorted by 5th filed and displaying smallest files first.
ls -al | sort +4nr : List the files in the descending order of the file-size. i.e sorted by 5th filed and displaying largest files first.
Tags: , , ,

[架构师]05.架构师就是平衡

三月 2nd, 2009 | No Comments | Posted in 软件架构

当我们想到软件架构时,我们最先想到的是经典的技术活动,如模块化体系、定义接口、分配责任、运用模式,并优化性能,架构师还需要考虑安全性、可用性、保障性、发布管理、部署选项,还包括了其他一些事情,但是这些技术上和程序上的问题必须由干系人和他们的利益进行平衡,采取“干系人和利益”的做法,在需求分析上的一个很好的方式,能够确保一些正在开发软件的需求规范的完整性。

在开发软件的组织和组织内部去分析干系人和他们的利益的过程,能揭露最终和软件架构相关的优先级事项,软件架构师将平衡这些优先级事项,在短期和长期上来说,真是一个适合当前的工作环境的好方法。

思考一下,举个例子,工程部门的软件即服务(SAAS)业务,这个业务可能有一些优先事项,如:合同法务会议、创收、客户保障、成本控制和创造有价值的技术资产,这些业务的优先级可能转化为部门的优先级,像确认功能和正确性,正在开发软件的“品质”,以及确保产品开发团队,确保可持续性和可审性的开发操作,以及适应性和长寿的软件产品。

这是架构师的工作,不仅仅是为用户创造有功能的、具有品质的软件,而且还要去兼顾其他部门优先级的事情,像和商业CEO的成本控制,和运营同事的易于管理的利益,和今后方案编制工作人员的易于学习和易于维护的利益,以及软件师专业的最佳实践。

架构师可以在短期内有意识去选择某一个举足轻重的优先事物,但是长远来看,为了真正做好工作,最好坚持一个适当的平衡,这个有影响力的平衡要适合手头上的工作环境,还要顾虑其他因素,譬如:预期软件寿命,关键软件的业务,技术和组织的财务文化。

总之,软件架构不仅仅是经典的技术活动;在项目中他还要平衡技术需求与商业需求相关者的利益。

选自:Architecting is about balancing

Tags: , ,

Linux秘笈22. Xargs命令

三月 2nd, 2009 | No Comments | Posted in Linux

xargs是一个强有力的命令,它能够捕获一个命令的输出,然后传递给另外一个命令,下面是一些如何有效使用xargs的实用例子。

1. 当你尝试用rm删除太多的文件,你可能得到一个错误信息:/bin/rm Argument list too long. 用xargs去避免这个问题。

find ~ -name ‘*.log’ -print0 | xargs -0 rm -f

2. 获得/etc/下所有*.conf结尾的文件列表,有几种不同的方法能得到相同的结果,下面的例子仅仅是示范怎么实用xargs,在这个例子中实用xargs将find命令的输出传递给ls -l

 
# find /etc -name "*.conf" | xargs ls –l

3. 假如你有一个文件包含了很多你希望下载的URL,你能够使用xargs下载所有链接。

 
# cat url-list.txt | xargs wget –c

4. 查找所有的jpg文件,并且压缩他。

 
# find / -name *.jpg -type f -print | xargs tar -cvzf images.tar.gz

5. 拷贝所有的图片文件到一个外部的硬盘驱动

 
# ls *.jpg | xargs -n1 -i cp {} /external-hard-drive/directory
Tags: , ,