bash shell 编程练习
原始文件:
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
/etc/passwd find: `/etc/ntp/crypto': Permission denied
find: `/etc/audisp': Permission denied
find: `/etc/audit': Permission denied find: `/etc/polkit-/localauthority': Permission denied
find: `/etc/dhcp': Permission denied
/etc/pam.d/passwd
find: `/etc/lvm/backup': Permission denied
find: `/etc/lvm/cache': Permission denied
find: `/etc/lvm/archive': Permission denied
find: `/etc/cups/ssl': Permission denied
find: `/etc/pki/rsyslog': Permission denied find: `/etc/pki/CA/private': Permission denied
find: `/etc/vmware-tools/GuestProxyData/trusted': Permission denied
find: `/etc/sudoers.d': Permission denied
find: `/etc/selinux/targeted/modules/active': Permission denied
2. cat -b 把 textfile1 和 textfile2 的文档内容加上行号(空白行不加)之后将内容附加到 textfile3 文档里:
xiluhua@localhost ~/t2scripts $ cat -b e.log | tee e3.log
/etc/passwd find: `/etc/ntp/crypto': Permission denied
find: `/etc/audisp': Permission denied
find: `/etc/audit': Permission denied find: `/etc/polkit-/localauthority': Permission denied
find: `/etc/dhcp': Permission denied
/etc/pam.d/passwd
find: `/etc/lvm/backup': Permission denied
find: `/etc/lvm/cache': Permission denied
find: `/etc/lvm/archive': Permission denied
find: `/etc/cups/ssl': Permission denied
find: `/etc/pki/rsyslog': Permission denied find: `/etc/pki/CA/private': Permission denied
find: `/etc/vmware-tools/GuestProxyData/trusted': Permission denied
find: `/etc/sudoers.d': Permission denied
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.sh
root@localhost /home/xiluhua/t2scripts # ll ttt.sh
-rw-r--r--. root root Jan : ttt.sh
root@localhost /home/xiluhua/t2scripts # chgrp xiluhua ttt.sh
root@localhost /home/xiluhua/t2scripts # ll ttt.sh
-rw-r--r--. root xiluhua Jan : 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. xiluhua xiluhua Jan : tt.sh
xiluhua@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/ t2 xiluhua@localhost ~ $ file -L t2
t2: directory
9. cut
xiluhua@localhost ~/t2 $ cat /etc/passwd|head -n |cut -d : -f ,-,
root:::root:/bin/bash
bin:::bin:/sbin/nologin
daemon:::daemon:/sbin/nologin
adm:::adm:/sbin/nologin
lp:::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 两个文件
abc
efg
12. umask (1)指定在建立文件时预设的权限掩码。
root@localhost ~ # umask root@localhost ~ # umask -S
u=rwx,g=rx,o=rx
13. umask (2)
xiluhua@localhost ~ $ umask xiluhua@localhost ~ $ umask -S
u=rwx,g=rwx,o=rx
14. which命令用于查找文件。
which指令会在环境变量$PATH设置的目录里查找符合条件的文件。
15. whereis
root@localhost ~ # whereis bash
bash: /bin/bash /usr/share/man/man1/bash..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.log
is
you
This's test
are
20. awk (2)
xiluhua@localhost ~/t2 $ awk '{printf "%-8s %-10s\n",$1,$4}' f1.log # 格式化输出
a
like
This's
orange,apple,mongo
21. awk (3)
提取yum list结果的第三列并除重
root@vm-xiluhua /mnt # yum -q list | awk '{print $3}'| sort -u
bash shell 编程练习的更多相关文章
- abc高级bash shell编程
http://www.pythoner.com/122.html abc高级bash shell编程
- linux 10 -Bash Shell编程
二十三. Bash Shell编程: 1. 读取用户变量: read命令是用于从终端或者文件中读取输入的内建命令,read命令读取整行输入,每行末尾的换行符不被读入.在read命令后 ...
- 【shell编程基础0】bash shell编程的基本配置
前面一篇“shell编程之变量篇”主要讲述下shell编程的变量的基本知识:设置变量的方式,自定义变量和环境变量的差别,变量的替换.删除.测试等. 这一篇主要是讲述在bash shell下的一些基本配 ...
- Bash shell编程的语法知识点(1)
Bash shell脚本编程知识点如下(初学,不全,欢迎讨论补充): shell简介 脚本的简单介绍 变量和引用 算术运算 交互式编程 选择判断 条件测试 循环 函数 shell简介 shell是一种 ...
- Bash Shell编程简记
Shell编程简记 经常在linux环境下开发的同学,难免要使用shell的一些命令或者编写小的脚本,我这里也总结和整理下,自己对Shell的理解和常用的一些shell脚本. 按照目录分为如下3个节: ...
- Bash Shell编程要点小结
一.case命令 case variable invalue1) command(s);; value2) command(s);; *) command(s);; esac 如果case变量没有被匹 ...
- GNU Bash Shell 编程图解笔记
bash,Unix shell的一种,在1987年由布莱恩·福克斯为了GNU计划而编写.1989年发布第一个正式版本,原先是计划用在GNU操作系统上,但能运行于大多数类Unix系统的操作系统之上,包括 ...
- bash/shell编程学习(3)
接上节继续, 1. 从键盘读取输入内容 #!/bin/bash read -p 'please input something:' input echo 'your input:' $input 运行 ...
- bash/shell编程学习(1)
1)定义变量 myvar=abc #注:等号前后不能加空格 #或 myvar="abc" #或 myvar='abc' #注:如果变量后面的值中间本身没有空格,加不加引号都无所谓, ...
- bash/shell编程学习(2)
先来复习上节重定向的用法: 1.快速清空文件 cat demo.txt < /dev/null 注:linux中有一个经典名言[一切皆文件],/dev/null可以认为是一个特殊的空文件,更形象 ...
随机推荐
- CF891C Envy 最小生成树/虚树
正解:最小生成树/虚树 解题报告: 传送门! sd如我就只想到了最暴力的想法,一点儿优化都麻油想到,,,真的菜到爆炸了QAQ 然后就分别港下两个正解QAQ 法一,最小生成树 这个主要是要想到关于最小生 ...
- 【Python全栈-HTML】HTML入门
HTML入门介绍 参考: https://www.bilibili.com/video/av21663728/?p=339 http://www.cnblogs.com/yuanchenqi/arti ...
- 【PyQt5-Qt Designer】简易的数字键盘输入+简易计算器
参考如下键盘格式写了一个键盘输入,目前还不能进行运算,后期完善... 效果如下: 完整代码: from PyQt5.QtWidgets import (QApplication,QWidget,QPu ...
- 第 9 章 DOM 的增删改查
DOM 的增删改查 本文不会详细讲解,只是简单提及知识要点,详细可以参考<dom高级编程>. 1. document.write document.write('<h1>创建节 ...
- (1.9)SQL优化——mysql导入导出优化
(1.9)SQL优化——mysql导入导出优化 1.大批量插入数据 [1.1]MyISAM: (1)如果存在表且有数据,插入前先关闭所有非唯一索引. (2)如果表是空的,默认就是先导入数据再创建索引, ...
- 所使用的“System.Web.Mvc, Version=3.0.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35”版本高于所引用的程序集“System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”的版本
System.Web.Mvc.dll引用是感叹号. 解决方法:新建mv3应用程序,右键选择System.Web.Mvc.dll 查看所引用的路径. 在旧程序中重新引用即可.C:\Program Fil ...
- Navigator is deprecated and has been removed from this package
报错:'Navigator is deprecated and has been removed from this package. It can now be installed ' + ...
- Python3学习之路~5.6 shutil & zipfile & tarfile模块
高级的 文件.文件夹.压缩包 处理模块 shutil.copyfileobj(fsrc, fdst[, length])#将文件内容拷贝到另一个文件中,可以部分内容 shutil.copyfile(s ...
- 使用jframe编写一个base64加密解密工具
该工具可以使用exe4j来打包成exe工具(如何打包自己百度) 先上截图功能 运行main方法后,会弹出如下窗口 输入密文 然后点击解密,在点格式化 代码分享 package tools;import ...
- 递归与非递归打印乘法口诀表--Scala(指令式、函数式思维练习)
object Test extends App { def printMultiTable() { var i = 1 while (i < 10) { var j = 1 while (j & ...