第二周博客作業(yè)

第一題 總結(jié)cp、mv命令的用法(要求列出源及目標(biāo)各種情況的表格)
cp 命令
用法:
cp 【選項(xiàng)】。。。源文件 目標(biāo)文件
-a:此選項(xiàng)通常在復(fù)制目錄的時(shí)候使用,保留鏈接、文件屬性,并復(fù)制目錄下的所有內(nèi)容。
-d:復(fù)制時(shí)保留鏈接。這里所說的鏈接相當(dāng)于Windows系統(tǒng)中的快捷方式。
-f:覆蓋已經(jīng)存在的目標(biāo)文件而不給出提示。
-i:與-f選項(xiàng)相反,在覆蓋目標(biāo)文件之前給出提示,要求用戶確認(rèn)是否覆蓋,回答y時(shí)目標(biāo)文件將被覆蓋。
-p:除復(fù)制文件的內(nèi)容外,還把修改時(shí)間和訪問權(quán)限也復(fù)制到新文件中。
-r:若給出的源文件是一個(gè)目錄文件,此時(shí)將復(fù)制該目錄下所有的子目錄和文件。
-l:不復(fù)制文件,只是生成鏈接文件。
功能:
將源文件復(fù)制到目標(biāo)文件
實(shí)例:
使用cp將當(dāng)前目錄test/下的所有文件復(fù)制到新目錄newtest下,輸入如下命令:
$ cp -r test/ newtest

mv命令
命令格式:mv 【選項(xiàng)】 源文件或目錄 目標(biāo)文件或目錄
命令功能:當(dāng)?shù)诙€(gè)參數(shù)類型是目錄時(shí),mv命令將文件重命名或者移動(dòng)到一個(gè)新的目錄中;當(dāng)?shù)诙€(gè)參數(shù)是文件時(shí),mv命令完成文件重命名,此時(shí)源文件只能有一個(gè)(也可是原目錄名),它將所給的源文件或目錄重命名為給定的目標(biāo)文件名;當(dāng)?shù)诙€(gè)參數(shù)是已經(jīng)存在的目錄名時(shí),源文件或者目錄可以有多個(gè),mv命令將各參賽指定的源文件均移至目標(biāo)目錄中,在跨文件系統(tǒng)移動(dòng)文件時(shí),mv先拷貝,再將原有文件刪除,而鏈至該文件的鏈接也將丟失。
命令參數(shù):
-b:若需要覆蓋文件,則覆蓋前先行備份。
-f:如果目標(biāo)文件已經(jīng)存在,不會詢問是否覆蓋,直接強(qiáng)制執(zhí)行。
-i:若目標(biāo)文件已經(jīng)存在時(shí),就會詢問是否覆蓋 。
-u:若目標(biāo)文件已經(jīng)存在,且source比較新,才會更新
-t:指定移動(dòng)的目標(biāo)目錄,該選項(xiàng)適用于移動(dòng)多個(gè)源文件到一個(gè)目錄的情況,此時(shí)目標(biāo)目錄在前,多個(gè)源文件在后。

第二題 總結(jié)IO重定向的類別和區(qū)別
1)標(biāo)準(zhǔn)輸入(stdin),文件標(biāo)識符為0,默認(rèn)接受來自鍵盤的輸入
2)標(biāo)準(zhǔn)輸出(stdout),文件標(biāo)識符為1,默認(rèn)輸出到終端。
3)標(biāo)準(zhǔn)錯(cuò)誤(stderr),文件標(biāo)識符為2,默認(rèn)輸出到終端。
輸入輸出重定向:就是改變輸入輸出來源,錯(cuò)誤輸出和標(biāo)準(zhǔn)輸出的重定向需要符號輔助完成。
1)標(biāo)準(zhǔn)輸出重定向
> :以覆蓋方式把命令的正確輸出內(nèi)容輸出到指定的文件或設(shè)備中
例如:
[magedu@localhost ~]cat /etc/fstab > data/file1.txt [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

:以追加的方式把命令的正確輸出到指定的文件或設(shè)備中。
例如:
[magedu@localhost ~]date >> data/file1.txt [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)標(biāo)準(zhǔn)輸出錯(cuò)誤重定向
2>:以覆蓋方式把命令的錯(cuò)誤輸出內(nèi)容輸出到指定的文件或設(shè)備中
2>>:以追加方式把命令的錯(cuò)誤輸出內(nèi)容輸出到指定的文件或設(shè)備中
例如:
[magedu@localhost ~]ls /data 2>data/err.txt [magedu@localhost ~] cat data/err.txt
ls: cannot access '/data': No such file or directory
[magedu@localhost ~]lk 2>> data/err.txt [magedu@localhost ~] cat data/err.txt
ls: cannot access '/data': No such file or directory
bash: lk: command not found...
[magedu@localhost ~]$

3)標(biāo)準(zhǔn)輸出和標(biāo)準(zhǔn)錯(cuò)誤重定向
&>:以覆蓋方式把stdout和stderr重定向到文件
&>>:以追加方式把stdout和stderr重定向到文件
例如:
[magedu@localhost ~]df -s &> data/err.txt [magedu@localhost ~] cat data/err.txt
df: invalid option -- 's'
Try 'df --help' for more information.
[magedu@localhost ~]echoPATH &>> 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文件中的內(nèi)容轉(zhuǎn)換為大寫后保存至/tmp/issue.out文件中
[magedu@localhost ~]cat /etc/issue |tr [:lower:] [:upper:] > /tmp/issue.out [magedu@localhost ~] cat /tmp/issue.out
\S
KERNEL \R ON AN \M

[magedu@localhost ~]$

第四題 請總結(jié)描述用戶和組管理類命令的使用方法并完成以下練習(xí):
(1)、創(chuàng)建組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)、創(chuàng)建用戶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)、創(chuàng)建用戶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]pwd /root [mageia@localhost root] cd
[mageia@localhost ~]$ pwd
/home/linux

(4)、給用戶mageia添加密碼,密碼為mageedu,并設(shè)置用戶密碼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)、創(chuàng)建用戶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的默認(rèn)shell為/bin/tcsh;
[root@localhost ~]# usermod -s slackware /bin/tcsh

(8)、為用戶slackware新增附加組admins,并設(shè)置不可登陸。
[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

第四題 創(chuàng)建用戶user1、user2、user3。在/data/下創(chuàng)建目錄test
(1)、設(shè)置目錄/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及其子目錄有讀寫權(quán)限
[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目錄下創(chuàng)建文件a1.sh, a2.sh, a3.sh, a4.sh,設(shè)置所有用戶都不可刪除1.sh,2.sh文件。
[user1@localhost ~]chmod 000 data/test/a1.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權(quán)限
[user1@localhost ~]setfacl -x u:user1 data/test/ [user1@localhost ~] getfacl data/test/

file: data/test/

owner: user1

group: user1

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

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 一、顯示/etc目錄下,非字母開頭,后面跟了一個(gè)字母以及其他任意長度任意字符的文件或目錄 命令: ls [...
    _檸檬氣泡水_閱讀 431評論 0 1
  • 第一題:Linux主要發(fā)行版本1、Redhat Linux 紅帽企業(yè)版本(收費(fèi))Centos 社區(qū)版本(開...
    左旋閱讀 209評論 0 0
  • 1、顯示/etc目錄下,以非字母開頭,后面跟了一個(gè)字母以及其他任意長度任意字符的文件或目錄[root@centos...
    網(wǎng)絡(luò)小孩閱讀 395評論 0 0
  • 1、總結(jié)cp、mv命令的用法(要求列出源及目標(biāo)各種情況的表格) cp命令使用: 功能說明:復(fù)制文件和目錄 語法...
    馬暉閱讀 260評論 0 0
  • 我是黑夜里大雨紛飛的人啊 1 “又到一年六月,有人笑有人哭,有人歡樂有人憂愁,有人驚喜有人失落,有的覺得收獲滿滿有...
    陌忘宇閱讀 8,822評論 28 54

友情鏈接更多精彩內(nèi)容