1.file1文件的内容为:”1 2 3 4 5 6 7 8 9 10” 计算出所有数字的总和
[[email protected] ~]# echo "1 2 3 4 5 6 7 8 9 10" >file1 [[email protected] ~]# cat file1 | tr ‘ ‘ ‘+‘ | bc 55
2.处理字符串“xt.,l 1 jr#!$mn2 c*/fe3 uz4”,只保留其中的数字和空格
[[email protected] ~]# echo "xt,. 1 jr#trmn2 c*/fe3 uz4" >file2 [[email protected] ~]# cat file2 | tr -d [[:alpha:]][[:punct:]] 1 2 3 4
3.将PATH变量每个目录显示在独立的一行
[[email protected] ~]# echo $PATH /usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin [[email protected] ~]# echo $PATH | tr ‘:‘ ‘\n‘ /usr/lib64/qt-3.3/bin /usr/local/sbin /usr/local/bin /sbin /bin /usr/sbin /usr/bin /root/bin
4.删除指定文件的空行
[[email protected] ~]# nano f12 [[email protected] ~]# tr -s ‘\n‘ < f12 shulei 123124 21312312 21312321
5.将文件中每个单词(字母)显示在独立的一行,并无空行
[[email protected] ~]# tr ‘ ‘ ‘\n‘ < /etc/issue | tr -s ‘\n‘ CentOS release 6.8 (Final) Kernel \r on an \m The system \n \l \t
6.创建用户gentoo,附加组为bin和root,默认shell为/bin/csh,注释信息为"Gentoo Distribution"
创建下面的用户、组和组成员关系
名字为admins 的组
用户natasha,使用admins 作为附属组
用户harry,也使用admins 作为附属组
用户sarah,不可交互登录系统,且不是admins 的成员,natasha,harry,sarah密码都是centos
[[email protected] ~]# useradd -G bin,root -s /bin/csh -c "Gentoo Distribution" gento [[email protected] ~]# getent passwd gentoo gentoo:x:501:501:Gentoo D:/home/gentoo:/bin/csh [[email protected] ~]# groups gentoo gentoo : gentoo root bin [[email protected] ~]# useradd -G admins natasha [[email protected] ~]# useradd -G admins harry [[email protected] ~]# useradd -s /sbin/nologin sarah [[email protected] ~]# echo ‘centos‘ | passwd --stdin natasha Changing password for user natasha. passwd: all authentication tokens updated successfully. [[email protected] ~]# echo ‘centos‘ | passwd --stdin harry Changing password for user harry. passwd: all authentication tokens updated successfully. [[email protected] ~]# echo ‘centos‘ | passwd --stdin sarah Changing password for user sarah. passwd: all authentication tokens updated successfully.
时间: 2024-11-06 10:05:37