crontab 使用

分為系統的crontab和使用者使用的crontab分別是在
/etc/crontab (系統crontab)
/var/cron/tabs (使用者crontab)

若修改讓系統自動備份的時間,那麼關於系統的都設定在/etc/crontab,所以先su成root之後,直接對它做編輯,那如果是自己要用的話,那就直接使用crontab指令。另外系統crontab和使用者的crontab有些差異,因為少了owner的欄位,系統的crontab可以指定由那個owner來執行,常理來說一般都是直接用root,而使用者的crontab如果沒有特別指定的話就是你自己本身了

※使用者crontab使用
crontab filename 直接將filename的檔案設為crontab,但格式要正確
crontab -l 列出目前的crontab
crontab -r 移除所有的crontab
crontab -e 編輯crontab (使用的編輯器和環境變數EDITOR有關)
而如果你是超級管理員,你可以使用-u name來針對某個使用者的crontab做變更的動作
ex: crontab -u user1 -e 幫user1編修crontab
ex: crontab -u user2 -r 把user2所設定的crontab移除

※crontab的格式
分 時 日 月 週 所有者 命令
(一共是六個欄位,若使用者自己設定的話不需要設定「所有者」欄位)
ex: */5 * * * * echo "每隔五分鐘"
ex: 59 23 * * * echo "每天的11點59分"
ex: 10 3 * * 6 echo "每星期六的早上3點10分"

Ports & Package 管理工具

系統裝完第一件事要完成以下的事情
1、安裝ports
2、安裝source code
可以透過csup來裝,也可以使用sysinstall如果要用sysinstall來裝的話則叫出sysinstall
Custom -> Distributions -> Custom -> src [X], ports [X] 選好後離開到Distrubitutions那層選Commit之後選擇ftp安裝,之後在/usr下面就會有src和ports目錄了,裡面是整個系統的source code,和ports tree。

另一個方法是使用csup來裝,首先先確定一下使用whereis csup來看看是否存在系統之中,正常來說會顯示csup: /usr/bin/csup (freebsd 7.0)在6.2以後都內件了,之後輸入以下指令
#csup -L 2 -h cvsup.tw.freebsd.org /usr/share/examples/cvsup/ports-supfile
#csup -L 2 -h cvsup.tw.freebsd.org /usr/share/examples/cvsup/stable-supfile
(-L 2 表示輸出cvsup的詳細資訊而-h 表示從那個host來更新,最後面的檔案表示要更新的項目)

3、安裝portupgrade tools
portupgrade 是套件管理不可缺少的工具,它含有更強功能的管理工具可以取代本來內件的陽春管理工具。
#cd /usr/ports/ports-mgmt/portupgrade
#make install clean (出現設定的選單,用預設就可以了)
裝完之後會多出幾個工具
/usr/local/sbin/pkg_deinstall //加強功能的移除套件
/usr/local/sbin/pkg_fetch //下載套件,但不安裝
/usr/local/sbin/pkg_glob //查詢已安裝套件的資料
/usr/local/sbin/pkg_sort //以相依關系排序,而不是以字母排序
/usr/local/sbin/pkg_which
/usr/local/sbin/pkgdb //套件的資料庫維護
/usr/local/sbin/pkgdu //計算套件的大小
/usr/local/sbin/portcvsweb
/usr/local/sbin/portinstall
/usr/local/sbin/ports_glob //查詢未安裝套件的資料
/usr/local/sbin/portsclean //清理ports tree
/usr/local/sbin/portsdb //ports index資料庫維護
/usr/local/sbin/portupgrade //套件升級
/usr/local/sbin/portversion //已安裝套件和ports tree中套件版本比較
內件的工具有(常用的)
/usr/sbin/pkg_add //透過package來安裝套件
/usr/sbin/pkg_delete //移除套件
/usr/sbin/pkg_info //顯示套件資訊
/usr/sbin/pkg_version //已安裝套件和ports tree中套件版本比較

※ports tree, package, 套件
在freebsd系統上安裝軟體有三種方法從ports、直接下載package或是自己編,而裝好之後就稱為套件了,不論是從ports上裝或是package直接安裝,裝完都是一樣的,都稱為套件,管理方式也是一樣的,而port的集合就是ports,而以樹狀目錄放在/usr/ports裡面我們就稱為ports tree。
port -- 由ports tree中來安裝
package -- 由二元可執行檔來安裝
套件 -- port和package裝完都叫套件

※可由portupgrade tools來取代的工具有
pkg_info =====> pkg_tree (若有安裝的話)
pkg_delete ===> pkg_deinstall
pkg_version ==> portversion

※工具詳細介紹
1、pkg_add (由二元可執行檔直接安裝)
pkg_add -r package_name 由遠端下載後安裝
pkg_add -v 安裝時顯示詳細資訊
ex: pkg_add -rv vim-lite

2、pkg_deinstall (移除已安裝的套件)
pkg_deinstall -a 移除全部套件
pkg_deinstall -i 互動詢問模式
pkg_deinstall -n 看看做什麼事而不是真的執行
pkg_deinstall -v 顯示詳細資訊
pkg_deinstall -d 移除套件中的空白資料夾
pkg_deinstall -r 相依於此套件的套件全砍 (向上相依)
pkg_deinstall -R 此套件所需要的套件全砍 (向下相依)
ex: pkg_deinstall -rRvi portupgrade

3、pkg_info (顯示套件相關資訊)
pkg_info 列出所有已經安裝的套件
pkg_info -L 列出已安裝套件檔案列表
pkg_info -b 詳細資訊
pkg_info -p 安裝路徑
pkg_info -D 安裝的訊息
pkg_info -r 顯示此套件相依的套件
pkg_info -R 顯示需要於此套件的套件
ex: pkg_info -L portupgrade-2.4.6,2
ex: pkg_info -rR portupgrade-2.4.6,2
ex: pkg_info -b portupgrade-2.4.6,2

4、pkg_tree (顯示套件相依圖型介面)(建議安裝)
pkg_tree -v 顯示完整相依資訊
pkg_tree -t 只顯示相依樹最上層的套件
pkg_tree -b 只顯示相依樹最下層的套件
pkg_tree -tq 顯示最上層套件,具不顯示細部資訊
ex: pkg_tree -tv
ex: pkg_tree -tq
ex: pkg_tree -v portupgrade

5、pkg_fetch (下載套件,但不安裝)
pkg_fetch -f 不論是否已安裝此套件,強制下載
pkg_fetch -R 此套件所需要的套件一併下載
pkg_fetch -v 顯示下載資訊
※下載的package放在/usr/ports/packages/All下面
ex: pkg_fetch -Rfv portupgrade

6、pkgdu (計算套件的大小)
pkgdu -k 以K來顯示套件大小
pkgdu -m 以M來顯示套件大小
pkgdu -q 只顯示所有安裝套件的總大小
pkgdu -t 顯示所有安裝套件各個大小和總大小
pkgdu -r 顯示相依於此套件的套件大小
pkgdu -R 顯示此套件所需要的套件大小
ex: pkgdu -tm
ex: pkgdu -tk
ex: pkgdu -qm
ex: pkgdu -Rt portupgrade

7、pkgdb (維護套件資料庫)
pkgdb -F 檢查修正資料庫相依性問題
pkgdb -u 更新資料庫
※一次要升級很多套件前後最好做一次
ex: pkgdb -Fu

8、pkg_glob (查詢已安裝套件的資料)
pkg_glob -a 列出全部安裝的套件
pkg_glob -r 列出需要於此套件的套件
pkg_glob -R 列出此套件所相依的套件
※可由pkg_tree來取代
ex: pkg_glob -rR portupgrade

9、portsdb (Ports INDEX資料庫維護)
portsdb -F 從網上取得ports的INDEX檔下來
portsdb -u 更新ports的INDEX資料庫
※可由make fetchindex取代-F
ex: portsdb -Fu

10、ports_glob (查詢Ports INDEX資料庫資料)
ports_glob -r 列出相依於此套件的套件
ports_glob -R 列出此套件所需要的套件
ex: ports_glob -Rr portupgrade
※請注意這ports_glob, pkg_glob兩者的差異,一個是查詢目前已經安裝的所有套件,另一個是查詢整個Ports tree未安裝的所有套件。

11、portversion (檢查套件版本)
portversion -v 列出套件版本詳細比較資料
portversion -F 顯示套件版本
portversion -r 列出相依於此套件的套件版本比較
portversion -R 列出此套件所需求的套件版本比較
ex: portversion -Fv
ex: portversion -FRrv portupgrade

12、portsclean (清理整個Ports tree)
portsclean -C 清理所有port中的工作目錄
portsclean -D 清理所有ports tree中不被參考到的distfile
portsclean -DD 清除所有已裝的port都不再使用的distfile
portsclean -L 清理系統中用不到的shared library
ex: portsclean -CDL

13、portupgrade (升級已經安裝的套件)
portupgrade -a 升級所有套件
portupgrade -n 只顯示將要做什麼,但不真的執行
portupgrade -i 互動模式
portupgrade -m 要append給make的參數
portupgrade -M 要prepend給make的參數
portupgrade -P 用package會去掃PKG_PATH找不到就pkg_fetch再不然就用ports來裝
portupgrade -PP 堅持只用package來裝,不用ports裝
portupgrade -p 做出package,若有指定-r的話,那些被需求套件也會生package
portupgrade -r 相依於此套件的套件全部升級
portupgrade -R 此套件所需要的套件全部升級
portupgrade -v 顯示升級詳細資訊
portupgrade -u 不要保留舊的shared libraries
portupgrade -y 所有問都回答yes
ex: portupgrade -an (看看那些需要升級)
ex: portupgrade -urR portupgrade
ex: portupgrade -urRa (由ports升級所有套件)
ex: portupgrade -urRPPa (由package升級所有套件)

pkg安裝換成其它mirror

#vim .cshrc
setenv PACKAGEROOT ftp://ftp.tw.freebsd.org

tcsh prompt

set prompt='%{\033[1;33m%}[%n@%m] %{\033[1;31m%}%~ %{\033[1;37m%}%T%{\033[m%} %# ' 上色版
set prompt='[%n@%m] %~ %T %# ' 無色版

freebsd 小紙條

1、问:如何让FreeBSD像RedHat那样在ls时显示多种颜色的目录?
答:在/etc/csh.cshrc里面加入:
代码:
setenv LSCOLORS ExGxFxdxCxegedabagExEx
setenv CLICOLOR yes

然后,执行:
sed -i.bak -E s/set prompt/#set prompt/g /root/.cshrc

并重新登录。

2、问:如何让FreeBSD的csh像bash那样按tab列出列出无法补齐的候选文件?
答:标准的方法是按Ctrl+D。但如果一定要用tab的话,在/etc/csh.cshrc中加入:
代码:
set autolist

3、问:如何让FreeBSD的csh显示类似[delphij@spirit] ~这样的提示符?
答:在/etc/csh.cshrc中加入:
代码:
set prompt = '[%B%n@%m%b] %B%~%b%# '
然后,执行:
sed -i.bak -E s/set prompt/#set prompt/g /root/.cshrc

4、问:如何让普通用户也拥有类似root用户那样的命令行编辑能力?
答:在/etc/csh.cshrc中加入:
代码:
bindkey "^W" backward-delete-word
bindkey -k up history-search-backward
bindkey -k down history-search-forward

5、问:使用port来安装软件的理由是什么?
答:ports是FreeBSD推荐的安装方式,它提供了依赖关系检查、自动安全审计(portaudit)、更新等多种功能。此外,还有一些其他理由:
a) 并不是每一个开发人员都了解FreeBSD,但是每一个ports committer都了解。他们可以帮助那些第三方软件的开发者将软件更好地运行在FreeBSD上。
b) 几乎每一个port都符合hier(7)标准。你可以轻易地找到文件。
c) 可以完整地卸载port,但手工安装的不行。
d) port出了问题你可以去邮件列表里抱怨port有问题,手工安装一个人一个办法,没人知道你的问题是什么。
e) FreeBSD的POLA政策保证了绝大多数情况下ports的使用方式的延续性(阅读ports/UPDATING基本上不会遇到大的困难)


6、问:bash, sh, csh哪一个更好?我是否可以把普通用户或root的shell改为bash或者ksh?
答:答案是,习惯哪个哪个就更好。唯一要注意的一点是,尽量不要改变root的shell,特别是要避免使用第三方的shell,因为这会在升级时带来麻烦。

改变shell官方的作法是chsh(1),然而你也可以用vipw或另外一大打工具来完成类似的工作。


7、问:tcsh(csh兼用) 提示符的变量常用的都有哪些?

答:

! 和%h一样
%B 开始粗体模式
%b 结束粗体模式
%c 当前工作目录名称的最后部分
%c2,%c3等等 当前工作目录名称的最后两个、三个(等等)组成部分
%C 跟%c类似,但是使用长形式的目录名称
%d 本周的当天
%D 今天是当月中的第几天
%h 当前命令的历史记录编号
%l shell的当前控制终端
%L 清除从提示符末尾到下一行的所有内容
%m 机器的主机名称
%M 机器的完全符合规范的域名
%n 用户名
%p 用精确格式(包括秒)显示的12小时制时间
%P 用精确格式(包括秒)显示的24小时制时间
%S 开始标准输出格式
%s 结束标准输出格式
%t 以12小时制格式显示时间
%T 以24小时制格式显示时间
%U 开始下划线模式
%u 结束下划线模式
%w 当前月的名称
%W 当前月的序数
%y 以2位格式表示的年
%Y 以4位格式表示的年
%% %字符
%! 跟%h相同
%@ 跟%t相同
$# 扩展到>供常规使用,如果用户正以root身份运行的话,就扩展到#
%/ 当前工作目录的完整名称
%- 以短格式表示的当前工作目录
^C 跟C匹配的控制字符:例如^G代表Ctrl+G
a 使tcsh在任何时候显示提示符时嘟嘟响
e 终止的escape符0x1B
f 终止的换页符
n 在这个位置开始一个新行
r 回车符
t Tab制表符
v 垂直制表符
nnn 由八进制数字nnn所指定的字符

8、问:更新了rc.conf,如何生效?
答:cd /etc && sh rc

9、问:修改更新.cshrc(或者类似文件)之后如何不退出登录立即生效?
答:$ source ~/.cshrc

10、问:我新装了程序在 path (/usr/bin /usr/local/bin etc.,)路径中,如何不重新登录就能直接使用?
答:$ rehash

11、问:csh中如何快速在命令行中移动?
答:移动到行首:^a,行尾:^e,清除:^u

12、问:如何看一个文件而不需要先解压?
答:zcat


13、问:我总是工作到很晚而忘了睡觉的时间怎么办?
答:leave +hhmm(hh小时,mm分钟)


14、C shell如何用快捷键删掉一个词(上一个空格到下一个空格或者行尾之间的部分)?
答:ctrl + w

15、如何用快捷键清屏?
答:ctrl + l

16、如何用快捷键推出shell?
答:ctrl + d


17、如何用快捷键挂起前台进程
答:ctrl + z

18、如何将挂起进程送入后台?
答:bg

19、如何将后台进程或者挂起进程调回前台?
答:fg

20、如何自动补全上次使用的某个命令?
答:敲命令的前几个字母然后按上箭头。
(这个功能是bash所没有的,也是我不爱用bash的主要原因,bash没有旧命令自动补全的能力,你要想找到你上次执行这个命令的所有部分,需要按无数次上箭头,csh能够满足我用bash时的所有常用功能,而反之bash不行,这就是为什么用csh而不是bash的原因)
还有个比较搞笑的快捷键ctrl + t,作用是调换光标之前两个字符的顺序,开始觉得比较BT,仔细想想也有道理,因为我们经常会把ls敲成sl,cd敲成dc....

21、如何在向屏幕回显的同时输出一份到一个文件里去?
答:netstat 1 | tee log

22、freebsd 5.3 and up我修改了rc.conf中的网络设置如何立刻生效?
答:/etc/netstart

23、像apache,mysql等应用是否手动安装会比Ports装更灵活而且快捷?
答:确实灵活而快捷,但是有几个生产系统一个月会升级十七八次?为什么不等ports更新呢?你有没有想过ports更新略晚的原因呢?maintainer是需要时间来测试这个应用更新后是不是会造成意外的问题的。如果你想拥有一个安全而且稳定的apache还是用ports装吧,因为一些潜在的安全问题和不稳定的问题ports里带的补丁会修正,并且将一些在FreeBSD上造成问题的部分移植。我连给这些应用写补丁都用 ports,因为写完了,我可以随时放入ports的补丁目录里,生成新的package。不用Ports就好像明明有艘快艇停在你身旁,你非要游过去一样。
"以至于个别的configure参数无法通过ports传递到原始程序包的编译环境中。"特殊的ports的Makefile不包括的选项,你可以直接写入该ports的Makefile里面,我不觉得这有什么困难的。

24、To run a daemon as non root
A:#su -f -m nobody -c "command args"

25、问:清空文件内容
答:要清空某些文件如日志文件的内容,千万不要使用rm删除文件然后再创建一个新的空文件,因为在两次操作的间隔,系统可能需要访问该文件。下面是清空文件内容的安全方法:
A:$ :>file-to-be-cleared

26、问:分割大文件
A:$ split -b 650m file # 将大文件分块成多个650MB的小文件
$ cat x* >largefile # 将所有小文件合并成一个大文件

27、$lock -p当你使用终端登陆时想暂时离开而又不想logout,那么可以用lock -p.
当你返回时输入密码就可以.

28、双系统中 重装Windows后怎样再进FreeBSD
...1)在能进FreeBSD时先备份好FreeBSD的引导文件
.... #dd bs=512 count=1 if=/dev/ad0s3 of=bootsect.bsd
.... 说明:/dev/ad0s3是你的FreeBSD所在分区,用mount命令可以查看
...2)#cp bootsect.bsd /mnt/c/
.....说明:/mnt/c/是你挂载的Windows所在分区
...3)修改Windows的启动文件boot.ini,在最后一行加入
.....C:bootsect.bsd="FreeBSD"
.....说明:这里假设你的Windows装在C盘

用手動連無線網路

出處 http://wirelessdefence.org/Contents/LinuxWirelessCommands.htm

Connecting to an OPEN / WEP WLAN (DHCP)

Note: replace [interface] with your interface name as required (e.g. eth1, wlan0, ath0 etc.)
iwconfig [interface] mode managed key [WEP key] (128 bit WEP use 26 hex characters, 64 bit WEP uses 10)
iwconfig essid "[ESSID]" (Specify ESSID for the WLAN)
dhclient [interface] (to receive an IP address, netmask, DNS server and default gateway from the Access Point)
ping www.bbc.co.uk (if you receive a reply you have access)

Connecting to an OPEN / WEP WLAN (Manual IP Setup)

Note: replace [interface] with your interface name as required (e.g. eth1, wlan0, ath0 etc.)
It may be necessary to run some packet capture software (e.g. Ethereal) to determine the IP addresses of both the Default Gateway and DNS servers.

iwconfig [interface] mode managed key [WEP key] (128 bit WEP use 26 hex characters, 64 bit WEP uses 10)
iwconfig essid "[ESSID]"
ifconfig [interface] [IP address] netmask [subnetmask]
route add default gw [IP of default gateway] (Configure your default gateway; usually the IP of the Access Point)
echo nameserver [IP address of DNS server] >> /etc/resolve.conf (Configure your DNS server)
ping www.bbc.co.uk (if you receive a reply you have access)

iwconfig Commands:

Note: replace [interface] with your interface name as required (e.g. eth1, wlan0, ath0 etc.)
iwconfig [interface] mode master (set the card to act as an access point mode)
iwconfig [interface] mode managed (set card to client mode on a network with an access point)
iwconfig [interface] mode ad-hoc (set card to peer to peer networking or no access point mode)
iwconfig [interface] mode monitor (set card to RFMON mode our favourite)
iwconfig [interface] essid any (with some cards you may disable the ESSID checking)
iwconfig [interface] essid �your ssid_here� (configure ESSID for network)
iwconfig [interface] key 1111-1111-1111-1111 (set 128 bit WEP key)
iwconfig [interface] key 11111111 (set 64 bit WEP key)
iwconfig [interface] key s:mykey (set key as an ASCII string)
iwconfig [interface] key off (disable WEP key)
iwconfig [interface] key open (sets open mode, no authentication is used and card may accept non-encrypted sessions)
iwconfig [interface] channel [channel no.] (set a channel 1-14)
iwconfig [interface] channel auto (automatic channel selection)
iwconfig [interface] freq 2.422G (channels can also be specified in GHz)
iwconfig [interface] ap 11:11:11:11:11:11 (Force card to register AP address)
iwconfig [interface] rate 11M (card will use the rate specified)
iwconfig [interface] rate auto (select automatic rate)
iwconfig [interface] rate auto 5.5M (card will use the rate specified and any rate below as required)

ifconfig Commands:

Note: replace [interface] with your interface name as required (e.g. eth1, wlan0, ath0 etc.)
ifconfig [interface] up (bring up specified interface)
ifconfig [interface] down (take down specified interface)
ifconfig [interface] [IP address] netmask [subnet-mask] (manually set IP and subnet-mask details)
ifconfig [interface] hw ether [MAC] (Change the wireless cards MAC address, specify in format 11:11:11:11:11:11)

iwpriv Commands:

Note: replace [interface] with your interface name as required (e.g. eth1, wlan0, ath0 etc.)
iwpriv [interface] hostapd 1 (used to set card mode to hostapd e.g. for void11)
When the monitor mode patch is installed as per the Wireless Build HOWTO the following commands may be used to set the card into monitor mode.
iwpriv [interface] monitor [A] [B]
[A]
0 = disable monitor mode
1 = enable monitor mode with Prism2 header
2 = enable monitor mode with no Prism2
[B]
Channel to monitor (1-14)

iwlist Commands:

Note: replace [interface] with your interface name as required (e.g. eth1, wlan0, ath0 etc.)
iwlist is used to display some large chunk of information from a wireless network interface that is not displayed by iwconfig.
iwlist [interface] scan (Give the list of Access Points and Ad-Hoc cells in range (ESSID, Quality, Frequency, Mode etc.) Note: In tests only worked with Atheros cards).
iwlist [interface] channel (Give the list of available frequencies in the device and the number of channels).
iwlist [interface] rate (List the bit-rates supported by the device).
iwlist [interface] key (List the encryption key sizes supported and display all the encryption keys available in the device).
iwlist [interface] power (List the various Power Management attributes and modes of the device).
iwlist [interface] txpower (List the various Transmit Power available on the device).
iwlist [interface] retry (List the transmit retry limits and retry lifetime on the device).
iwlist [interface] ap (Give the list of Access Points in range, and optionally the quality of link to them. Deprecated in favour of scan)
iwlist [interface] peers (Give the list of Peers associated/registered with this card).
iwlist [interface] event (List the wireless events supported by this card).

Madwifi-ng Commands:

MADWiFi supports virtual access points (VAPS), which means you can create more than one wireless device per wireless card (the host wireless card = wifi0).
By default, a sta mode VAP is created by, which is MadWifi talk for a 'managed mode wireless interface'.

Note: replace athx with your interface name as required (e.g. ath0, ath1)

wlanconfig athx destroy (Destroy VAP, athx)
wlanconfig athx create wlandev wifi0 wlanmode sta (Create a managed mode VAP, athx)
wlanconfig athx create wlandev wifi0 wlanmode ap (Create an Access Point VAP, athx)
wlanconfig athx create wlandev wifi0 wlanmode adhoc (Create an Ad-Hoc VAP, athx)
wlanconfig athx create wlandev wifi0 wlanmode monitor (Create a Monitor mode VAP, athx)

Changing modes:

ifconfig athx down (Take the VAP down)
wlanconfig athx destroy (Destroy the VAP, athx)
wlanconfig athx create wlandev wifi0 wlanmode [sta|adhoc|ap|monitor] (Create a new sta, adhoc, ap or monitor VAP)
Scan for Access Points (requires both steps):
modprobe wlan_scan_sta (To insert the scanning module)
wlanconfig athx list scan (To list the APs)

解決flash player中文乩碼問題

先使用root開啟/etc/fonts/conf.d/49-sansserif.conf
之後使用fc-list :lang=zh-tw 來看看有那些可以用的字型
之後複製貼上到最後一個 區段,把它裡面的 sans-serif 換成你要換的字體。