linux常见命令示例

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

#############################################################################

cp -ar /etc/skel/ /home/tuser1

[root@localhost ~]# chmod -R 700 /home/tuser1

[root@localhost ~]# ll -a /home/tuser1

总用量 12

drwx——. 2 root root 62 11月 14 01:29 .

drwxr-xr-x. 14 root root 176 12月 22 20:15 ..

-rwx——. 1 root root 18 8月 3 05:11 .bash_logout

-rwx——. 1 root root 193 8月 3 05:11 .bash_profile

-rwx——. 1 root root 231 8月 3 05:11 .bashrc

[root@localhost ~]#

#############################################################################

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

#############################################################################

vim /etc/group

hadoop:x:2020:

“/etc/group” 54L, 735C 已写入

[root@localhost ~]# useradd -g hadoop test2

[root@localhost ~]# id test2

uid=2003(test2) gid=2020(hadoop) 组=2020(hadoop)

#############################################################################

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

#############################################################################

vim /etc/passwd

hadoop:x:2020:2020::/home/hadoop:/bin/bash

[root@localhost ~]# rm -rf /home/hadoop

[root@localhost ~]# cp -ar /etc/skel/ /home/hadoop

[root@localhost ~]# chmod -R 700 /home/hadoop

[root@localhost ~]# chown -R hadoop:hadoop /home/hadoop

[root@localhost ~]# ll -a /home/hadoop

总用量 12

drwx——. 2 hadoop hadoop 62 11月 14 01:29 .

drwxr-xr-x. 13 root root 162 12月 22 20:09 ..

-rwx——. 1 hadoop hadoop 18 8月 3 05:11 .bash_logout

-rwx——. 1 hadoop hadoop 193 8月 3 05:11 .bash_profile

-rwx——. 1 hadoop hadoop 231 8月 3 05:11 .bashrc

[root@localhost ~]# su – hadoop

上一次登录:五 12月 22 19:59:57 CST 2017pts/0 上

[hadoop@localhost ~]$ pwd

/home/hadoop

#############################################################################

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

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

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

#############################################################################

[root@localhost ~]# grep “^[sS]” /proc/meminfo

[root@localhost ~]# grep -i “^s” /proc/meminfo

#############################################################################

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

#############################################################################

[root@localhost ~]# grep -v “/sbin/nologin” /etc/passwd | cut -d: -f1

#############################################################################

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

#############################################################################

[root@localhost ~]# grep “\/bin\/bash$” /etc/passwd | cut -d: -f1

#############################################################################

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

#############################################################################

[root@localhost ~]# egrep “\<[0-9]\>|\<([0-9][0-9])\>” /etc/passwd | cut -d: -f1

[root@localhost ~]# egrep “\<[0-9]\>|\<([0-9][0-9])\>”

#############################################################################

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

#############################################################################

[root@localhost ~]# grep “^[[:space:]]\+” /etc/init.d/functions

[root@localhost ~]# grep “^[[:space:]]\+” /boot/grub/grub.conf

#############################################################################

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

#############################################################################

[root@localhost ~]# grep “^#[[:space:]]\+[^[:space:]]\+” /etc/init.d/functions

[root@localhost ~]# grep “^#[[:space:]]\+[^[:space:]]\+” /etc/rc.d/rc.sysinit

#############################################################################

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

#############################################################################

[root@localhost ~]# netstat -tan | egrep “LISTEN[[:space:]]*”

#############################################################################

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

#############################################################################

[root@localhost ~]# useradd bash

[root@localhost ~]# useradd testbash

[root@localhost ~]# useradd basher

[root@localhost ~]# useradd -s /sbin/nologin nologin

[root@localhost ~]# egrep “^([[:alnum:]]+):.*\1$” /etc/passwd

#############################################################################

本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/90573

(2)
神策神策
上一篇 2017-12-24
下一篇 2017-12-25

相关推荐

  • linux文件权限详解

    基本命令 1.cut : cat /etc/passwd | cut -d’:’ -f7| uniq -c| sort -nr 2.authconfig 修改加密方式 –passalgo=sha256 — update 3.scp 上传文件 -r dir ip:path 传目录 file ip:path传文件 …

    Linux干货 2017-04-03
  • 计算机网络基础及常用工具

    Linux网络属性配置      计算机网络:      TCP/IP: 协议栈(使用)      ISO, OSI: 协议栈(学习)  MAC:Media Access Control      48bits:   &…

    Linux干货 2017-01-02
  • selinux

    [root@localhost ~]# ll /etc/sysconfig/selinux lrwxrwxrwx. 1 root root 17 May 10 16:38 /etc/sysconfig/selinux -> ../selinux/config [root@localhost ~]# cat /etc/selinux/confi…

    Linux干货 2017-05-15
  • hadoop分布式集群

    分布式集群的实现 环境: 192.168.36.129   node1:NN,SNN,RM  192.168.36.130  node2:DN,NM 192.168.36.132   node3:DN,NM 192.168.36.133   node4:DN,NM 配置java环境,每个节点时间同步,基于主机名互相通信,定义/etc/hosts 文件 &nb…

    2017-12-09
  • 构建企业日志实时查看系统

    前言:          由于项目刚刚上线,出现了许多bug,开发人员需要经常跑过来查看日记,严重影响了我们运维人员的工作效率,时而久之,感觉那个烦啊。。各位仁兄有 没有体 会到呢!!! 之前找了一些处理日记的工具都不具有实时性,所以都未采纳,刚刚发现了log.io这个工具推荐个…

    Linux干货 2015-02-13
  • shell脚本执行

    shell脚本执行 对于我们这些小白而讲,shell脚本无疑是最令人头疼的事了,我再这里讲一下shell脚本运行要注意的哪些。 shell脚本就好像c++,java代码一样,按照从上到下然后从左到右的顺序执行。就像我们日常读书一样。如果shell命令遇见了子进程(嵌套代码),程序就会跟着顺序进入子进程。当子进程完成后,回到父进程,并且把父进程所需要的参数提交…

    2017-06-05

评论列表(1条)

  • 马哥教育
    马哥教育 2018-01-02 21:51

    正则的运用对运维工作来说非常重要,作业完成的非常好,平时也要注意多实践,加油。