linux 基础命令(四)

1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其他用户均没有任何访问权限。

[root@localhost home]# cp -r /etc/skel/ /home/tuser1
[root@localhost home]# chmod 700 tuser1/
[root@localhost home]# ll -d tuser1
/drwx------ 2 root root 59 10月 16 18:48 tuser1/

2、编辑/etc/group文件,添加组Hadoop。

[root@localhost home]# tail -1 /etc/grouphadoop:x:1001:

3、手动编辑/etc/passwd文件,增加一行,添加用户Hadoop,其基本组为ID为Hadoop的组ID号,其家目录为/home/hadoop.

[root@localhost home]# cp -r /etc/skel/ /home/hadoop
[root@localhost home]# vim /etc/passwd
[root@localhost home]# tail -1 /etc/passwdhadoop:x:1001:1001::/home/hadoop:/bin/bash
[root@localhost home]# su - hadoop
[hadoop@localhost ~]$ id hadoop
uid=1001(hadoop) gid=1001(hadoop) 组=1001(hadoop)

4、复制/etc/skel目录为/home/hadoop,要求修改Hadoop的目录的属组和其他用户没有任何访问权限。

[root@localhost home]# ll -d /home/hadoop/
drwxr-xr-x 2 root root 59 10月 16 18:54 /home/hadoop/
[root@localhost home]# chown -R hadoop.hadoop /home/hadoop/
[root@localhost home]# chmod -R 700 /home/hadoop/
[root@localhost home]# ll -d /home/hadoop/
drwx------ 2 hadoop hadoop 59 10月 16 18:54 /home/hadoop/

5、修改/home/hadoop目录及其内部所有文件的属主为Hadoop,属组为Hadoop

[root@localhost home]# chown -R hadoop.hadoop /home/hadoop/
[root@localhost home]# ll -a /home/hadoop/
总用量 12
drwx------  2 hadoop hadoop  59 10月 16 18:54 .
drwxr-xr-x. 6 root   root    56 10月 16 18:54 ..
-rwx------  1 hadoop hadoop  18 10月 16 18:54 .bash_logout
-rwx------  1 hadoop hadoop 193 10月 16 18:54 .bash_profile
-rwx------  1 hadoop hadoop 231 10月 16 18:54 .bashrc

6、显示/proc/meminfo文件中以大写或小写s开头的行;用两种方式

[root@localhost home]# egrep "^[Ss]" /proc/meminfo
 SwapCached:            0 kB
 SwapTotal:       2097148 kB
 SwapFree:        2097148 kB
 Shmem:              6836 kB
 Slab:              35932 kB
 SReclaimable:      14572 kB
 SUnreclaim:        21360 kB
 [root@localhost home]# grep -i "^s" /proc/meminfo
  SwapCached:            0 kB
  SwapTotal:       2097148 kB
  SwapFree:        2097148 kB
  Shmem:              6836 kB
  Slab:              35932 kB
  SReclaimable:      14572 kB
  SUnreclaim:        21360 kB

7、显示/etc/passwd文件中其默认登录shell为/sbin/nologin的用户;

[root@localhost home]# cut -d: -f1,7 /etc/passwd | grep "/sbin/nologin"bin:/sbin/nologin
daemon:/sbin/nologin
adm:/sbin/nologin
lp:/sbin/nologin
mail:/sbin/nologin
operator:/sbin/nologin
games:/sbin/nologin
ftp:/sbin/nologin
nobody:/sbin/nologin
avahi-autoipd:/sbin/nologin
systemd-bus-proxy:/sbin/nologin
systemd-network:/sbin/nologin
dbus:/sbin/nologin
polkitd:/sbin/nologin
abrt:/sbin/nologin
tss:/sbin/nologin
postfix:/sbin/nologin
sshd:/sbin/nologin

8、显示/etc/passwd文件中默认登录shell为/bin/bash的用户;

[root@localhost home]# cut -d: -f1,7 /etc/passwd | grep "/bin/bash"
root:/bin/bash
baoman:/bin/bash
hadoop:/bin/bash

9、找出/etc/passwd文件中的一位数两位数;

[root@localhost home]# grep "\<[0-9]\{1,2\}\>" /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin

10、显示/boot/grub/grub.conf中至少一个空白字符开头的行;

[root@localhost grub2]# egrep "^[[:space:]]+" /boot/grub2/grub.cfg

11、显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行;

[root@localhost grub2]# egrep "^#[[:space:]]+[^[:space:]]+" /boot/grub2/grub.cfg
# DO NOT EDIT THIS FILE# It is automatically generated by grub2-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
# Fallback normal timeout code in case the timeout_style feature is# unavailable.
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change# the 'exec tail' line above.

12、打出netstat -ant命令结果中以'LISTEN',后或跟空白字符结尾的行;

[root@localhost grub2]# netstat -tan | grep "\<LISTEN[[:space:]]*"
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN     
tcp6       0      0 ::1:25                  :::*                    LISTEN

13、添加用户bash,testbash,basher,nologin(此一个用户shell为/sbin/nologin),而后找出当前系统上用户名和默认shell相同的用户的信息;

[root@localhost scripts]# grep "^\<\([a-z]\+\)\>.*\1$" /etc/passwd
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
bash:x:1002:1002::/home/bash:/bin/bash
nologin:x:1005:1005::/home/nologin:/sbin/nologin

原创文章,作者:jbm,如若转载,请注明出处:http://www.178linux.com/51989

(0)
jbmjbm
上一篇 2016-10-16
下一篇 2016-10-16

相关推荐

  • 压缩、解压缩和归档工具

    1  compress和uncompress 用法:     compress [-dfvcVr] [-b maxbits] [file…] 选项:     -d   解压缩     -c   结果…

    Linux干货 2016-08-18
  • 一键搭建mysql集群系列一

    一键自动安装mysql 5.7 shell脚本自动化安装二进制mysql-5.7 本节主要用到四个shell脚本 和 一台资料存储机器(IP:192.168.42.26) install_mysql.sh 自动化安装mysql脚本 ntpdate.sh 时间同步脚本 system_init.sh 系统初始化脚本 yum.sh yum源配置脚本 执行步骤: 1…

    2017-05-13
  • 开始学习总结的一些基本知识点

       第一VNC软件(面授班课堂用的),这款软件采用C/S架构(client/sever客户端和服务器端)还有VNC协议(virtual Network computing虚拟网络计算)协议。虽说这款软件对网络班没有实际用途,但自己了解下这款软件的构成也是不错的。    第二开始学习需要的虚拟机软件其中包括VMWARE…

    Linux干货 2016-10-29
  • Linux Kernel

    Linux Kernel 概述:文章将主要介绍Linux 内核的相关信息,包括内核各组成部分的详细介绍,其中有内核信息的获取命令,uname;内核模块管理类命令:lsmod,modinfo,modprobe,insomd,rmmod;ramdisk生成的相关命令,mkinitrd和dracut命令;以及linux中的两个为文件系统 /proc和/sys。最后…

    Linux干货 2016-09-19
  • 关于shell脚本编程基础第三篇

                          关于shell脚本编程基础第三篇   本章主要内容:循环的特殊用法;while;for;select 循环与菜单       &nbsp…

    系统运维 2016-08-21
  • DHCP及自动化安装Linux

    主机IP配置: 静态指定 静态IP 动态获取: bootp:bootprotocol MAC与IP一一静态对应 DHCP: Dynamic Host Configuration Protocol 动态主机配置协议基于UTP协议 主要用途:自动化分配IP地址,实现集中管理,解决IP地址不足的问题。 DHCP的4种报文 DHCP DISCOVER OFFER R…

    2017-09-18

评论列表(1条)

  • 马哥教育
    马哥教育 2016-10-20 19:38

    很不错,学有余力的话,可以把一些题目换个正则表达式来完成,加油。