LInux习题练习-04(yum源、用户和组、文件权限、find)

简介: LInux习题练习-04(yum源、用户和组、文件权限、find)

习题练习-04

yum 练习题

  • 利用 yum 安装tree 工具包与http 服务

在web服务初期,由于经常编辑Apache配置文件,请为该配置文件定义别名congfighttp

/etc/httpd/conf/httpd.conf


    # 先进行yum源配置
    [root@localhost ~]# mkdir /mnt/cdrom
    [root@localhost ~]# mount /dev/sr0 /mnt/cdrom
    mount: /dev/sr0 is write-protected, mounting read-only
    [root@localhost ~]# cd /etc/yum.repos.d/
    [root@localhost yum.repos.d]# rm -rf *
    [root@localhost yum.repos.d]# vim yum_con.repo
    [yum_config]
    name = yum_config
    baseurl = file:///mnt/cdrom
    gpgcheck = 0
    enabled = 1
    [root@localhost yum.repos.d]# yum clean all
    [root@localhost yum.repos.d]# yum repolist all

    安装tree
    [root@localhost yum.repos.d]# yum install tree -y

    [root@localhost yum.repos.d]# tree /root/

    安装http 服务
    [root@localhost ~]# yum install httpd -y

    # 重命名配置文件
    [root@localhost ~]# vim /etc/bashrc 
    # 最后一行加入        
    alias confighttp='vim /etc/httpd/conf/httpd.conf'

用户和组练习题

  1. 创建指定用户和组

    • 增加urergrp组,GID号为6000

      [root@localhost ~]# groupadd -g 6000 usergrp

    • 新增user1用户,UID号为6000,密码为空,并将其附属组加入usergrp组中

      [root@localhost ~]# useradd -u 6000 -G usergrp user1

    • 新增user2用户,密码为password,将用户的附属组加入root和usergrp组,用户的主目录为/user2目录

      [root@localhost ~]# useradd -d /user2 -G root,usergrp user2
      [root@localhost ~]# echo 'password' | passwd --stdin user2

    • 新增user3用户,不为用户建立并初始化宿主目录,用户不允许登录到系统的shell

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

  2. 设置用户的密码期限

    • 设置user1用户,在下此登录时必须强制更改密码

      [root@localhost ~]# chage -d 0 user1

    • 设置user2用户,密码30必须更改密码,账号在2016年10月10日过期

      [root@localhost ~]# chage -d 30 -E 2016-10-10 user2

文件权限练习题


  1. 新建目录/var/www/user1,并设置如下权限

    • 将此目录的所有者设置为user1,并设置读写执行权限
    • 将此目录的组设置为usergrp,并设置读执行权限
    • 将其他用户的权限设置为只读

      [root@localhost ~]# mkdir /var/www/user1
      [root@localhost ~]# chown user1:usergrp /var/www/user1/
      [root@localhost ~]# chmod 754 /var/www/user1/

  2. 创建一个共享组ateam,该组中拥有两个新用户andy与alice,这两个账号的密码是password

    • 在/home中创建名为 ateam-text的目录
    • 将ateam-text目录的组所有权限更改为ateam
    • 确保ateam-text的权限允许组成员创建和删除文件
    • 确保ateam-text的权限禁止其他人访问其文件
        [root@localhost ~]# groupadd ateam 
        [root@localhost ~]# useradd -G ateam andy
        [root@localhost ~]# useradd -G ateam alice
        [root@localhost ~]# echo 'password' | passwd --stdin andy
        Changing password for user andy.
        passwd: all authentication tokens updated successfully.
        [root@localhost ~]# echo 'password' | passwd --stdin alice
        Changing password for user alice.
        passwd: all authentication tokens updated successfully.
        [root@localhost ~]# mkdir /home/ateam-text
        [root@localhost ~]# chown :ateam /home/ateam-text/
        [root@localhost ~]# chmod g+w /home/ateam-text/
        [root@localhost ~]# chmod 770 /home/ateam-text/

其他练习题

  • find

    • 找出当前目录下的目录和普通文件
    • 找出当前目录下10天没有改变,大小小于4K的普通文件或目录
    [root@localhost ~]# find . -type d -o -type f -size +4k ! -mtime -10

stat filename 查看文件状态

关于Linux下三种时间的简单介绍
  • atime(access time)

    • 显示文件中的数据最后被访问的时间,example: 可执行脚本文件

      • 此时最后被访问时间是进程调用/脚本执行,不是查看(cat)
  • mtime(modify time)

    • 显示文件内容最后一次被修改的时间,example: vim编辑文件
  • ctime(change time)

    • 显示文件的权限,拥有者,所属的组,链接数发生改变的时间(内容改变也会随之改变)
[root@localhost ~]# touch aa.txt
[root@localhost ~]# stat aa.txt
Access: 2020-05-22 08:20:38.488730387 -0400
Modify: 2020-05-22 08:20:38.488730387 -0400
Change: 2020-05-22 08:20:38.488730387 -0400

[root@localhost ~]# vim aa.txt
print 'Hello linux!!!'
[root@localhost ~]# stat aa.txt
Access: 2020-05-22 08:26:45.115458651 -0400
Modify: 2020-05-22 08:26:45.115458651 -0400
Change: 2020-05-22 08:26:45.116458648 -0400

[root@localhost ~]# python aa.txt
Hello linux!!!
Access: 2020-05-22 08:27:32.967636929 -0400
Modify: 2020-05-22 08:26:45.115458651 -0400
Change: 2020-05-22 08:26:45.116458648 -0400

[root@localhost ~]# cat aa.txt
print 'Hello linux!!!'
Access: 2020-05-22 08:27:32.967636929 -0400
Modify: 2020-05-22 08:26:45.115458651 -0400
Change: 2020-05-22 08:26:45.116458648 -0400

  • 用三种方法在文件hello.txt 中增加一行内容

    vim/gedit hello.txt
    echo 'linux' >> hello.txt
    cat >> hello.txt << END

    [root@localhost ~]# vim hello.txt
    这是vim写的
    [root@localhost ~]# echo '这是echo写的' >> hello.txt 
    [root@localhost ~]# cat hello.txt 
    这是vim写的
    这是echo写的
    [root@localhost ~]# cat >> hello.txt 
    cat写的
    
    
    ^C
    [root@localhost ~]# cat hello.txt 
    这是vim写的
    这是echo写的
    cat写的
    
    
    [root@localhost ~]# cat >> hello.txt << END
    > 111
    > 222
    > 333
    > END
    [root@localhost ~]# cat hello.txt 
    这是vim写的
    这是echo写的
    cat写的
    
    
    111
    222
    333
目录
相关文章
|
17天前
|
Linux C语言
linux yum安装ffmpeg 图文详解
linux yum安装ffmpeg 图文详解
38 0
|
17天前
|
Linux
linux yum 安装rar和unrar
linux yum 安装rar和unrar
57 0
|
1月前
|
Shell Linux
【Shell 命令集合 文件管理】Linux find命令使用教程
【Shell 命令集合 文件管理】Linux find命令使用教程
36 0
|
1月前
|
存储 Linux 数据安全/隐私保护
Linux文件权限及用户管理
Linux文件权限及用户管理
15 0
|
19天前
|
Ubuntu Linux 编译器
【Linux】4. 开发工具的使用(yum/vim)
【Linux】4. 开发工具的使用(yum/vim)
44 2
|
29天前
|
安全 Ubuntu Shell
Linux之用户权限和文件权限详解
Linux之用户权限和文件权限详解
|
3天前
|
人工智能 数据可视化 Linux
【linux基础(五)】Linux中的开发工具(上)---yum和vim
【linux基础(五)】Linux中的开发工具(上)---yum和vim
|
13天前
|
Linux
Linux 指令|date|cal|find|grep|热键
Linux 指令|date|cal|find|grep|热键
|
17天前
|
缓存 Linux
linux centos7 挂载本地iso yum源
linux centos7 挂载本地iso yum源
73 0
|
19天前
|
缓存 自然语言处理 Linux
【Linux】9. 习题①
【Linux】9. 习题①
38 2