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)
上一篇 2016-10-16 11:51
下一篇 2016-10-16 13:06

相关推荐

  • 关于大型网站技术演进的思考(十四)–网站静态化处理—前后端分离—上(6)

    原文出处: 夏天的森林    前文讲到了CSI技术,这就说明网站静态化技术的讲述已经推进到了浏览器端了即真正到了web前端的范畴了,而时下web前端技术的前沿之一就是前后端 分离技术了,那么在这里网站静态化技术和前后端分离技术产生了交集,所以今天我将讨论下前后端分离技术,前后端分离技术讨论完后,下一篇文章我将会以网站 静态化技术…

    Linux干货 2015-03-11
  • while until 循环用法和 case 条件base编程

    写一个脚本: (1)能接受四个参数:start、stop、restart、status 输入start输出starting,脚本名为finished (2)其它任意参数均报错退出 #!bin/bash #author:jian #date:2017-11-12 #discription: read -p “please input a strin…

    Linux干货 2017-11-14
  • shell脚本编程初步入门

    shell脚本编程初步入门    说到shell脚本编程,那我们就来先看下shell,shell既是一种命令语言,又是一种程序设计语言。作为命令语言,它交互式地解释和执行用户输入的命令;作为程序设计语言,它定义了各种变量和参数,并提供了许多在高级语言中才具有的控制结构,包括循环和分支。它虽然不是Linux系统内核的一部分,但它调用了系统核…

    Linux干货 2016-08-15
  • Linux systemd管理

                                                      &nbsp…

    系统运维 2016-09-28
  • 最简单的Linux系统——更加深入了解Linux启动过程

    自制一个最简单的Linux: 1、有一个新的磁盘,并创建分区 2、挂载分区,创建目录 3、拷贝内核文件 4、创建MBR和grub.conf文件 5、创建/etc/fstab文件,设置开机自动挂载 6、拷贝一个bash程序 7、卸载分区,以新磁盘重启系统

    Linux干货 2016-09-11
  • N26-博客作业-week5

    1、显示当前系统上root、fedora或user1用户的默认shell; ~]# grep -E “^((root|fedora|user1)\>)” /etc/passwd | cut -d: -f7 2、找出/etc/rc.d/init.d/functions文件中某单词后面跟一组小括号的行,形如:hello(); ~]#…

    Linux干货 2017-03-05

评论列表(1条)

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

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