重定向、管道和用户管理练习题
一、重定向、管道的用法练习
1、将/etc/issue文件的内容转换为大写保存到/tmp/issue.out文件中
[root@localhost ~]# tr [a-z] [A-Z] < /etc/issue > /tmp/issue.out [root@localhost ~]# cat /tmp/issue.out \S KERNEL \R ON AN \M
或者
[root@localhost ~]# tr '[:lower:]' '[:upper:]' < /etc/issue > /tmp/issue.out.bak [root@localhost ~]# cat /tmp/issue.out.bak \S KERNEL \R ON AN \M
2、将当前系统登录用户信息转换为大写后保存至/tmp/who.out文件中
[root@localhost ~]# w |tr '[:lower:]' '[:upper:]' > /tmp/who.out [root@localhost ~]# cat /tmp/who.out 10:54:38 UP 1:23, 2 USERS, LOAD AVERAGE: 0.00, 0.01, 0.05 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT ROOT PTS/0 10.1.250.91 09:31 6.00S 0.49S 0.02S W ROOT PTS/1 10.1.250.91 09:36 21:10 0.29S 0.26S INFO TR
3、一个Linux用户给root发邮件,邮件标题为help,正文是:Hello,I am 用户名,the system version is here,please help me to check it ,thanks!
操作系统信息
[nieda@localhost ~]$ mail -s "help" root <<eof > Hello,I am `whoami`,the system version is here,please help me to check it,thanks! > `uname -or` > eof [nieda@localhost ~]$
[root@localhost ~]# mail Heirloom Mail version 12.5 7/5/10. Type ? for help >N 8 nieda Sun Jul 31 11:01 19/716 "help" & 8 Message 8: From nieda@localhost.localdomain Sun Jul 31 11:01:36 2016 Return-Path: <nieda@localhost.localdomain> X-Original-To: root Delivered-To: root@localhost.localdomain Date: Sun, 31 Jul 2016 11:01:36 +0800 To: root@localhost.localdomain Subject: help User-Agent: Heirloom mailx 12.5 7/5/10 Content-Type: text/plain; charset=us-ascii From: nieda@localhost.localdomain (nieda) Status: RHello,I am nieda,the system version is here,please help me to check it,thanks! 3.10.0-327.el7.x86_64 GNU/Linux
其中`whoami`可以用$USER替换,uname -ar可能信息不全,可以用uname -a或者cat /etc/centos-release
也可以将要发送的信息先写在一个文件里,然后在发送,但是要发送的文件里只能是纯文本,不能有变量和命令。
4、将/root/下文件列表,显示成一行,文件名之间用空格隔开
[root@localhost ~]# ls /root/ |tr '\n' ' ' anaconda-ks.cfg Desktop Documents Downloads f1 file1 initial-setup-ks.cfg Music Pictures Public Templates Videos [root@localhost ~]#
5、file1文件的内容为“1 2 3 4 5 6 7 8 9 10”计算出所有数字的总和
[root@localhost testdir]# cat file 1 2 3 4 5 6 7 8 9 10 [root@localhost testdir]# cat file |tr ' ' '+'|bc 55
6、删除wndows文本文件中的‘^M’字符
操作系统中^是ctrl的显示方式,在Windows中ctrl+M是回车换行的意思
[root@localhost /testdir]# ll Windows.txt -rw-r--r--. 1 root root 122 Aug 1 16:21 Windows.txt [root@localhost /testdir]# file Windows.txt Windows.txt: ASCII text, with CRLF line terminators [root@localhost /testdir]# hexdump -C Windows.txt 00000000 0d 0a 0d 0a 48 65 6c 6c 6f 2c 6e 69 63 65 20 74 |....Hello,nice t| 00000010 6f 20 6d 65 65 74 20 79 6f 75 21 0d 0a 0d 0a 0d |o meet you!.....| 00000020 0a 4c 65 74 27 73 20 73 74 75 64 79 20 68 61 72 |.Let's study har| 00000030 64 20 61 73 20 62 65 73 74 20 61 73 20 77 65 20 |d as best as we | 00000040 63 61 6e 20 64 6f 20 69 6e 20 74 68 65 20 6e 65 |can do in the ne| 00000050 78 74 20 6d 6f 6e 74 68 73 2c 0d 0a 0d 0a 61 6e |xt months,....an| 00000060 64 20 69 20 62 65 6c 65 76 65 20 77 65 20 63 61 |d i beleve we ca| 00000070 6e 20 64 6f 20 77 65 6c 6c 2e |n do well.| 0000007a [root@localhost /testdir]# cat Windows.txt Hello,nice to meet you!Let's study hard as best as we can do in the next months,and i beleve we can do well.[root@localhost /testdir]#
[root@localhost /testdir]# hexdump -c Windows.txt 0000000 \r \n \r \n H e l l o , n i c e t 0000010 o m e e t y o u ! \r \n \r \n \r 0000020 \n L e t ' s s t u d y h a r 0000030 d a s b e s t a s w e 0000040 c a n d o i n t h e n e 0000050 x t m o n t h s , \r \n \r \n a n 0000060 d i b e l e v e w e c a 0000070 n d o w e l l . 000007a
其中Windows.txt中的换行都是^M,可以看到它的编码是\r\n和回车换行一样
[root@localhost /testdir]# tr -d '[:cntrl:]M' < Windows.txt Hello,nice to meet you!Let's study hard as best as we can do in the next months,and i beleve we can do well.[root@localhost /testdir]#
可以看出换行已经被删除了
7、处理字符串“xt.,| 1 jr#!$mn 2 c*/fe 3 uz 4”,只保留其中的数字和空格
[root@localhost testdir]# cat a xt.,| 1 jr#!$mn 2 c*/fe 3 uz 4 [root@localhost testdir]# tr -c -d '[:digit:][:space:]' < a1 2 3 4
8、将PATH变量每个目录显示在独立的一行
[root@localhost testdir]# echo $PATH /usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin [root@localhost testdir]# echo $PATH|tr ':' '\n' /usr/lib64/qt-3.3/bin /usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /root/bin
9、删除指定文件的空行
[root@localhost testdir]# cat a hello,wangI am rootI have some questions about the linux command need your helpif you have time,call me please! eof [root@localhost testdir]# tr -s '\n' < a hello,wang I am root I have some questions about the linux command need your help if you have time,call me please! eof [root@localhost testdir]#
10、将文件中每个单词(字母)显示在独立的一行,并无空行
[root@localhost testdir]# tr '[:blank:][:punct:]' '\n' < word |tr -s '\n' hello this is the CCTV welcome to listen our news you can look the news happend everywhere at once
二、用户、组及其权限管理练习
1、创建用户gentoo,附加组为bin和root,默认shell是/bin/sch,注释信息为“Gentoo Distributuon”
[root@localhost ~]# useradd -G bin,root -s /bin/sch -c "Gentoo Distribution" geetoo [root@localhost ~]# id geetoo uid=1002(geetoo) gid=1002(geetoo) groups=1002(geetoo),0(root),1(bin)
2、创建下面的用户、组和组成员关系
名字为admins的组
用户natasha,使用admins作为附加组
用户harry,也使用admins作为附属组
用户sarah,不可交互登录系统,且不是admins的成员,natasha,harry,sarah密码都是centos
[root@localhost ~]# groupadd admins [root@localhost ~]# useradd -G admins natasha [root@localhost ~]# useradd -G admins harry;useradd -s /sbin/nologin sarah [root@localhost ~]# echo centos |passwd --stdin natasha harry sarah passwd: Only one user name may be specified. [root@localhost ~]# echo centos |passwd --stdin natasha Changing password for user natasha. passwd: all authentication tokens updated successfully. [root@localhost ~]# echo centos |passwd --stdin harry Changing password for user harry. passwd: all authentication tokens updated successfully. [root@localhost ~]# echo centos |passwd --stdin sarah Changing password for user sarah. passwd: all authentication tokens updated successfully. [root@localhost ~]# id natasha uid=1003(natasha) gid=1004(natasha) groups=1004(natasha),1003(admins) [root@localhost ~]# id harry uid=1004(harry) gid=1005(harry) groups=1005(harry),1003(admins) [root@localhost ~]# id sarah uid=1005(sarah) gid=1006(sarah) groups=1006(sarah)
转载于:https://blog.51cto.com/11551196/1833032
重定向、管道和用户管理练习题相关推荐
- linux用户管理练习题
转载自:http://blog.sina.com.cn/s/blog_6a8d2f120100qiyj.html 1)新建一个组group1,新建一个系统组group2 参考答案: groupadd ...
- 【Linux】Linux常用命令--文件打开、创建、移动、用户管理权限等相关命令
目录 一.关于Linux文件目录 二.Linux常用命令 1.文件的打开显示命令 1.1 ls命令 1.2 cd命令 1.3 vim命令 2.文件夹的创建/删除/移动命令 2.1创建 2.2删除 2. ...
- Linux文件管理和用户管理
Linux命令格式: 命令 [选项] [参数] 命令:实现某种功能的程序.如ls.date 选项:命令中实现某种功能的字母(短选项)或单词(长选项)代号.如ls --help . ls ...
- Linux笔记1(安装,目录结构,远程登录,vi和vim,用户管理,实用指令。定时调度,挂载。)
1.linux的安装 1.先安装virtualmachine15.5 2.再安装Linux(CentOS7.6/centOS8.1) 首先在自己的window电脑上安装虚拟机,然后虚拟机相当于一台电脑 ...
- Linux 用户管理 文件目录指令 时间日期指令 搜索查找类 解压压缩类
目录 用户管理 添加用户: 指定/修改密码 删除用户 查询用户信息指令 切换用户 查看当前用户/登录用户 用户组 修改用户的组 用户和组相关文件 指定运行级别1 指定运行级别2 找回root密码 帮助 ...
- 大数据技术之_01_Linux学习_01_linux的入门+VM和linux的安装+linux的目录结构+远程登录到linux服务器+vi和vim编辑器+开机、重启和用户登录注销+用户管理+用户组管理
大数据学习之_01_Linux学习_01 1 linux的入门 1.1 Linux的介绍 2 VM和linux的安装 2.1 安装vm和Centos 2.1.1 基本说明 2.1.2 CentOS安装 ...
- Windows基本命令操作、网络相关操作、windows用户管理、NTFS权限、更新策略的方法
一.Windows基本命令操作 一.目录与文件应用操作 1.cd 命令 用于改变当前提示符盘符路径或提示符目录路径 CD [/D] [drive:][path] #跨盘符切换必须要跟上 /d 选项 举 ...
- 输入输出管理 用户管理
第四单元 #########管理输入输出######### 正确输出的编号为1,错误输出编号为2,在普通用户下会因为用户权限,出现两种结果(正确输出和报错) find /etc -name passw ...
- 02、文件与用户管理
1.文件与目录管理 1.1文件的分类 普通文件 l 目录文件 d 套接字文件 命名管道 设备文件 b 常见的目录 root 超级管理员目录 tmp 临时文件 etc 配置文件 home 家 ...
最新文章
- JavaScript面向对象及原型 及setTimeout
- FLASH模仿苹果菜单源码.(AS苹果菜单源码)
- 系列笔记 | 深度学习连载(4):优化技巧(上)
- VTK修炼之道81:VTK开发基础_vtkObject类深入分析
- matlab如何使音频文件声音变大_如何制作视频课程
- 大学计算机需要论文吗,大一新生刚开学,是否有必要带电脑?听听辅导员的建议,非常中肯...
- 如何解决IE6双边距问题?
- Java23种设计模式之概念篇
- (53)FPGA面试题-利用任务task实现单字节乘法功能(Verilog语言实现)
- 大数据_Hbase-API访问_Java操作Hbase_判断表是否存在---Hbase工作笔记0012
- HYSBZ(BZOJ) 4300 绝世好题(位运算,递推)
- Android应用快捷方式
- NLP-D23-cs224nkaggle房价预测复习chap5深度学习计算算法R2D7Unicorn
- catic备份mysql,caticbj.com
- 音乐格式怎么转换,音频格式转换的方法
- oracle备份数据库的格式,ORACLE 数据库备份文件的后缀是()。
- 【Nessus安装、使用】
- VC中CTreeView控件的使用
- 隐藏自己是爬虫装作客户爬取豆瓣网
- ARM+FPGA运动控制卡 运动控制卡方案 运动控制卡方案 运动控制卡
热门文章
- nagios部署安装中篇
- oracle client中对 TNSNAMES.ORA的研究
- 服务器系统ghost版 raid,服务器在raid5下做系统ghost备份.docx
- python多个线程join_python-使用`thread.join()`时多线程冻结
- KaliLinuxNetHunter教程刷入第三方Recovery与开始刷机
- XamarinSQLite教程添加测试数据
- Xamarin.Forms使用Slider注意问题
- 计算机四级分数怎么查,计算机三四级成绩查询正确打开方式
- html资源加载,如何加载文件资源 (HTML)
- vue ui无效_vue开发中,父组件添加scoped之后。解决在父组件中无法修改子组件样式问题。...