博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
bash shell 编程练习
阅读量:7282 次
发布时间:2019-06-30

本文共 4193 字,大约阅读时间需要 13 分钟。

原始文件:

find /etc -name passwd 2>&1 | tee ee.log

 

1. cat -n 把 e.log 的文档内容加上行号后输入 e2.log 这个文档里:

xiluhua@localhost ~/t2scripts $ cat -n e.log | tee e2.log     1  /etc/passwd     2     3     4  find: `/etc/ntp/crypto': Permission denied     5  find: `/etc/audisp': Permission denied     6  find: `/etc/audit': Permission denied     7     8  find: `/etc/polkit-1/localauthority': Permission denied     9  find: `/etc/dhcp': Permission denied    10  /etc/pam.d/passwd    11  find: `/etc/lvm/backup': Permission denied    12  find: `/etc/lvm/cache': Permission denied    13  find: `/etc/lvm/archive': Permission denied    14  find: `/etc/cups/ssl': Permission denied    15  find: `/etc/pki/rsyslog': Permission denied    16    17    18    19    20    21    22  find: `/etc/pki/CA/private': Permission denied    23  find: `/etc/vmware-tools/GuestProxyData/trusted': Permission denied    24  find: `/etc/sudoers.d': Permission denied    25  find: `/etc/selinux/targeted/modules/active': Permission denied

 

2. cat -b 把 textfile1 和 textfile2 的文档内容加上行号(空白行不加)之后将内容附加到 textfile3 文档里:

xiluhua@localhost ~/t2scripts $ cat -b e.log | tee e3.log     1  /etc/passwd       2  find: `/etc/ntp/crypto': Permission denied     3  find: `/etc/audisp': Permission denied     4  find: `/etc/audit': Permission denied      5  find: `/etc/polkit-1/localauthority': Permission denied     6  find: `/etc/dhcp': Permission denied     7  /etc/pam.d/passwd     8  find: `/etc/lvm/backup': Permission denied     9  find: `/etc/lvm/cache': Permission denied    10  find: `/etc/lvm/archive': Permission denied    11  find: `/etc/cups/ssl': Permission denied    12  find: `/etc/pki/rsyslog': Permission denied          13  find: `/etc/pki/CA/private': Permission denied    14  find: `/etc/vmware-tools/GuestProxyData/trusted': Permission denied    15  find: `/etc/sudoers.d': Permission denied    16  find: `/etc/selinux/targeted/modules/active': Permission denied

3. cat /dev/null 清空 ee.log 文档内容:

cat /dev/null > e3.log

 4. chattr  +i:不得任意更动文件或目录。

root@localhost /home/xiluhua/t2scripts $ chattr +i ttt.sh $ 加了 +i 之后,root权限也删不了了root@localhost /home/xiluhua/t2scripts $ rm -rf ttt.sh rm: cannot remove `ttt.sh': Operation not permitted

5. chgrp 

root@localhost /home/xiluhua/t2scripts # touch ttt.shroot@localhost /home/xiluhua/t2scripts # ll ttt.sh -rw-r--r--. 1 root root 0 Jan 15 15:22 ttt.shroot@localhost /home/xiluhua/t2scripts # chgrp xiluhua ttt.sh root@localhost /home/xiluhua/t2scripts # ll ttt.sh -rw-r--r--. 1 root xiluhua 0 Jan 15 15:22 ttt.sh

6. chmod

xiluhua@localhost ~/t2 $ chmod --reference=t.sh tt.sh # 以 t.sh 为原型更改 tt.sh 的权限xiluhua@localhost ~/t2 $ ll tt.sh-rwxrwxr-x. 1 xiluhua xiluhua 48 Jan 15 16:40 tt.shxiluhua@localhost ~/t2 $

7. file (1) 用于辨识文件类型。

xiluhua@localhost ~/t2scripts $ file t.sh -i  # 显示 mime 类别t.sh: text/x-shellscript; charset=us-ascii

8. file (2) 显示符号链接的文件类型

xiluhua@localhost ~ $ ln -s t2scripts/ t2xiluhua@localhost ~ $ file -L  t2t2: directory

 9. cut

xiluhua@localhost ~/t2 $  cat /etc/passwd|head -n 5|cut -d : -f 1,3-5,7root:0:0:root:/bin/bashbin:1:1:bin:/sbin/nologindaemon:2:2:daemon:/sbin/nologinadm:3:4:adm:/sbin/nologinlp:4:7:lp:/sbin/nologin

10. lsattr 用于显示文件属性,配合 chattr 命令使用

xiluhua@localhost ~/t2 $ lsattr tt.sh ----i--------e- tt.sh

11. tee

xiluhua@localhost ~/t2 $ cat f3.log | tee f4.log f5.log # 同时输出到 f4和f5 两个文件abcefg123456

12. umask (1)指定在建立文件时预设的权限掩码。

root@localhost ~ # umask0022root@localhost ~ # umask -Su=rwx,g=rx,o=rx

13. umask (2)

xiluhua@localhost ~ $ umask0002xiluhua@localhost ~ $ umask -Su=rwx,g=rwx,o=rx

 14. which命令用于查找文件。

which指令会在环境变量$PATH设置的目录里查找符合条件的文件。

15. whereis

root@localhost ~ # whereis bashbash: /bin/bash /usr/share/man/man1/bash.1.gz

16. scp (1) 本地到远程

scp install.log xiluhua@192.168.178.132:~

17. scp (2) 远程到本地

scp xiluhua@192.168.178.132:~/rmq_bk_gc.log .

18. awk 是一种处理文本文件的语言,是一个强大的文本分析工具。

 

19. awk (1)

xiluhua@localhost ~/t2 $ awk '{print $1,$3}' f1.log2 is3 youThis's test10 are

20. awk (2)

xiluhua@localhost ~/t2 $ awk '{printf "%-8s %-10s\n",$1,$4}' f1.log  # 格式化输出2        a         3        like      This's             10       orange,apple,mongo

21. awk (3)

提取yum list结果的第三列并除重

root@vm-xiluhua /mnt # yum -q list | awk '{print $3}'| sort -u

 

转载地址:http://fgzjm.baihongyu.com/

你可能感兴趣的文章
Packet Tacer做Cisco终端访问服务器实验
查看>>
用REDIS+PHP实现跨机器session共享
查看>>
rsyslog配置错误导致日志messages secure tallylog spooler 0byte空没有日志
查看>>
亲自测试可以用: sql server 2008 r2 安装提示license that key.......
查看>>
JAX-WS Client Application超时设置
查看>>
如何解决企业的虚拟UC和VDI问题?
查看>>
monitor session
查看>>
存储领域常见术语解释
查看>>
一次ogg extract抽取进程异常abending问题处理OGG-00446
查看>>
linux下使用split 来分割大文件
查看>>
mysql 基础
查看>>
狐狸坑蛋糕
查看>>
svn+apache for centos 5
查看>>
AIX如何查看文件系统分布在哪个物理磁盘上
查看>>
19.VLAN的几种划分
查看>>
一张图告诉你,只会jQuery还不够!!!!
查看>>
linux系统下清空所有arp缓存
查看>>
Java操作MongoDB
查看>>
sybase锁机制以及死锁现象避免
查看>>
Linux lvm逻辑卷的使用
查看>>