第二周博客作业

第一题 总结cp、mv命令的用法(要求列出源及目标各种情况的表格)
cp 命令
用法:
cp 【选项】。。。源文件 目标文件
-a:此选项通常在复制目录的时候使用,保留链接、文件属性,并复制目录下的所有内容。
-d:复制时保留链接。这里所说的链接相当于Windows系统中的快捷方式。
-f:覆盖已经存在的目标文件而不给出提示。
-i:与-f选项相反,在覆盖目标文件之前给出提示,要求用户确认是否覆盖,回答y时目标文件将被覆盖。
-p:除复制文件的内容外,还把修改时间和访问权限也复制到新文件中。
-r:若给出的源文件是一个目录文件,此时将复制该目录下所有的子目录和文件。
-l:不复制文件,只是生成链接文件。
功能:
将源文件复制到目标文件
实例:
使用cp将当前目录test/下的所有文件复制到新目录newtest下,输入如下命令:
$ cp -r test/ newtest

mv命令
命令格式:mv 【选项】 源文件或目录 目标文件或目录
命令功能:当第二个参数类型是目录时,mv命令将文件重命名或者移动到一个新的目录中;当第二个参数是文件时,mv命令完成文件重命名,此时源文件只能有一个(也可是原目录名),它将所给的源文件或目录重命名为给定的目标文件名;当第二个参数是已经存在的目录名时,源文件或者目录可以有多个,mv命令将各参赛指定的源文件均移至目标目录中,在跨文件系统移动文件时,mv先拷贝,再将原有文件删除,而链至该文件的链接也将丢失。
命令参数:
-b:若需要覆盖文件,则覆盖前先行备份。
-f:如果目标文件已经存在,不会询问是否覆盖,直接强制执行。
-i:若目标文件已经存在时,就会询问是否覆盖 。
-u:若目标文件已经存在,且source比较新,才会更新
-t:指定移动的目标目录,该选项适用于移动多个源文件到一个目录的情况,此时目标目录在前,多个源文件在后。

第二题 总结IO重定向的类别和区别
1)标准输入(stdin),文件标识符为0,默认接受来自键盘的输入
2)标准输出(stdout),文件标识符为1,默认输出到终端。
3)标准错误(stderr),文件标识符为2,默认输出到终端。
输入输出重定向:就是改变输入输出来源,错误输出和标准输出的重定向需要符号辅助完成。
1)标准输出重定向
> :以覆盖方式把命令的正确输出内容输出到指定的文件或设备中
例如:
[magedu@localhost ~] ls data/
file1.txt file2.txt ifconfig.txt test.file
[magedu@localhost ~]$ cat data/file1.txt

/etc/fstab

Created by anaconda on Thu Jun 3 23:26:26 2021

Accessible filesystems, by reference, are maintained under '/dev/disk/'.

See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.

After editing this file, run 'systemctl daemon-reload' to update systemd

units generated from this file.

/dev/mapper/cs-root / xfs defaults 0 0
UUID=d7eba891-0699-47a8-bfff-478076cee3b6 /boot xfs defaults 0 0
/dev/mapper/cs-swap none swap defaults 0 0

:以追加的方式把命令的正确输出到指定的文件或设备中。
例如:
[magedu@localhost ~] cat data/file1.txt

/etc/fstab

Created by anaconda on Thu Jun 3 23:26:26 2021

Accessible filesystems, by reference, are maintained under '/dev/disk/'.

See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.

After editing this file, run 'systemctl daemon-reload' to update systemd

units generated from this file.

/dev/mapper/cs-root / xfs defaults 0 0
UUID=d7eba891-0699-47a8-bfff-478076cee3b6 /boot xfs defaults 0 0
/dev/mapper/cs-swap none swap defaults 0 0
Mon Jun 14 17:49:39 CST 2021

2)标准输出错误重定向
2>:以覆盖方式把命令的错误输出内容输出到指定的文件或设备中
2>>:以追加方式把命令的错误输出内容输出到指定的文件或设备中
例如:
[magedu@localhost ~] cat data/err.txt
ls: cannot access '/data': No such file or directory
[magedu@localhost ~] cat data/err.txt
ls: cannot access '/data': No such file or directory
bash: lk: command not found...
[magedu@localhost ~]$

3)标准输出和标准错误重定向
&>:以覆盖方式把stdout和stderr重定向到文件
&>>:以追加方式把stdout和stderr重定向到文件
例如:
[magedu@localhost ~] cat data/err.txt
df: invalid option -- 's'
Try 'df --help' for more information.
[magedu@localhost ~]PATH &>> data/err.txt
[magedu@localhost ~]$ cat data/err.txt
df: invalid option -- 's'
Try 'df --help' for more information.
/home/magedu/.local/bin:/home/magedu/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin

第三题 将/etc/issue文件中的内容转换为大写后保存至/tmp/issue.out文件中
[magedu@localhost ~] cat /tmp/issue.out
\S
KERNEL \R ON AN \M

[magedu@localhost ~]$

第四题 请总结描述用户和组管理类命令的使用方法并完成以下练习:
(1)、创建组distro,其GID为2019;
[root@localhost ~]# groupadd -g 2019 distro
[root@localhost ~]# useradd wang -g distro
[root@localhost ~]# id wang
uid=1001(wang) gid=2019(distro) groups=2019(distro)

(2)、创建用户mandriva, 其ID号为1005;基本组为distro;
[root@localhost ~]# useradd mandriva -u 1005 -g distro
[root@localhost ~]# id mandriva
uid=1005(mandriva) gid=2019(distro) groups=2019(distro)

(3)、创建用户mageia,其ID号为1100,家目录为/home/linux;
[root@localhost ~]# useradd mageia -u 1100 -d /home/linux
[root@localhost ~]# id mageia
uid=1100(mageia) gid=1100(mageia) groups=1100(mageia)
[root@localhost ~]# su mageia
[mageia@localhost root] cd
[mageia@localhost ~]$ pwd
/home/linux

(4)、给用户mageia添加密码,密码为mageedu,并设置用户密码7天后过期
[root@localhost ~]# echo "mageedu" | passwd --stdin mageia
Changing password for user mageia.
passwd: all authentication tokens updated successfully.
[root@localhost ~]# passwd -x 7 mageia
Adjusting aging data for user mageia.
passwd: Success

(5)、删除mandriva,但保留其家目录;
[root@localhost ~]# userdel mandviva
(6)、创建用户slackware,其ID号为2002,基本组为distro,附加组peguin;
[root@localhost ~]# groupadd -g 5000 peguin
[root@localhost ~]# useradd slackware -u 2002 -g distro -G peguin
[root@localhost ~]# id slackware
uid=2002(slackware) gid=2019(distro) groups=2019(distro),5000(peguin)

(7)、修改slackware的默认shell为/bin/tcsh;
[root@localhost ~]# usermod -s slackware /bin/tcsh

(8)、为用户slackware新增附加组admins,并设置不可登陆。
[root@localhost ~]# usermod slackware -g admins -s /bin/nologin
[root@localhost ~]# id slackware
uid=2002(slackware) gid=5001(admins) groups=5001(admins),5000(peguin)
[root@localhost ~]# su slackware
su: failed to execute /bin/nologin: No such file or directory

第四题 创建用户user1、user2、user3。在/data/下创建目录test
(1)、设置目录/data/test属主、属组为user1
[root@localhost ~]# chown user1:user1 data/test
[root@localhost ~]# ll data/
total 4
-rw-r--r--. 1 root root 0 Jun 7 00:41 file1
-rw-r--r--. 1 root root 16 Jun 7 00:13 file2
lrwxrwxrwx. 1 root root 5 Jun 7 00:08 file3 -> file1
d---------. 2 user1 user1 6 Jun 14 22:58 test
[root@localhost ~]#
(2)、在目录属主、属组不变的情况下,user2对test及其子目录有读写权限
[root@localhost ~]# chmod o+rw data/test/
[root@localhost ~]# ll data/
total 4
-rw-r--r--. 1 root root 0 Jun 7 00:41 file1
-rw-r--r--. 1 root root 16 Jun 7 00:13 file2
lrwxrwxrwx. 1 root root 5 Jun 7 00:08 file3 -> file1
d------rw-. 2 user1 user1 6 Jun 14 22:58 test

(3)、user1在/data/test目录下创建文件a1.sh, a2.sh, a3.sh, a4.sh,设置所有用户都不可删除1.sh,2.sh文件。
[user1@localhost ~] chmod 000 data/test/a2.sh
[user1@localhost ~]ll data/test/ total 0 ----------. 1 user1 user1 0 Jun 15 23:07 a1.sh ----------. 1 user1 user1 0 Jun 15 23:07 a2.sh -rw-rw-r--. 1 user1 user1 0 Jun 15 23:07 a3.sh -rw-rw-r--. 1 user1 user1 0 Jun 15 23:08 a4.sh 如此操作root可以删除。 [user1@localhost ~] chattr +i data/test/a1.sh
[user1@localhost ~]$ chattr +i data/test/a2.sh

(4)、清理/data/test目录及其下所有文件的acl权限
[user1@localhost ~] getfacl data/test/

file: data/test/

owner: user1

group: user1

user::rwx
group::rwx
other::r-x

你可能感兴趣的:(第二周博客作业)