标签:
作用是将参数列表转换成小块分段传递给其他命令,以避免参数列表过长的问题
语法格式:
# xargs [-ni]
常用参数:
参数 |
参数说明 |
-n |
分组输出,n个分为一组 |
-i |
与大括号{}关联,使每一个输出的参数都会被执行一次 |
实践说明:
[root@ky01 ~]# find . -type f -name "123.txt"|xargs mv {} /tmp
mv: target `./123.txt‘ is not a directory
[root@ky01 ~]# find . -type f -name "123.txt"|xargs -i mv {} /tmp
[root@ky01 ~]# ls /tmp/
123.txt etc01.tar.gz etc.tar.gz oldboy.txt test.txt
统计数字
语法格式:
# wc [-lwc] 文件
常用参数:
参数 |
参数说明 |
-l |
计算行数 |
-w |
计算字数 |
-c |
计算字符数 |
实践说明:
[root@ky01 ~]# wc -l b.txt
4 b.txt
[root@ky01 ~]# wc -w b.txt
10 b.txt
[root@ky01 ~]# wc -c b.txt
52 b.txt
只显示目录下文件的名称,shell脚本中会用到
语法结构:
# basename [文件]
实践说明:
只显示目录/root/01/02/03/04/05/123.txt的文件名
[root@ky01 ~]# basename 01/02/03/04/05/123.txt
123.txt
改变文件属性
语法结构:
# chattr [-R] [+-=] [属性] 文件
参数 |
参数说明 |
-R |
递归处理 |
属性 |
参数说明 |
a |
只需添加 |
i |
不许更改文件属性 |
实践说明:
[root@ky01 ~]# ls -l 12.txt
-rw-rw-rw- 1 root root 1210 April 24 19:49 12.txt
[root@ky01 ~]# chattr +i 12.txt
[root@ky01 ~]# chmod 777 12.txt
chmod: changing permissions of `12.txt‘: Operation not permitted
[root@ky01 ~]# chattr -i 12.txt
[root@ky01 ~]# chmod 777 12.txt
[root@ky01 ~]# ls -l 12.txt
-rwxrwxrwx 1 root root 1210 April 24 19:49 12.txt
修改文件或目录的用户组
语法结构:
# chgrp 用户组 文件
常用参数:
参数 |
参数说明 |
-R |
递归处理 |
实践说明:
修改文件123.txt的用户和用户组
[root@ky01 ~]# ls -l 123.txt
-rwxrwxrw- 1 ky1 root 31 April 23 12:14 123.txt
[root@ky01 ~]# chgrp ky1 123.txt
[root@ky01 ~]# ls -l 123.txt
-rwxrwxrw- 1 ky1 ky1 31 April 23 12:14 123.txt
查看或更改开机自启动的运行级别的情况,chkconfig管理的服务是/etc/init.d/下的服务文件
原理:chkconfig和当前服务进程的运行情况没有关系,只是在开机时影响服务的启动
实现:
开启实质:rm -f /etc/rc.d/rc3.d/K75oldboy(删除关闭顺序的文件)
ln -s /etc/init.d/oldboy /etc/rc.d/rc3.d/S25oldboy(建立开启顺序文件连接)
关闭实质:rm -f /etc/rc.d/rc3.d/S25oldboy(删除开启顺序的文件)
ln -s /etc/init.d/oldboy /etc/rc.d/rc3.d/S75oldboy(建立关闭顺序文件连接)
语法结构:
# chkconfig [--list、--level] [服务] [on/off]
常用参数:
参数 |
参数说明 |
--list |
查看所有服务在所有级别的开启关闭状态(没有也显示) |
--level |
接级别,设置相应级别的某个服务的开启或关闭 |
实践说明:
[root@ky01 ~]# chkconfig --list netfs
netfs 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@ky01 ~]# chkconfig --level 3 netfs on
[root@ky01 ~]# chkconfig --list netfs
netfs 0:off 1:off 2:off 3:on 4:off 5:off 6:off
[root@ky01 ~]# chkconfig --level 23 netfs on
[root@ky01 ~]# chkconfig --list netfs
netfs 0:off 1:off 2:on 3:on 4:off 5:off 6:off
查看或更改开机自启动的运行级别的情况,chkconfig管理的服务是/etc/init.d/下的服务文件
原理:chkconfig和当前服务进程的运行情况没有关系,只是在开机时影响服务的启动
实现:1、编写服务文件(如名字为oldboy)脚本时需要包含chkconfig管理的代码# chkconfig: 345 25 75(345代表的是启动级别,25代表服务开启顺序的号码,75代表服务关闭顺序的号码,号码默认是1-99号),再添加权限chmod +x oldboy
2、把脚本放到/etc/init.d/文件夹下面,并且希望开机时被chkconfig管理,需要添加chkconfig --add oldboy
3、添加进去的默认在哪个级别上启动要看开发脚本中chkconfig的配置,服务启动顺序和关闭顺序也是看脚本中chkconfig的配置
4、chkconfig --level 3 oldboy on/off的实质
开启实质:rm -f /etc/rc.d/rc3.d/K75oldboy(删除关闭顺序的文件)
ln -s /etc/init.d/oldboy /etc/rc.d/rc3.d/S25oldboy(建立开启顺序文件连接)
关闭实质:rm -f /etc/rc.d/rc3.d/S25oldboy(删除开启顺序的文件)
ln -s /etc/init.d/oldboy /etc/rc.d/rc3.d/S75oldboy(建立关闭顺序文件连接)
标签:
原文地址:http://www.cnblogs.com/tina-python/p/5429665.html