2009年6月15日 星期一

linux 記錄2

#grep -v '^#' httpd.conf | grep -v '^$' | wc -l <請觀察內容>
#wc -l httpd.conf <請觀察內容>
#egrep -v '^#|^$' httpd.conf <請觀察內容>
==========================================
#echo "Today is `date`" 檔指令可以執行
#echo 'Today is `date`' 全部為字串

================================
#ls /123 2> ls.txt <將 ls /123 的 STDERR 導向到 ls.txt, 2> 指定 STDERR>
==========================
#mail root -s "disk free" < df.txt <以 df.txt 為信件內容寫信給 root,主旨為 disk free >
=======================
dd <剪下一行>
p <貼上>
2dd <剪下兩行>
p <貼上>
yy <複製一行>
p <貼上>
:syntax on
:%s/httpd.conf/http.bak/gc
============================
*相關設定
:set nu <顯示行號>
:151,156s/^/#/g
==================================
#vi /etc/inittab
修改
id:3:initdefault: <將 5 改為 3, 之後就以 Runlevel 3 開機>
=======================
Lab: userdel 與 userdel -r 的差異為?
-r 會刪除使用者家目錄及信箱
========================
#useradd -m test
#echo 1234 | passwd --stdin test

當使用者離職
1.鎖定該帳戶
#usermod -L test <鎖定使用者帳戶, -L 鎖定, -U 解除>
#tail -n 2 /etc/shadow <在密碼前加上!,為鎖定>
2.刪除使用者帳戶
#userdel test
#ls -l /home
3.將其帳戶移轉到/root
#mv /home/test /root
#chown root.root /root/test
=====================================
Lab: group
#tail -n 2 /etc/group <觀察群組資料庫>
#groupadd mis <新增 mis 群組>
#tail -n 2 /etc/group
#groupmod -A max mis <將使用者 max 加入 mis 群組, -A 新增>
#tail -n 2 /etc/group
#groupmod -R max mis <將使用者 max 從 mis 群組移除, -R 移除>
#tail -n 2 /etc/group
#groupdel mis <刪除 mis 群組>
#tail -n 2 /etc/group
===================================
#chmod g+s /mis <將/mis 資料夾加上 SGID>
#ls -ld /mis <請觀察權限及擁有者,群組>
#touch /mis/test2
#ls -l /mis <請觀察權限及擁有者,群組>
===================
Lab: sticky bit
目的:不管權限為何不可以刪除其他人的檔案
#mkdir /test
#chmod 1777 /test <將/test 加上 sticky bit 權限並將權限設定為 777>
#touch /test/test.txt
#chmod 777 /test/test.txt
#ls -ld /test <請觀察權限及擁有者,群組>
#ls -l /test <請觀察權限及擁有者,群組>
#su - user1 -c "rm /test/test.txt" <以使用者 user1 刪除/test/test.txt -->失敗>
<因/test 目錄有設定 sticky bit 權限,故非本人不能刪除>

沒有留言: