N25第四周总结

linux bassic Week 4 Blogging

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

~]# cp -r /etc/skel/   /home/tuser1/
~]# chmod -R g-rwx,o-rwx /home/tuser1/
~]# ls -la /home/tuser1/
total 28
d---------. 4 root root 4096 Dec 20 10:56 .
drwxr-xr-x. 6 root root 4096 Dec 20 10:19 .. 注意此文件位当前目录上一级目录
----------. 1 root root   18 Dec 20 10:19 .bash_logout
----------. 1 root root  176 Dec 20 10:19 .bash_profile
----------. 1 root root  124 Dec 20 10:19 .bashrc
d---------. 2 root root 4096 Dec 20 10:19 .gnome2
drwx------. 3 root root 4096 Dec 20 10:56 skel

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

~]# vim /etc/group
distro:x:5000:
peguin:x:5001:
gentoo:x:3002:
fedora:x:3003:
mageedu:x:5010:gentoo,fedora
fed:x:3004:
gentoo1:x:3005:
gentoo2:x:3006:
hadoop:x:3008:  编辑添加,G-->o在尾行添加

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

~]# vim /etc/passwd
gentoo1:x:3005:3005::/users/gentoo1:/bin/bash
gentoo2:x:3006:3006::/users/gentoo:/bin/bash
gen:x:3007:3007::/users/gen:/bin/bash
hadoop:x:3008:3008::/home/hadoop:/bin/bash

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

~]# cp -r /etc/skel/ /home/hadoop
~]# chmod g-rwx,o-rwx /home/hadoop/
 ~]# ls -la /home/hadoop/
total 24
drwx------. 3 root root 4096 Dec 20 11:10 .
drwxr-xr-x. 7 root root 4096 Dec 20 11:10 ..
-rw-r--r--. 1 root root   18 Dec 20 11:10 .bash_logout
-rw-r--r--. 1 root root  176 Dec 20 11:10 .bash_profile
-rw-r--r--. 1 root root  124 Dec 20 11:10 .bashrc
drwxr-xr-x. 2 root root 4096 Dec 20 11:10 .gnome2

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

~]# chown -R  hadoop:hadoop /home/hadoop/
~]# ls -la /home/hadoop/
total 24
drwx------. 3 hadoop hadoop 4096 Dec 20 11:10 .
drwxr-xr-x. 7 root   root   4096 Dec 20 11:10 .. 当前目录的上一级目录
-rw-r--r--. 1 hadoop hadoop   18 Dec 20 11:10 .bash_logout
-rw-r--r--. 1 hadoop hadoop  176 Dec 20 11:10 .bash_profile
-rw-r--r--. 1 hadoop hadoop  124 Dec 20 11:10 .bashrc
drwxr-xr-x. 2 hadoop hadoop 4096 Dec 20 11:10 .gnome2

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

~]# grep "^[sS]" /proc/meminfo 
SwapCached:            0 kB
SwapTotal:       1048572 kB
SwapFree:        1048572 kB
Shmem:               232 kB
Slab:              66492 kB
SReclaimable:      11380 kB
SUnreclaim:        55112 kB
~]# grep "^(s|S)" /proc/meminfo  第二种方法
 ~]# grep -i "^s" /proc/meminfo  第三种方法

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

~]# grep -v "/sbin/nologin$" /etc/passwd
root:x:0:0:root:/root:/bin/bash
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
openstack:x:3000:3000::/home/openstack:/bin/bash
archinux:x:3001:3001::/home/archinux:/bin/bash
gentoo:x:3002:3002::/users/gentoo:/bin/bash
fedora:x:3003:3003::/users/fedora:/bin/bash
fed:x:3004:3004::/users/fed:/bin/bash
gentoo1:x:3005:3005::/users/gentoo1:/bin/bash
gentoo2:x:3006:3006::/users/gentoo:/bin/bash
gen:x:3007:3007::/users/gen:/bin/bash
hadoop:x:3008:3008::/home/hadoop:/bin/bash
~]# grep -v "/sbin/nologin$" /etc/passwd | cut -d: -f1
root
sync
shutdown
halt
openstack
archinux
gentoo
fedora
fed
gentoo1
gentoo2
gen
hadoop

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

 ~]# grep "/bin/bash" /etc/passwd | cut -d: -f1rootopenstackarchinuxgentoofedorafedgentoo1gentoo2genhadoop

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

~]# grep -o "[0-9][0-9]\>" /etc/passwd   这是是错误的,默认工作在贪婪模式包含里面数字都匹配
12
10
14
11
12
00
13
30
14
50
99
99
81
81
69
69
73
73
68
68
38
38
99
76
89
89
74
74
72
72
00
00
01
01
02
02
03
03
04
04
05
~]# grep -E -o "\<[0-9]{1,2}\>" /etc/passwd 必须锚定词首词尾

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

~]# grep -E "^[[:space:]]+" /boot/grub/grub.conf 
~]# grep -E "^[[:space:]]+" /boot/grub/grub.conf 
root (hd0,0)
kernel /vmlinuz-2.6.32-504.el6.x86_64 ro root=UUID=cae1b7e9-d579-46d0-9723-51391a99e07f rd_NO_LUKS  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet
initrd /initramfs-2.6.32-504.el6.x86_64.img

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

~]# grep -E -o "^[[:space:]]+" /boot/grub/grub.conf 		
[root@mytest6 ~]# grep -E "^#[[:space:]]+[^[:space:]]" /etc/rc.d/rc.sysinit 
# /etc/rc.d/rc.sysinit - run once at boot time
# Taken in part from Miquel van Smoorenburg's bcheckrc.
# Check SELinux status
# Print a text banner.
# Only read this once.
# Initialize hardware
# Set default affinity
# Load other user-defined modules
# Load modules (for backward compatibility with VARs)
# Configure kernel parameters
# Set the hostname.
......

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

~]# netstat -tan | grep  "LISTEN[[:space:]]*$"
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      
tcp        0      0 :::22                       :::*                        LISTEN

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

 ~]# grep -E -o  "^([^:]+\>).*\1$" /etc/passwd

原创文章,作者:让优秀称为一种习惯,如若转载,请注明出处:http://www.178linux.com/64713

(0)
上一篇 2016-12-26 08:36
下一篇 2016-12-26 10:11

相关推荐

  • MySQL常用命令

    本文大纲 MySQL命令             (0%) 交互式CLI工具     服务端命令 mysqld服务器程序 数据类型 DDL语句                 &n…

    Linux干货 2017-02-16
  • 单台主机lnmp+wordpress配置示例

    单台主机lnmp+wordpress fpm配置 ]# yum install php php-fpm php-mysql –y ]# vim /etc/php-fpm.d/www.conf 配置服务监听地址和程序运行者身份 listen = 127.0.0.1:9000 user = nginx group = nginx ]# chown -R ngin…

    Linux干货 2016-11-07
  • 在VMware workstations中安装CentOS-7-x86_64-Everything-1611.ISO

      对于最近在Linux学习的过程中,许多同学对CentOS系统的详细配置还不熟悉,于是我编写此详细步骤供大家参考。 工具: VMware workstations; CentOS-7-x86_64-Everything-1611.iso; 准备工作:  1、先要下载一个系统镜像centOS-7-x86_64-Everythin…

    2017-07-11
  • Linux磁盘管理(分区,格式化,文件系统、VFS、mount、fstab)

    Linux系统中数据存储在磁盘中,磁盘在冯诺依曼体系中属于输入输出外部存储对象,保存着重要的企业数据,对Linux系统中的磁盘管理尤其需要熟练掌握,由于企业目前使用的主流存储设备还是硬盘,所以这里只叙述硬盘的组织结构; 1.分区:    (1)低级格式化:       硬盘在出厂的时候厂家会做一次分区格式化,…

    Linux干货 2016-09-02
  • Select、Case

    select循环与菜单 select循环主要用于创建菜单,按数字排序list指定的顺序排序,并列出在标准输出,利用PS3列出提示符进行输入选择 用法: select VARIABLE in list  do     循环体命令 done PS3提示语定义: 在脚本中脚本代码的第一…

    Linux干货 2016-08-21
  • Linux系统的软链接和硬链接

    Linux的链接是一种共享文件和访问它的用户的若干目录项之间建立联系的一种方法。一共分为两种链接,分别是软链接和硬链接。 一、硬链接 1、硬链接的本质上是一个文件,它们除了名字不一样,其他都一样,占用的空间是一个。硬链接会增加文件的链接数。如下图 (1)建立硬链集之前     (2)建立硬链接之后 2、删去一个链接名,链接数减一…

    Linux干货 2016-10-22

评论列表(1条)

  • 马哥教育
    马哥教育 2017-01-03 17:04

    掌握的不错,相信正则表达式会对你今后的工作起到很大的益处。