這裏顯示兩個版本的差異處。
| Both sides previous revision 前次修改 下次修改 | 前次修改 | ||
|
linux:basic [2007/03/30 10:53] wenpei tar -p |
linux:basic [2010/04/06 12:19] (目前版本) wenpei |
||
|---|---|---|---|
| 行 1: | 行 1: | ||
| + | ====== 關掉 console 下的蜂鳴器 ====== | ||
| + | sudo modprobe -r pcspkr | ||
| + | |||
| + | 或者用 sudo modconf,找到 drivers/input/misc/pcspkr.ko 並移除。 | ||
| + | |||
| ====== 家目錄的原始檔 ====== | ====== 家目錄的原始檔 ====== | ||
| /etc/skel | /etc/skel | ||
| 行 4: | 行 9: | ||
| ====== 手動建帳號 ====== | ====== 手動建帳號 ====== | ||
| - 編輯 /etc/passwd | - 編輯 /etc/passwd | ||
| + | - 將 /etc/passwd 與 /etc/shadow 同步化 ( pwconv ) | ||
| - 編輯 /etc/group | - 編輯 /etc/group | ||
| + | - 將 /etc/group 與 /etc/gshadow 同步化 ( grpconv ) | ||
| - 開設使用者的自家目錄(通常在 /home 中, 建一個和使用者帳號同名的目錄) | - 開設使用者的自家目錄(通常在 /home 中, 建一個和使用者帳號同名的目錄) | ||
| - 將 /etc/skel 中的檔案全拷貝至使用者的自家目錄(cp /etc/skel/.* /home/使用者) | - 將 /etc/skel 中的檔案全拷貝至使用者的自家目錄(cp /etc/skel/.* /home/使用者) | ||
| 行 10: | 行 17: | ||
| - 設定密碼 | - 設定密碼 | ||
| + | ====== 大量建帳號 ====== | ||
| + | <code> | ||
| + | for line in `cat account.txt` | ||
| + | do | ||
| + | account=`echo $line | cut -d : -f 1` | ||
| + | passwd=`echo $line | cut -d : -f 2` | ||
| + | useradd -m $account | ||
| + | echo $account:$passwd | chpasswd | ||
| + | done | ||
| + | </code> | ||
| + | |||
| + | account.txt 格式: | ||
| + | account:password | ||
| + | |||
| + | ====== 手動移除帳號 ====== | ||
| + | - 先以 find / -user account 找出所有的帳號檔案,並將他刪除 | ||
| + | - 將 /etc/passwd 與 /etc/shadow 的相關資料刪除 | ||
| + | - 將 /etc/group 及 /etc/gshadow 相關資料刪除 | ||
| + | - 將 /home 底下關於該帳號的目錄刪除 | ||
| + | - 到 /var/spool/mail 以及 /var/spool/cron 裡面將相關的使用者檔案刪除 | ||
| ====== 使用者郵件轉寄 ====== | ====== 使用者郵件轉寄 ====== | ||
| 行 84: | 行 111: | ||
| scp [file] [username]@[host]:[path] | scp [file] [username]@[host]:[path] | ||
| example: | example: | ||
| - | scp make.conf fang@140.115.189.106: | + | scp make.conf user@192.168.1.2:~ |
| - | 主機後面要加一個「:」 | + | 主機後面要加一個「:」代表遠端的主機,「~」代表遠端的家目錄。 |
| ====== 透過 ssh 掛載遠端 filesystem ====== | ====== 透過 ssh 掛載遠端 filesystem ====== | ||
| 行 112: | 行 139: | ||
| ===== bmon ===== | ===== bmon ===== | ||
| ===== iftop ===== | ===== iftop ===== | ||
| + | ===== iptraf ===== | ||
| 行 130: | 行 158: | ||
| set paste | set paste | ||
| set softtabstop=4 | set softtabstop=4 | ||
| + | |||
| + | ====== cp ====== | ||
| + | * -p 表示保留 permission,ownership,timestamp | ||
| + | * -d 表示完整複製 symlink and hard link | ||
| + | * -R 表示複製子目錄與特殊屬性的檔案 (socket, pipe line file) | ||
| ====== tar ====== | ====== tar ====== | ||
| 行 144: | 行 177: | ||
| tar -rvf filename.tar file1 [file2 ...] # 將檔案放入已存在的 .tar 檔中 | tar -rvf filename.tar file1 [file2 ...] # 將檔案放入已存在的 .tar 檔中 | ||
| tar --delete -vf filename.tar file1 [file2 ...] # 將存在 .tar 裡面的 file1 刪除 | tar --delete -vf filename.tar file1 [file2 ...] # 將存在 .tar 裡面的 file1 刪除 | ||
| - | tar -xvf filename.tar # 解開 | + | tar -xvf filename.tar[.Z | .gz | .bz2] # 解開(可以不用指定解壓縮方式) |
| ===== 以 bzip2 壓縮 ===== | ===== 以 bzip2 壓縮 ===== | ||
| 行 165: | 行 198: | ||
| * -m 顯示共享記憶體 | * -m 顯示共享記憶體 | ||
| * -p 顯示 Process 訊息 | * -p 顯示 Process 訊息 | ||
| + | |||
| + | ====== curl ====== | ||
| + | 列出網頁的詳細 header | ||
| + | $ curl -I [url] | ||
| ====== ssh 登入訊息 ====== | ====== ssh 登入訊息 ====== | ||
| 行 173: | 行 210: | ||
| # uname -snrvm > /var/run/motd | # uname -snrvm > /var/run/motd | ||
| # [ -f /etc/motd.tail ] && cat /etc/motd.tail >> /var/run/motd | # [ -f /etc/motd.tail ] && cat /etc/motd.tail >> /var/run/motd | ||
| + | |||
| + | ====== SSH 不檢查 key ====== | ||
| + | ~/.ssh/config | ||
| + | StrictHostKeyChecking no | ||
| + | |||
| + | ====== 備份指令 ====== | ||
| + | ===== bash ===== | ||
| + | http://blog.wu-boy.com/2006/12/10/52 | ||
| + | <code> | ||
| + | #!/bin/bash | ||
| + | date=`date +%Y-%m-%d` | ||
| + | RETENTION_PERIOD="7" | ||
| + | HEADER="Backup data" | ||
| + | remove_oldfiles(){ | ||
| + | echo "Removing directory $1 files older than $RETENTION_PERIOD days" | ||
| + | | wall | ||
| + | find $1 -type f -mtime +$2 -exec rm '{}' \; | ||
| + | } | ||
| + | |||
| + | BACKUPDIR="/home/appleboy /var/www/html" | ||
| + | back_www_dir="/backup01/www_data" | ||
| + | |||
| + | # | ||
| + | # 開始備份 | ||
| + | # | ||
| + | |||
| + | cd $back_www_dir | ||
| + | |||
| + | for TARGET in $BACKUPDIR | ||
| + | do | ||
| + | echo "System backup on $TARGET" | wall | ||
| + | BASENAME=`basename $TARGET` | ||
| + | |||
| + | tar -zcvf ${BASENAME}-${date}.tar.gz $TARGET 1>/dev/null | ||
| + | sleep 2 | ||
| + | done | ||
| + | |||
| + | # | ||
| + | # 刪除7天前的資料 | ||
| + | # | ||
| + | remove_oldfiles $back_www_dir $RETENTION_PERIOD | ||
| + | </code> | ||
| + | |||
| + | ====== Run commands on multiple machines ====== | ||
| + | Fanout and Fanterm: http://blog.wu-boy.com/2010/01/08/1950/ | ||
| + | |||