显示/etc 目录下,以非字母开头,后面跟了一个字母以及其它任意长度任意字符的文件或目录。
[root@localhost ~]# ls /etc/ abrt chromium ethertypes gss libblockdev networks profile.d scl target adjtime chrony.conf exports gssproxy libibverbs.d nfs.conf protocols securetty tcsd.conf aliases chrony.keys exports.d host.conf libnl nfsmount.conf pulse security terminfo aliases.db cifs-utils favicon.png hostname libpaper.d nsswitch.conf purple selinux tmpfiles.d alsa cron.d fcoe hosts libreport nsswitch.conf.bak python services trusted-key.key alternatives cron.daily festival hosts.allow libuser.conf ntp qemu-ga sestatus.conf tuned anacrontab cron.deny filesystems hosts.deny libvirt ntp.conf qemu-kvm setroubleshoot udev asound.conf cron.hourly firefox hp locale.conf numad.conf radvd.conf setuptool.d udisks2 at.deny cron.monthly firewalld idmapd.conf localtime oddjob rc0.d sgml unbound audisp crontab flatpak init.d login.defs oddjobd.conf rc1.d shadow updatedb.conf audit cron.weekly fonts inittab logrotate.conf oddjobd.conf.d rc2.d shadow- UPower autofs.conf crypttab fprintd.conf inputrc logrotate.d openldap rc3.d shells usb_modeswitch.conf autofs_ldap_auth.conf csh.cshrc fstab ipa lsm opt rc4.d skel vconsole.conf auto.master csh.login fuse.conf iproute2 lvm os-release rc5.d smartmontools vimrc auto.master.d cups fwupd ipsec.conf machine-id PackageKit rc6.d sos.conf virc auto.misc cupshelpers gconf ipsec.d magic pam.d rc.d speech-dispatcher vmware-tools auto.net dbus-1 gcrypt ipsec.secrets mail.rc papersize rc.local ssh wgetrc auto.smb dconf gdbinit iscsi makedumpfile.conf.sample passwd rdma ssl wpa_supplicant avahi default gdbinit.d issue man_db.conf passwd- redhat-release sssd wvdial.conf bash_completion.d depmod.d gdm issue.net maven pbm2ppa.conf request-key.conf statetab X11 bashrc dhcp geoclue issue.out mke2fs.conf pinforc request-key.d statetab.d xdg binfmt.d DIR_COLORS GeoIP.conf java modprobe.d pkcs11 resolv.conf subgid xinetd.d bluetooth DIR_COLORS.256color ghostscript jvm modules-load.d pki resolv.conf.save subuid xml brltty DIR_COLORS.lightbgcolor glvnd jvm-commmon motd plymouth rpc sudo.conf yum brltty.conf dleyna-server-service.conf gnupg kdump.conf mtab pm rpm sudoers yum.conf centos-release dnsmasq.conf GREP_COLORS kernel mtools.conf pnm2ppa.conf rsyncd.conf sudoers.d yum.repos.d centos-release-upstream dnsmasq.d groff krb5.conf multipath polkit-1 rsyslog.conf sudo-ldap.conf certmonger dracut.conf group krb5.conf.d my.cnf popt.d rsyslog.d sysconfig cgconfig.conf dracut.conf.d group- ksmtuned.conf my.cnf.d postfix rwtab sysctl.conf cgconfig.d e2fsck.conf grub2.cfg ld.so.cache nanorc ppp rwtab.d sysctl.d cgrules.conf egl grub.d ld.so.conf ndctl prelink.conf.d samba systemd cgsnapshot_blacklist.conf enscript.cfg gshadow ld.so.conf.d netconfig printcap sane.d system-release chkconfig.d environment gshadow- libaudit.conf NetworkManager profile sasl2 system-release-cpe [root@localhost ~]# touch /etc/1a232123sdf [root@localhost ~]# mkdir /etc/2c3234 [root@localhost ~]# mkdir /etc/2bsdfs2342342323 [root@localhost ~]# ls -d /etc/[^[:alpha:]][:alpha:]* /etc/1a232123sdf [root@localhost ~]# ls -a /etc/[^[:alpha:]][[:alpha:]]* /etc/1a232123sdf /etc/2bsdfs2342342323: . .. /etc/2c3234: . .. [root@localhost ~]# ls /etc/ 1a232123sdf cgrules.conf egl grub.d ld.so.conf ndctl prelink.conf.d samba systemd 2bsdfs2342342323 cgsnapshot_blacklist.conf enscript.cfg gshadow ld.so.conf.d netconfig printcap sane.d system-release 2c3234 chkconfig.d environment gshadow- libaudit.conf NetworkManager profile sasl2 system-release-cpe abrt chromium ethertypes gss libblockdev networks profile.d scl target adjtime chrony.conf exports gssproxy libibverbs.d nfs.conf protocols securetty tcsd.conf aliases chrony.keys exports.d host.conf libnl nfsmount.conf pulse security terminfo aliases.db cifs-utils favicon.png hostname libpaper.d nsswitch.conf purple selinux tmpfiles.d alsa cron.d fcoe hosts libreport nsswitch.conf.bak python services trusted-key.key alternatives cron.daily festival hosts.allow libuser.conf ntp qemu-ga sestatus.conf tuned anacrontab cron.deny filesystems hosts.deny libvirt ntp.conf qemu-kvm setroubleshoot udev asound.conf cron.hourly firefox hp locale.conf numad.conf radvd.conf setuptool.d udisks2 at.deny cron.monthly firewalld idmapd.conf localtime oddjob rc0.d sgml unbound audisp crontab flatpak init.d login.defs oddjobd.conf rc1.d shadow updatedb.conf audit cron.weekly fonts inittab logrotate.conf oddjobd.conf.d rc2.d shadow- UPower autofs.conf crypttab fprintd.conf inputrc logrotate.d openldap rc3.d shells usb_modeswitch.conf autofs_ldap_auth.conf csh.cshrc fstab ipa lsm opt rc4.d skel vconsole.conf auto.master csh.login fuse.conf iproute2 lvm os-release rc5.d smartmontools vimrc auto.master.d cups fwupd ipsec.conf machine-id PackageKit rc6.d sos.conf virc auto.misc cupshelpers gconf ipsec.d magic pam.d rc.d speech-dispatcher vmware-tools auto.net dbus-1 gcrypt ipsec.secrets mail.rc papersize rc.local ssh wgetrc auto.smb dconf gdbinit iscsi makedumpfile.conf.sample passwd rdma ssl wpa_supplicant avahi default gdbinit.d issue man_db.conf passwd- redhat-release sssd wvdial.conf bash_completion.d depmod.d gdm issue.net maven pbm2ppa.conf request-key.conf statetab X11 bashrc dhcp geoclue issue.out mke2fs.conf pinforc request-key.d statetab.d xdg binfmt.d DIR_COLORS GeoIP.conf java modprobe.d pkcs11 resolv.conf subgid xinetd.d bluetooth DIR_COLORS.256color ghostscript jvm modules-load.d pki resolv.conf.save subuid xml brltty DIR_COLORS.lightbgcolor glvnd jvm-commmon motd plymouth rpc sudo.conf yum brltty.conf dleyna-server-service.conf gnupg kdump.conf mtab pm rpm sudoers yum.conf centos-release dnsmasq.conf GREP_COLORS kernel mtools.conf pnm2ppa.conf rsyncd.conf sudoers.d yum.repos.d centos-release-upstream dnsmasq.d groff krb5.conf multipath polkit-1 rsyslog.conf sudo-ldap.conf certmonger dracut.conf group krb5.conf.d my.cnf popt.d rsyslog.d sysconfig cgconfig.conf dracut.conf.d group- ksmtuned.conf my.cnf.d postfix rwtab sysctl.conf cgconfig.d e2fsck.conf grub2.cfg ld.so.cache nanorc ppp rwtab.d sysctl.d [root@localhost ~]#
复制/etc 目录下所有以p开头,以非数字结尾的文件或目录到/tmp/mytest1目录中。
[root@localhost ~]# mkdir /tmp/mytest{1..3} [root@localhost ~]# cp -a /etc/p*[^[:digit:]] /tmp/mytest1/ [root@localhost ~]# ls /tmp/mytest1 pam.d passwd pbm2ppa.conf pki pm popt.d ppp printcap profile.d pulse python papersize passwd- pinforc plymouth pnm2ppa.conf postfix prelink.conf.d profile protocols purple [root@localhost ~]# cp -a /etc/p*[^0-9] /tmp/mytest2/ [root@localhost ~]# ls /tmp/mytest2 pam.d passwd pbm2ppa.conf pki pm popt.d ppp printcap profile.d pulse python papersize passwd- pinforc plymouth pnm2ppa.conf postfix prelink.conf.d profile protocols purple [root@localhost ~]# cp -a /etc/p*[a-Z] /tmp/mytest3/ [root@localhost ~]# ls /tmp/mytest3 pam.d papersize passwd pbm2ppa.conf pinforc pki plymouth pm pnm2ppa.conf popt.d postfix ppp prelink.conf.d printcap profile profile.d protocols pulse purple python 这种是不正确的方式,与题目不太相符。
将/etc/issue文件中的内容转换为大写后保存至/tmp/issue.out 文件中。
[root@localhost ~]# cat /etc/issue \S Kernel \r on an \m [root@localhost ~]# tr [:lower:] [:upper:] < /etc/issue > /etc/issue.out [root@localhost ~]# [root@localhost ~]# cat /etc/issue.out \S KERNEL \R ON AN \M [root@localhost ~]# cat /etc/issue \S Kernel \r on an \m [root@localhost ~]#
[root@localhost abc]# cat /etc/issue | tr 'a-z' 'A-Z' > /etc/issue.out [root@localhost abc]# cat /etc/issue \S Kernel \r on an \m [root@localhost abc]# [root@localhost abc]# cat /etc/issue.out \S KERNEL \R ON AN \M
总结描述用户和组管理类命令的使用方法并完成一下练习。
创建组 distro ,其GID为 2019 ;
[root@localhost abc]# getent group distro [root@localhost abc]# groupadd distro -g 2019 [root@localhost abc]# getent group distro distro:x:2019: [root@localhost abc]#
创建用户 mandriva ,其ID号为 1005 ,基本组为 distro ;
[root@localhost abc]# useradd mandriva -u 1005 -g distro [root@localhost abc]# id mandriva uid=1005(mandriva) gid=2019(distro) groups=2019(distro) [root@localhost abc]#
创建用户 mageia ,其ID号为 1100,家目录为 /home/linux ;
[root@localhost abc]# useradd mageia -u 1100 -d /home/linux -m [root@localhost abc]# ls /home/ edward linux mandriva [root@localhost abc]# id mageia uid=1100(mageia) gid=1100(mageia) groups=1100(mageia) [root@localhost abc]# getent passwd mageia mageia:x:1100:1100::/home/linux:/bin/bash [root@localhost abc]#
给用户mageia 添加密码,密码为 mageedu ,并设置用户密码7天后过期;
[root@localhost abc]# echo mageia:mageedu | chpasswd [root@localhost abc]# chage -l mageia Last password change : May 03, 2020 Password expires : never Password inactive : never Account expires : never Minimum number of days between password change : 0 Maximum number of days between password change : 99999 Number of days of warning before password expires : 7 [root@localhost abc]# chage -M 7 mageia [root@localhost abc]# chage -l mageia Last password change : May 03, 2020 Password expires : May 10, 2020 Password inactive : never Account expires : never Minimum number of days between password change : 0 Maximum number of days between password change : 7 Number of days of warning before password expires : 7 [root@localhost abc]# date -s '10 day' Thu May 14 05:46:44 CST 2020 [root@localhost abc]# su - edward Last login: Mon May 4 05:44:36 CST 2020 on pts/1 [edward@localhost ~]$ su - mageia Password: You are required to change your password immediately (password aged) Changing password for mageia. (current) UNIX password: New password: Retype new password: Last login: Thu May 14 05:46:52 CST 2020 on pts/1 Last failed login: Thu May 14 05:47:44 CST 2020 on pts/1 There was 1 failed login attempt since the last successful login. [mageia@localhost ~]$ id uid=1100(mageia) gid=1100(mageia) groups=1100(mageia)
删除 mandriva ,但保留其家目录;
[root@localhost abc]# userdel mandriva [root@localhost abc]# ls /home/mandriva/ test [root@localhost abc]# ls /home/ edward linux mandriva slackware test1 test2 test3 test4 [root@localhost abc]#
创建用户 slackware ,其ID号为 2002 ,基本组为 distro ,附加组 peguin ;
[root@localhost abc]# groupadd peguin [root@localhost abc]# useradd slackware -u 2002 -g distro -G peguin [root@localhost abc]# id slackware uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin) [root@localhost abc]#
修改 slackware 的默认shell为 /bin/tcsh ;
[root@localhost abc]# clear [root@localhost abc]# getent passwd slackware slackware:x:2002:2019:slackware name,depops,123,456:/home/slackware:/bin/bash [root@localhost abc]# chsh -s /bin/tcsh slackware Changing shell for slackware. Shell changed. [root@localhost abc]# getent passwd slackware slackware:x:2002:2019:slackware name,depops,123,456:/home/slackware:/bin/tcsh [root@localhost abc]# chsh -s /bin/bash slackware Changing shell for slackware. Shell changed. [root@localhost abc]# getent passwd slackware slackware:x:2002:2019:slackware name,depops,123,456:/home/slackware:/bin/bash [root@localhost abc]# usermod -s /bin/tcsh slackware [root@localhost abc]# getent passwd slackware slackware:x:2002:2019:slackware name,depops,123,456:/home/slackware:/bin/tcsh [root@localhost abc]#
为用户 slackware 新增附加组 admins;
[root@localhost abc]# id slackware uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin) [root@localhost abc]# groupadd admins [root@localhost abc]# usermod -aG admins slackware [root@localhost abc]# id slackware uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin),2021(admins)
命令随笔:
[root@localhost abc]# hostname |tr 'a-z' 'A-Z' LOCALHOST.LOCALDOMAIN [root@localhost abc]# hos |tr 'a-z' 'A-Z' bash: hos: command not found... [root@localhost abc]# hos 2>&1 |tr 'a-z' 'A-Z' BASH: HOS: COMMAND NOT FOUND... [root@localhost abc]# hos |& tr 'a-z' 'A-Z' BASH: HOS: COMMAND NOT FOUND... [root@localhost abc]#
[root@localhost abc]# echo magedu | passwd --stdin edward Changing password for user edward. passwd: all authentication tokens updated successfully. [root@localhost abc]# echo magedu | passwd --stdin edward > /dev/null
[root@localhost abc]# cat edward.file cat: edward.file: No such file or directory [root@localhost abc]# cat edward.file > test1.log 2> test2.log [root@localhost abc]# ls test1.log test2.log [root@localhost abc]# cat test1.log [root@localhost abc]# cat test2.log cat: edward.file: No such file or directory [root@localhost abc]# [root@localhost abc]# cat edward.file &> test3.log [root@localhost abc]# cat test3.log cat: edward.file: No such file or directory [root@localhost abc]# cat edward.file > test4.log 2>&1 [root@localhost abc]# cat test4.log cat: edward.file: No such file or directory
[root@localhost abc]# hostname | tee /tmp/abc/test1 localhost.localdomain [root@localhost abc]# cat test1 localhost.localdomain [root@localhost abc]# [root@localhost abc]# uname -r | tee /tmp/abc/test1 3.10.0-1062.el7.x86_64 [root@localhost abc]# cat test1 3.10.0-1062.el7.x86_64 [root@localhost abc]# [root@localhost abc]# hostname | tee -a /tmp/abc/test1 localhost.localdomain [root@localhost abc]# [root@localhost abc]# cat test1 3.10.0-1062.el7.x86_64 localhost.localdomain [root@localhost abc]# [root@localhost abc]# [root@localhost abc]# hostname | tee -a /tmp/abc/test1 |tr 'a-z' 'A-Z' LOCALHOST.LOCALDOMAIN [root@localhost abc]# cat test1 3.10.0-1062.el7.x86_64 localhost.localdomain localhost.localdomain
[root@localhost abc]# su - edward [edward@localhost ~]$ mail -s help root <I am $USER . please help me. > `cat /etc/issue` > EOF [edward@localhost ~]$ exit logout [root@localhost abc]# mail Heirloom Mail version 12.5 7/5/10. Type ? for help. "/var/spool/mail/root": 1 message 1 new >N 1 edward Mon May 4 02:26 20/662 "help" & 1 Message 1: From edward@localhost.localdomain Mon May 4 02:26:14 2020 Return-Path: X-Original-To: root Delivered-To: root@localhost.localdomain Date: Mon, 04 May 2020 02:26:14 +0800 To: root@localhost.localdomain Subject: help User-Agent: Heirloom mailx 12.5 7/5/10 Content-Type: text/plain; charset=us-ascii From: edward@localhost.localdomain (edward) Status: R I am edward . please help me. \S Kernel \r on an \m &
[root@localhost abc]# echo {1..100} 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 [root@localhost abc]# echo {1..100} | tr ' ' '+' 1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21+22+23+24+25+26+27+28+29+30+31+32+33+34+35+36+37+38+39+40+41+42+43+44+45+46+47+48+49+50+51+52+53+54+55+56+57+58+59+60+61+62+63+64+65+66+67+68+69+70+71+72+73+74+75+76+77+78+79+80+81+82+83+84+85+86+87+88+89+90+91+92+93+94+95+96+97+98+99+100 [root@localhost abc]# echo {1..100} | tr ' ' '+' |bc 5050 [root@localhost abc]#
[root@localhost abc]# seq -s+ 1 100 1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21+22+23+24+25+26+27+28+29+30+31+32+33+34+35+36+37+38+39+40+41+42+43+44+45+46+47+48+49+50+51+52+53+54+55+56+57+58+59+60+61+62+63+64+65+66+67+68+69+70+71+72+73+74+75+76+77+78+79+80+81+82+83+84+85+86+87+88+89+90+91+92+93+94+95+96+97+98+99+100 [root@localhost abc]# seq -s + 1 100 1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21+22+23+24+25+26+27+28+29+30+31+32+33+34+35+36+37+38+39+40+41+42+43+44+45+46+47+48+49+50+51+52+53+54+55+56+57+58+59+60+61+62+63+64+65+66+67+68+69+70+71+72+73+74+75+76+77+78+79+80+81+82+83+84+85+86+87+88+89+90+91+92+93+94+95+96+97+98+99+100 [root@localhost abc]# seq -s + 1 100 |bc 5050 [root@localhost abc]#
[root@localhost abc]# date Mon May 4 03:13:31 CST 2020 [root@localhost abc]# date +%s 1588533215 [root@localhost abc]# echo `date +%s`/86400 | bc 18385 [root@localhost abc]# echo `date +%s`/86400/365 | bc 50 [root@localhost abc]#
[root@localhost abc]# openssl rand -base64 9 oxmVEgg0TvhU [root@localhost abc]# mkpasswd lcqdWF92+ [root@localhost abc]# yum install expect [root@localhost abc]# mkpasswd -l 15 -d 3 -C 5 g82ZzI5pVq=EMud [root@localhost abc]#
[root@localhost abc]# pwck user 'ftp': directory '/var/ftp' does not exist user 'gluster': directory '/run/gluster' does not exist user 'saslauth': directory '/run/saslauthd' does not exist user 'pulse': directory '/var/run/pulse' does not exist user 'gnome-initial-setup': directory '/run/gnome-initial-setup/' does not exist pwck: no changes [root@localhost abc]# getent passwd edward edward:x:1000:1000:edward:/home/edward:/bin/bash [root@localhost abc]# getent group edward edward:x:1000:edward [root@localhost abc]# getent group edward root edward:x:1000:edward root:x:0: [root@localhost abc]# [root@localhost abc]# grpck [root@localhost abc]# vipw vipw: /etc/passwd is unchanged [root@localhost abc]# vigr vigr: /etc/group is unchanged [root@localhost abc]#
[root@localhost abc]# yum install finger -y [root@localhost abc]# finger slackware Login: slackware Name: Directory: /home/slackware Shell: /bin/bash Never logged in. No mail. No Plan. [root@localhost abc]# chfn slackware Changing finger information for slackware. Name []: slackware name Office []: depops Office Phone []: 123 Home Phone []: 456 Finger information changed. [root@localhost abc]# finger slackware Login: slackware Name: slackware name Directory: /home/slackware Shell: /bin/bash Office: depops, 123 Home Phone: 456 Never logged in. No mail. No Plan. [root@localhost abc]#
在一台机器上新建了 test1、test2、test3等用户,需要在其他机器上,也批量创建这些用户,则,需要将 /etc/passwd 里,相关用户信息复制出来,在其他机器上使用: [root@localhost abc]# cat test.user test1:x:2003:2003::/home/test1:/bin/bash test2:x:2004:2004::/home/test2:/bin/bash test3:x:2005:2005::/home/test3:/bin/bash [root@localhost abc]# newusers test.user [root@localhost abc]# ls /home/ edward linux mandriva slackware test1 test2 test3
[root@localhost abc]# cat test.pass test1:1234 test2:5678 test3:abc123 [root@localhost abc]# cat test.pass | chpasswd 批量修改密码