linux實驗-基本指令1
阿新 • • 發佈:2018-04-10
及其 重定向 unix2dos 要求 func 帳號登錄 定向 設置密碼 dir 1、root帳號登錄,查看/tmp目錄,如果/tmp目錄下沒有子目錄myshare,則建立該目錄。
2、創建帳號testuser。
3、把myshare目錄及其目錄下的所有文件和子目錄的擁有者該為testuser,工作組改為users。
4、切換至testuser帳號。進入/tmp/myshare目錄,采用vim編輯器編寫以上程序,程序名稱為hello.sh:
#!/bin/bash
echo "app start"
echo -e
func (){
echo "hello world!"
}
func
echo -e
echo "app end"
5、保存hello.sh後,給予hello.sh擁有者可讀、可寫和可執行的權限,同組可讀可執行,其他人可執行權限。
6、輸入./hello.sh,觀察程序輸出的效果。
7、進入testuser的用戶主目錄,在這個目錄下創建hello.sh的軟鏈接,同時拷貝hello.sh到該目錄下並改名為hello.sh.bak,要求拷貝時保留文件屬性值。
8、退出testuser帳號,回到root帳號,從/開始查找後綴名為.conf的所有文件,把輸出結果重定向到testuser帳號的主目錄下的output.txt文件。
9、在上一步操作的.conf文件中找出文件容量最大的和最小那個,並把這兩個文件的容量大小輸出到output.txt文件中。
10、統計出系統中有多少個用戶帳號,把數量輸出到output.txt文件中。
11、把output.txt文件轉換為windows記事本可正規打開的格式。
12、tar打包壓縮testuser帳號主目錄下的所有文件。
13、用U盤把上一步打包壓縮文件拷貝到U盤上。
14、執行userdel -r testuser,執行rm -fr myshare
我的做法
剛開始就用root賬號登進去
1 進入tmp目錄 cd /tmp
2 創建目錄 mkdir myshare
創建用戶 useradd testuser
設置密碼 passwd testuser
3 修改文件權限 chown -R testuser:users myshare
4 切換賬號 su testuser
進入myshare目錄 cd /tmp/myshare
vi hello.sh
5 保存文件後,賦予權限 chmod 751 hello.sh
6 ./hello.sh
7 cd ~
ln -s /tmp/myshare/hello.sh myhello.sh
cp -p /tmp/myshare/hello.sh hello.sh.bak
8 回到root賬號 su root
find / -name "*.conf" >output.txt
9 find / -name "*.conf" |xargs du -h |sort -n | tail -1 >> output.txt
find / -name "*.conf" |xargs du -h |sort -n | tail -1 >> output.txt
再vi output.txt把文件裏面後面兩行的文件名刪掉。
10 who -a | wc -l >>output.txt
11 unix2dos -n output.txt.dos output.txt
12 tar -zcvf double.tar.gz testuser
linux實驗-基本指令1