EMACS & 程序 编程点滴...

天下难事必作于易,天下大事必作于细

Lastupdated: 2010-12-28

Linux Shell

TOPsed相关

打包修改的未提交的源代码(由svn管理)

1
$svn st | sed /^?/d | sed 's/M      //g' | xargs -I {} zip target.zip {}

更改文件前缀(后缀)

- 替换a.txt为result.txt
$sed -e 's/\(a\.txt\)$/result\.txt/g'

TOPfind+cp

I 必须指定替换字符 -i 是否指定替换字符-可选
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
- 查找并拷贝
$find . | xargs -I {} cp {} $D_PATH
$find . | xargs -i cp {} $D_PATH

- 遍历查找并在结果中查找匹配字符
$find ./ -name "a.txt" | xargs -I {} grep 'ABCD' {} > result.txt
$find ./ -name "a.txt" | xargs grep 'ABCD' > result.txt
xargs -0 :   空白文字を含んだファイルを処理
在使用find命令的-exec选项处理匹配到的文件时,
find命令将所有匹配到的文件一起传递给exec执行。
而xargs命令每次只获取一部分文件而不是全部。

- 查找当前目录下匹配文件:
$find ./ -name "*data*" -maxdepth 1

- 查找到匹配内容后删除
$find ./ -name  ".svn" -exec rm -fr {} \;
$find ./ -name ".svn" -delete

TOP(dot).bashrc .bash_profile .profile的调用顺序

与bash关联的文件,有以下几个:

  • /etc/profile
  • ~/.bash_profile
  • ~/.bash_login
  • ~/.profile
  • ~/.bashrc
  • ~/.bash_logout

用户登录的时候,首先读入/etc/profile,接下来是~/.bash_profile。

如果~/.bash_profile不存在、读入~/.bash_login。

如果~/.bash_login也不存在,读入~/.profile。~/.bash_logout是在退出登录状态是读入。

而.bashrc是当bash作为进程启动的时候读入。就是说登陆后,如果又执行了 $ bash 等启动bash的操作后,该文件被读入。

具体可以总结为以下几点:

通常登陆(login) & su -
没有.bash_profile 的情况下 按 .bash_login→.profile 的顺序,最终调用 ~/.bashrc
su
只是调用 ~/.bashrc
/bin/bash
如果/bin/sh 中 链接了/bin/bash,.bashrc 不读入,否则读入 .bashrc  

作为设置个人设定的 .bashrc ,是由.profile系列调用的基本配置。如果没有.profile系列的系统,登录的时候不会调用 .bashrc,这一点需要留意。

TOPRPM相关

TOPRPM使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# 展开RPM包到当前目录
$ rpm2cpio hoge.rpm | cpio -id
# 检索所有的rpm文件并解开
$ find . \( -type d -name '.svn' -prune \) -o \( -name "*.rpm" -type f -print \) | xargs -i ksh -c 'rpm2cpio {} | cpio -id'

# i -- 提取文件
# v -- 指示执行进程
# d -- 根据包中文件原来的路径建立目录
# m -- 保持文件的更新时间

# 浏览RPM包内容
$ rpm2cpio xxx.rpm | cpio --list
$ rpm -qlp xxx.rpm

# 查询RPM包的版本
$ rpm -qip xxx.rpm
$ rpm -qi  xxx

# 安装RPM到指定目录
$ rpm -ivh --prefix=/opt/usr xxx.rpm
$ rpm -i xxx.rpm --relocate=/usr=/opt/usr --relocate=/etc=/usr/etc

# 强制安装RPM包
$ rpm --force -i xxx.rpm

# 忽略依存关系来安装
$ rpm --nodeps -i xxx.rpm
$ rpm -i --force --nodeps xxx.rpm

# 忽略MD5错误提示来安装
$ rpm --nomd5 -i xxx.rpm

# 安装RPM并让其自行解决包依赖关系
$ rpm -ivh --aid xxx.rpm

# 安装.src.rpm软件包
$ rpm -i you-package.src.rpm
$ cd /usr/src/redhat/SPECS
$ rpmbuild -bb your-package.specs
# 在/usr/src/redhat/RPM/i386/ (根据具体包的不同,也可能是i686,noarch等等)
# 在这个目录下,有一个新的rpm包,这个是编译好的二进制文件
$ rpm -i new-package.rpm

# 通过RPM管理器查询安装过的包
$ rpm -qa | grep httpd
httpd-2.0.52-25.ent.i386.rpm
httpd-suexec-2.0.52-25.ent.i386.rpm

# 查询RPM包信息
$ rpm -ql 包名   (which xxx)

# 某个程序是哪个软件包安装的,或者哪个软件包包含这个程序
# 返回软件包的全名
$ rpm -qf `which 程序名`
# 返回软件包的有关信息
$ rpm -qif `which 程序名`
# 返回软件包的文件列表
$ rpm -qlf `which 程序名`

$ whereis ftptop
ftptop: /usr/bin/ftptop /usr/share/man/man1/ftptop.1.gz
$ rpm -qf /usr/bin/ftptop
proftpd-1.2.8-1
$ rpm -qf /usr/share/doc/proftpd-1.2.8/rfc/rfc0959.txt
proftpd-1.2.8-1

# 卸载RPM包
$ rpm -e xxx
# 强制卸载
$ rpm -e --nodeps

TOPOthers

1
2
3
4
5
6
7
8
9
-通过internet更新系统时间
$sudo ntpdate t3.hshh.org

-二进制文件查看
$objdump -b binary -s

-二进制表示,并且加上 0x前缀
$od -tx1 -An file > temp | xargs sed 's/ / 0x/g' temp
$od -tx1 -An file | sed -e 's/ / 0x/g'
© www.yifeiyang.net
net tracking

                                                                                                 stats