...
零,由於某種誤操作,導致用戶賬戶下的shell配置文件丟失被刪除
一,你登錄到對應主機后,默認使用的那種shell
$ echo $SHELL
$ pstree
$ pstree -up|grep sshd
二,bash,csh的全局配置,用戶配置文件
三,配置對應的ORACLE_HOME,ORACLE_SID
export ORACLE_HOME=
export ORACLE_SID=
=====================================
四,參考資料:
http://www.ochef.net/2009/09/compare-unix-shell.html
隨着在Unix和Linux平台下工作的時間越長,不同種類的shell繁多,感覺對shell的認識由清晰開始變得模糊,所以應該趕緊弄清楚它們,shell太重要了。以下內容來自互聯網綜合、整理后的。
.profile:是Bourne Shell (sh)的配置文件,Korn Shell (ksh)兼容sh所以也會使用.profile。
/etc/profile:此文件為系統的每個用戶設置環境信息,當用戶第一次登錄時該文件被執行,並從/etc/profile.d目錄的配置文件中搜集shell的設置。
.bash_ profile:是bash特有的, 由於bash被設計成兼容sh、ksh並有csh的特征, 所以會在用戶主目錄依次查找.bash_profile, .bash_login,.profile並用找到的第一個作為自己的配置文件。
~/.bash_profile:每個用戶都可使用該文件輸入專用於自己使用的shell信息。當用戶登錄時,該文件僅僅執行一次。默認情況下,它設置一些環境變量,執行用戶的.bashrc文件。
.login 是C Shell (csh) 的配置文件。
在Linux下sh是bash的一個鏈接, 如果bash使用sh命令啟動的, 就會以sh兼容方式運行使用.profile,可用man bash命令查看更詳細的解釋。
/etc/bashrc:為每一個運行bash shell的用戶執行此文件,當bash shell被打開時,該文件被讀取。
~/.bashrc:該文件包含專用於你的bash shell的bash信息,當登錄時以及每次打開新的shell時,該該文件被讀取。
~/.bash_logout:當每次退出系統(退出bash shell)時,執行該文件。另外,/etc/profile中設定的變量(全局)的可以作用於任何用戶,而~/.bashrc等中設定的變量(局部)只能繼承/etc/profile中的變量,它們是”父子”關系。
~/.bash_profile:是交互式、login 方式進入 bash 運行的;~/.bashrc 是交互式 non-login 方式進入 bash 運行的。通常二者設置大致相同,所以通常前者會調用后者。
-The End-
http://space.itpub.net/22666004/viewspace-618337
大家要尊重俺的勞動成果,轉載請注明出處。本文首發自http://blog.csdn.net/erazy0/archive/2009/11/07/4782368.aspx
俺的百度空間http://hi.baidu.com/erazy0以及俺的ITPUB博客http://space.itpub.net/22666004/spacelist-blog也會同步更新
歡迎共同學習,交流,本人QQ:398467907 郵箱:zhaizhibin@hotmail.com
歡迎交換友情鏈接~~
===================================華麗的分割線=========================================
果然,事情永遠不會一帆風順,在連續出了N次故障后,今天,俺的 Oracle 11g 終於不甘寂寞,再次的出來“興風作浪”了。
今天的問題很簡單,我登錄進oracle用戶以后,鍵入sqlplus出現如下錯誤:
--------------------------------------------------------------------------------
[oracle@zzb ~]$ sqlplus
sqlplus: Command not found.
--------------------------------------------------------------------------------
試了幾次又重新啟動都是這樣的,於是立刻去百度,出來一大堆,具體有以下兩種:
oracle環境變量設置不正確或者PATH設置不正確。
root登陸后應該 su - oracle,而不是直接 su oracle,中間加短線以繼承oracle用戶的環境變量。
第2種情況不用考慮,我是用secureCRT直接登錄的oracle,不存在環境變量沒繼承的問題。
至於第1種情況我記得從沒有改過家目錄下的 .bash_profile 文件,我 vi .bash_profile 看了一下沒有發現有什么問題:
--------------------------------------------------------------------------------
[oracle@zzb ~]$ vi .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
unset USERNAME
ORACLE_BASE=/u01
ORACLE_HOME=$ORACLE_BASE/oracle
ORACLE_SID=zzb
PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_BASE ORACLE_HOME ORACLE_SID PATH
stty erase ^h
#DISPLAY=192.168.0.1:0.0; export DISPLAY
LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
".bash_profile" 28L, 464C written
[oracle@zzb ~]$ vi .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
unset USERNAME
ORACLE_BASE=/u01
ORACLE_HOME=$ORACLE_BASE/oracle
ORACLE_SID=zzb
PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_BASE ORACLE_HOME ORACLE_SID PATH
stty erase ^h
#DISPLAY=192.168.0.1:0.0; export DISPLAY
--------------------------------------------------------------------------------
於是我又輸入:
--------------------------------------------------------------------------------
[oracle@zzb ~]$ env | grep ORA
[oracle@zzb ~]$
--------------------------------------------------------------------------------
終於出問題了,oracle的環境變量竟然一個也沒出來,難道是啟動時出了什么問題?於是我又輸入:
--------------------------------------------------------------------------------
[oracle@zzb ~]$ source .bash_profile
if: Expression Syntax.
--------------------------------------------------------------------------------
怪了,竟然出了語法問題。這時我突然想起來了,這幾天我在學 Shell ,難道是我昨天切換到其他的 shell 下沒有切換回來?似乎只有這樣才會報語法問題吧,畢竟不同的 shell 之間語法還是有一些差異的。於是我就:
--------------------------------------------------------------------------------
[oracle@zzb ~]$ echo $SHELL
/bin/csh
--------------------------------------------------------------------------------
果然是 shell 的問題。於是我:
--------------------------------------------------------------------------------
[oracle@zzb ~]$ exec bash
[oracle@zzb ~]$
[oracle@zzb ~]$ pstree
init─┬─acpid
├─anacron
├─atd
├─crond
├─cups-config-dae
├─cupsd
├─dbus-daemon-1
├─events/0
├─gpm
├─hald
├─htt───htt_server
├─khelper
├─khubd
├─kjournald
├─klogd
├─kseriod
├─ksoftirqd/0
├─kswapd0
├─kthread─┬─aio/0
│ ├─ata/0
│ ├─ata_aux
│ ├─kacpid
│ ├─kauditd
│ ├─kblockd/0
│ └─2*[pdflush]
├─migration/0
├─6*[mingetty]
├─24*[oracle]
├─portmap
├─rpc.idmapd
├─rpc.statd
├─scsi_eh_0
├─2*[sendmail]
├─sshd───sshd───sshd───bash───pstree
├─syslogd
├─udevd
├─vmhgfs
├─vmmemctl
├─vmware-guestd
├─xfs
└─xinetd
[oracle@zzb ~]$ env|grep ORA
ORACLE_SID=zzb
ORACLE_BASE=/u01
ORACLE_HOME=/u01/oracle
[oracle@zzb ~]$
--------------------------------------------------------------------------------
大家可以看到,現在一切正常了。然后再次輸入:
--------------------------------------------------------------------------------
[oracle@zzb ~]$ source .bash_profile
[oracle@zzb ~]$
--------------------------------------------------------------------------------
這次沒報錯,然后我就:
--------------------------------------------------------------------------------
[oracle@zzb ~]$ sqlplus /nolog
SQL*Plus: Release 11.1.0.6.0 - Production on Sat Nov 7 12:55:15 2009
Copyright (c) 1982, 2007, Oracle. All rights reserved.
SQL> conn / as sysdba
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 313860096 bytes
Fixed Size 1299624 bytes
Variable Size 226495320 bytes
Database Buffers 79691776 bytes
Redo Buffers 6373376 bytes
Database mounted.
Database opened.
SQL> select * from dual;
D
-
X
--------------------------------------------------------------------------------
可以看到,正常進入了。
最后,秉着好奇心,我又輸入:
--------------------------------------------------------------------------------
[oracle@zzb ~]$ echo $SHELL
/bin/csh
--------------------------------------------------------------------------------
額。。。怎么還是 csh,pstree 里顯示的明明只有 bash ,沒辦法,我只能:
--------------------------------------------------------------------------------
[oracle@zzb ~]$ su -
Password:
[root@zzb ~]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
news:x:9:13:news:/etc/news:/sbin/nologin
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
rpm:x:37:37::/var/lib/rpm:/sbin/nologin
haldaemon:x:68:68:HAL daemon:/:/sbin/nologin
netdump:x:34:34:Network Crash Dump user:/var/crash:/bin/bash
nscd:x:28:28:NSCD Daemon:/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
rpc:x:32:32:Portmapper RPC user:/:/sbin/nologin
mailnull:x:47:47::/var/spool/mqueue:/sbin/nologin
smmsp:x:51:51::/var/spool/mqueue:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
pcap:x:77:77::/var/arpwatch:/sbin/nologin
apache:x:48:48:Apache:/var/www:/sbin/nologin
squid:x:23:23::/var/spool/squid:/sbin/nologin
webalizer:x:67:67:Webalizer:/var/www/usage:/sbin/nologin
xfs:x:43:43:X Font Server:/etc/X11/fs:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
gdm:x:42:42::/var/gdm:/sbin/nologin
pegasus:x:66:65:tog-pegasus OpenPegasus WBEM/CIM services:/var/lib/Pegasus:/sbin/nologin
htt:x:100:103:IIIMF Htt:/usr/lib/im:/sbin/nologin
named:x:25:25:Named:/var/named:/sbin/nologin
dovecot:x:97:97:dovecot:/usr/libexec/dovecot:/sbin/nologin
erazy0:x:500:500:erazy0:/home/erazy0:/bin/bash
oracle:x:501:501::/u01/oracle:/bin/csh <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<注意這行
[root@zzb ~]# vi /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
news:x:9:13:news:/etc/news:/sbin/nologin
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
rpm:x:37:37::/var/lib/rpm:/sbin/nologin
haldaemon:x:68:68:HAL daemon:/:/sbin/nologin
netdump:x:34:34:Network Crash Dump user:/var/crash:/bin/bash
nscd:x:28:28:NSCD Daemon:/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
rpc:x:32:32:Portmapper RPC user:/:/sbin/nologin
mailnull:x:47:47::/var/spool/mqueue:/sbin/nologin
smmsp:x:51:51::/var/spool/mqueue:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
pcap:x:77:77::/var/arpwatch:/sbin/nologin
apache:x:48:48:Apache:/var/www:/sbin/nologin
squid:x:23:23::/var/spool/squid:/sbin/nologin
webalizer:x:67:67:Webalizer:/var/www/usage:/sbin/nologin
xfs:x:43:43:X Font Server:/etc/X11/fs:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
gdm:x:42:42::/var/gdm:/sbin/nologin
pegasus:x:66:65:tog-pegasus OpenPegasus WBEM/CIM services:/var/lib/Pegasus:/sbin/nologin
htt:x:100:103:IIIMF Htt:/usr/lib/im:/sbin/nologin
named:x:25:25:Named:/var/named:/sbin/nologin
dovecot:x:97:97:dovecot:/usr/libexec/dovecot:/sbin/nologin
erazy0:x:500:500:erazy0:/home/erazy0:/bin/bash
oracle:x:501:501::/u01/oracle:/bin/bash
"/etc/passwd" 41L, 1932C written
--------------------------------------------------------------------------------
注意到被我加紅的那一行,問題就出在這兒,看來是昨天練習 shell 的時候不小心把oracle用戶的登陸shell給改了,現在我再:
--------------------------------------------------------------------------------
[oracle@zzb ~]$ echo $SHELL
/bin/bash
--------------------------------------------------------------------------------
終於好了,至此,我的 sqlplus 不能登錄的問題應該算是圓滿解決了。
PostScripts:貼一段找來的Matlab error "if: Expression Syntax" in tcsh 作為參考
Solution:
The "if: Expression Syntax" error can occur if you have the SHELL environment variable set to something different than what is expected. For example, one MATLAB user reported this error and was able to trace it to their use of "tcsh" instead of "csh." Once they explicitly set the SHELL variable in .matlab6rc.sh to "csh" the "if: Expression Syntax" was resolved.
If you are using "csh" or "tcsh", the "if: Expression Syntax" error may also occur as a result of a syntax error in either the .cshrc or .tcshrc files. Please examine the appropriate file for any errors. Alternatively, you can have MATLAB use "sh" by entering the following before starting MATLAB:
setenv MATLAB_SHELL=/bin/shNote: The method for setting environment variables depends on which shell you are using.
THAT'S ALL.
########################
http://space.itpub.net/519536/viewspace-672034
【故障處理】ORA-12162: TNS:net service name is incorrectly specified
本文將給大家闡述一個因未設置系統環境變量ORACLE_SID導致ORA-12162錯誤的案例。希望大家有所思考。
1.獲得有關ORA-12162報錯信息的通用表述信息
[oracle@asdlabdb01 ~]$ oerr ora 12162
12162, 00000, "TNS:net service name is incorrectly specified"
// *Cause: The connect descriptor corresponding to the net service name in
// TNSNAMES.ORA or in the directory server (Oracle Internet Directory) is
// incorrectly specified.
// *Action: If using local naming make sure there are no syntax errors in
// the corresponding connect descriptor in the TNSNAMES.ORA file. If using
// directory naming check the information provided through the administration
// used for directory naming.
2.故障現象
本文所要描述的故障與這個通用的問題描述不同,在數據庫服務器端使用TNSNAMES.ORA中記錄的連接串連接沒有問題,但如若未指定連接串,將會報出ORA-12162錯誤。
1)使用system用戶嘗試登錄系統,此時便會收到報錯如下信息
[oracle@asdlabdb01 ~]$ sqlplus system/sys
SQL*Plus: Release 10.2.0.3.0 - Production on Sat Aug 27 22:54:02 2010
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
ERROR:
ORA-12162: TNS:net service name is incorrectly specified
Enter user-name:
2)使用sysdba身份登陸會得到同樣的錯誤信息
[oracle@asdlabdb01 ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.3.0 - Production on Sat Aug 27 22:54:48 2010
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
ERROR:
ORA-12162: TNS:net service name is incorrectly specified
Enter user-name:
3)但此時,如果使用服務名方式連接數據庫,是可以成功的,這也是該問題現象的詭異之處。
[oracle@asdlabdb01 ~]$ sqlplus system/sys@ora10g
SQL*Plus: Release 10.2.0.3.0 - Production on Sat Aug 27 22:53:41 2010
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options
system@ora10g>
想象一下,你的目標是快速的進入到數據庫中進行維護操作,但此時登錄都遭遇障礙,會感到非常的別扭。更讓人抓狂的是,如果此時使用連接串登錄到數據庫進行停起操作,結果將會處於更加慘烈境況:數據庫將因為無法正常登錄導致無法啟動數據庫。
3.故障原因
詭異的故障背后的原因竟然是那樣的基礎:ORACLE_SID沒有指定!
確認系統當前的ORACLE_HOME和ORACLE_SID環境變量
[oracle@asdlabdb01 ~]$ echo $ORACLE_HOME
/oracle/app/oracle/product/10.2.0/db_1
[oracle@asdlabdb01 ~]$ echo $ORACLE_SID
[oracle@asdlabdb01 ~]$
可見,此時只設置了ORACLE_HOME環境變量,但ORACLE_SID此時為空,這就是該問題的真實原因。
4.故障處理
給出ORACLE_SID,重新嘗試登錄。
[oracle@asdlabdb01 ~]$ export ORACLE_SID=ora10g
[oracle@asdlabdb01 ~]$ echo $ORACLE_SID
ora10g
[oracle@asdlabdb01 ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.3.0 - Production on Sat Aug 27 23:27:34 2010
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options
sys@ora10g>
OK,此時問題處理完畢。
5.小結
這個案例給我們的啟迪是什么?
1)系統默認的錯誤提示信息有時不具有參考價值。而且,某些情況下這些錯誤提示還可能給我們帶來誤導。原因很簡單,系統默認的錯誤提示信息不可能囊括所有故障現象;
2)任何系統級別的設置問題都有可能導致數據庫系統出現異常;
3)在遇到故障的時候,我們需要沉着冷靜。有些時候可能需要我們Check最原始的信息,切莫想當然。
建議:為了避免出現文章中提到的問題,第一,可以將ORACLE_SID等環境變量寫入到系統profile中,但需要確保系統profile文件內容的有效性;第二,不在profile中進行填寫,每次登錄數據庫服務器時手工完成數據庫環境變量的指定,這種方法雖然增加了鍵盤的敲擊,但它更直觀、更有保障。
Good luck.
secooler
10.08.27
-- The End --
#############################
http://blog.csdn.net/cathysun118/article/details/4197778
Sql plus命令報command not found的解決筆記
1.問題描述
環境:linux9, Oracle10g.
在一台裝有Oracle10g的Linux機器上,我運行sqlplus命令,報錯"command not found",
運行別的命令(如:lsnrctl)也同樣的錯誤。初步懷疑是路徑問題,然后我嘗試cd $oracle_home/bin下,
再次運行這些命令,還是同樣的錯誤。但用ls能看到這些命令的存在。
2.分析和解決
這種情況應該是路徑的問題,應該Oracle剛剛安裝成功的,而且安裝過程中沒有出現異常。
我echo $oracle_home為空,echo $path也為空,問題就出在這里了。
然后我
export ORACLE_HOME=<your Oracle Home>
export PATH=$ORACLE_HOME/bin:$PATH
再次運行Sqlplus命令,ok,可以了。
最后,我用vi編輯 .profile文件,把
export ORACLE_HOME=<your Oracle Home>
export PATH=$ORACLE_HOME/bin:$PATH
加入.profile中。保存。
用source .profile啟用該資源文件。
重新進入Linux系統,sqlplus命令一切正常。
#############################################
http://wiki.freebsdchina.org/howto/c/config_your_csh
選擇 csh/tcsh
和許多剛從 Linux 轉到 BSD 的人不同,我並沒有裝完 BSD 就順手安裝 bash,
因為之前除了打命令,我沒有用到額外的功能,bash 也好,csh 也罷,在我眼里都是當做 shell 來用。
但是漸漸地,我發現 csh 真的挺好用,它小巧、簡單、開放,不需要額外依賴。
可能有人要拿腳本能力來作對比,比如bash腳本支持函數,csh不支持等。
對我來說,其實我從未像模像樣地寫過一個腳本,我的工作是 C++ 程序員。
從我的角度來看,
論腳本能力,其實bash、csh、zsh都比不上Python,
論兼容性,bash、csh、zsh都比不上sh,
論強大,bash、csh、zsh都比不上C/C++,甚至asm。
再看易學程度,bash、csh、zsh可能還是要輸給Python。
綜上,腳本能力忽略不計。
好了,說了這么多大不敬的話,我們開始切入正題。
配置文件
全局配置文件 /etc/csh.cshrc
個人配置文件 ~/.cshrc或~/.tcshrc
為了方便,建議修改全局性的配置文件,這樣每個賬號都可以享受便利。
按鍵綁定
通常,我們不設置按鍵綁定也能很好地工作,
但是對於遠程登錄,可能需要一些額外的配置。
比如,為了避免putty登錄后,Home、End、Delete等變成~,你需要如下配置:
bindkey '\e[1~' beginning-of-line # Home bindkey '\e[3~' delete-char # Delete bindkey '\e[4~' end-of-line # End bindkey "^W" backward-delete-word # Delete bindkey -k up history-search-backward # PageUp bindkey -k down history-search-forward # PageDown
提示符
設置一個漂亮使用的的提示符可以讓工作變得更愉快高效。
以下是一個合理的配置方案:
if ( $?prompt ) then #如果$prompt變量尚未設置,則做如下設置 if ( "$uid" == "0" ) then #判斷用戶的uid set prompt = "%U%n%u@%m [%l] %B%~%b # " #對於root,我們顯示“#”號 else set prompt = "%U%n%u@%m [%l] %B%~%b % " #對於普通用戶,顯示“%”號。 endif endif
一種彩色的配置方案如下:
set cr = "%{\e[31m%}" #開始紅色
set cg = "%{\e[32m%}" #開始綠色
set c0 = "%{\e[0m%}" #恢復為默認色彩
# Set some variables for interactive shells
if ( $?prompt ) then
if ( "$uid" == "0" ) then
set prompt = "%B%U%n%u@%m.$cr%l$c0%b %c2 %B%#%b "
else
set prompt = "%B%U%n%u@%m.$cg%l$c0%b %c2 %B%%%b "
endif
endif
顏色代碼:
1 for brighter colors
4 for underlined text
5 for flashing text
30 for black foreground
31 for red foreground
32 for green foreground
33 for yellow (or brown) foreground
34 for blue foreground
35 for purple foreground
36 for cyan foreground
37 for white (or gray) foreground
40 for black background
41 for red background
42 for green background
43 for yellow (or brown) background
44 for blue background
45 for purple background
46 for cyan background
47 for white (or gray) background
查看更多參數,及其作用:
man tcsh #查看man手冊 /%/ #搜索到“%/”開始的地方
環境變量等
你在抱怨 FreeBSD下的 ls 沒有顯示顏色, grep 出來的東西沒有高亮嗎? 那么你需要如下的配置:
#讓 ls 鮮艷些 setenv LSCOLORS ExGxFxdxCxegedabagExEx setenv CLICOLOR yes #讓 grep 匹配到的字符高亮 setenv GREP_OPTIONS --color=auto
對於在KDE下使用fcitx的人,需要如下三行設置,
其實就是fcitx安裝完后所提示的內容,如果你夠細心的話。
setenv XMODIFIERS @im=fcitx setenv QT_IM_MODULE xim setenv GTK_IM_MODULE xim
嗯, ls 有顏色了,但是等等,為何 tab 不能補全?
你需要如下配置:
set autolist
如果命令輸錯了,讓csh/tcsh 為你糾正:
set correct = cmd
為了在命令行啟動某個游戲,或者kde程序,例如dolphin、kcalc,
你需要加兩個路徑到$path中去:
/usr/games /usr/local/kde4/bin/
set path = (/sbin /bin /usr/sbin /usr/local/bin /usr/games /usr/local/sbin /usr/bin $HOME/bin /usr/local/kde4/bin/)
黑魔法防御術
重定向防御
重定向很強大,我們有時候會運行諸如“date » b.txt”,“ls -l > files.txt”等命令。
然而如果一不小心,把“»”輸成“>”會造成什么后果呢?
為此,tcsh提供了noclobber這個選項:
set noclobber
有了它,悲劇就不會發生。如果“>”的目標文件已存在,tcsh會拒絕重定向。
覆蓋防御
是否遇到過“mv a b”,從而把有用的b文件覆蓋掉了?
為此,我們要讓mv和cp的行為更謹慎:
alias mv 'mv -i' alias cp 'cp -i'
如果目標文件已存在,mv和cp會拒絕操作,除非使用參數“-f”。
誤刪防御
rm這個命令自從誕生起,就一直是個危險的操作。
我們可以讓rm更溫和:
alias rm 'rm -i'
這樣rm之前,會要求再次確認。
一切皆alias
前面,我們在黑魔法防御術中已經初步見識了alias。
alias不僅可以避免危險操作,還可以簡化命令,自創命令。
除非極短,否則良好的alias命名,應當以某個統一的單詞或字母開頭,
例如下面即將展示的reload/edit系列、update系列、show系列等。
先展示最基本的alias,並逐條解釋。
alias .. 'cd ..' #兩點即可回到上級目錄 alias - 'cd -' #一杠返回上次的目錄 alias q 'exit' #退出登錄 alias rm 'rm -i' #誤刪防御 alias del 'rm -r' #刪除整個目錄 alias mv 'mv -i' #覆蓋防御 alias cp 'cp -i' #覆蓋防御 alias ls 'ls -I' #root狀態下,默認不顯示隱藏文件(.*)。BSD的ls很特殊,root默認顯示所有文件。 alias la 'ls -a' #顯示所有文件 alias ll 'ls -h -l' #顯示文件權限和大小(以合理的單位) alias lr 'ls -R' #遞歸顯示目錄 alias dh 'df -h -a -T' #以合適的單位顯示所有磁盤的剩余空間,以及文件系統類型(如ufs、devfs、procfs)。 alias ds 'du -sh' #以合適的單位顯示查看每個文件/文件夾的大小
find/wc系列。快速查找當前目錄下的所有c/cxx/python源碼文件。結合wc可以統計行數。
alias find-c 'find . -name "*.h" -o -name "*.c"' alias find-x 'find . -name "*.h" -o -name "*.hpp" -o -name "*.cpp" -o -name "*.cxx"' alias find-py 'find . -name ".py"' alias wc-c 'find . -name "*.h" -o -name "*.c" | xargs wc | sort -k 4' alias wc-x 'find . -name "*.h" -o -name "*.hpp" -o -name "*.cpp" -o -name "*.cxx" | xargs wc | sort -k 4' alias wc-py 'find . -name ".py" | xargs wc | sort -k 4'
reload/edit系列。實現快速修改,載入配置文件。
alias reload-rc.conf 'sh /etc/rc' alias reload-cshrc 'unalias * && source /etc/csh.cshrc' alias edit-xorg.conf 'vim /etc/xorg.conf' alias edit-csh.cshrc 'vim /etc/csh.cshrc' alias edit-make.conf 'vim /etc/make.conf' alias edit-kern.conf 'vim /etc/kernconf/thinkpad' alias edit-rc.conf 'vim /etc/rc.conf' alias edit-vimrc 'vim /usr/local/share/vim/vimrc'
set系列。快速設置locale。
alias setlocale-zhcn 'setenv LC_ALL zh_CN.UTF-8 && setenv LANG zh_CN.UTF-8' alias setlocale-c 'setenv LC_ALL C'
startx專用。
保持命令行下為英文locale(避免date等命令出現亂碼),而讓x環境為中文,適合手動startx而不是kdm的人。
alias sx 'setenv LC_ALL zh_CN.UTF-8 && setenv LANG zh_CN.UTF-8 && startx && setenv LC_ALL C'
make系列。快速編譯kernel/world。
alias make-world 'cd /usr/src && make buildworld && cd -' alias make-kernel 'cd /usr/src && make kernel KERNCONF=thinkpad && cd -' alias make-installworld 'cd /usr/src && make installworld && make delete-old && cd -'
show系列。查看狀態或某些信息。
alias show-ifstat 'systat -ifstat' #查看網絡接口的數據流量 alias show-geom 'gstat' #查看I/O狀態 alias show-thermal 'sysctl dev.acpi_ibm.0.thermal' #查看ThinkPad筆記本的各部分溫度 alias show-cpufreq 'sysctl dev.cpu.0.freq' #查看當前cpu頻率 alias show-cpulevels 'sysctl dev.cpu.0.freq_levels' #查看可用的cpu頻率 alias show-battery 'sysctl hw.acpi.battery.life && sysctl hw.acpi.battery.time' #查看電力 alias show-smartctl 'smartctl -a /dev/ad4' #需要安裝smartmontools,查看磁盤smart參數 alias show-alldep 'make all-depends-list' #需要在ports的安裝目錄下執行,顯示所有依賴 alias show-dep 'portmaster --show-work ./ | sort' #同上,且需要安裝portmaster,只顯示尚未安裝的依賴 alias show-ver 'pkg_version -v' #查看是否有軟件可更新
update系列。顧名思義,更新嘛。
alias update-locatedb '/usr/libexec/locate.updatedb' #更新locate數據庫 alias update-kernsrc 'csup -L 2 /etc/supfiles/stable-supfile' #同步kernel tree alias update-ports 'portsnap fetch update' #同步ports tree alias update-apps 'portmaster -a --force-config' #需要安裝portmaster,更新所有軟件,提示配置選項
雜項,均需要安裝第三方軟件才能用。
alias lt 'tree -N -C' #需要安裝tree。樹狀顯示目錄,-N可以保證中文顯示,-C使用彩色
alias l3 'tree -N -C -L 3' #目錄最多遞歸三級
alias l4 'tree -N -C -L 4' #四級
alias l5 'tree -N -C -L 5' #五級
alias l6 'tree -N -C -L 6' #六級
alias v 'vim' #不用說,我懶
alias m 'mocp' #控制台下的cs架構播放器
alias getdir 'wget -c -r -np -k' #遞歸下載目錄
alias ssh-home 'ssh raphael.vicp.cc -l root' #用root賬號登錄,結合key可以免輸密碼
alias ftp-home 'ftp ftp://syh:syh@raphael.vicp.cc' #BSD自帶的ftp,免輸賬號密碼。主機已被電信和工信部和諧,勿再試
alias lft-phome 'lftp raphael.vicp.cc -u syh,syh' #lftp的免輸賬號密碼。
alias scons 'scons -Q -j 4' #構建工具,默認4個線程進行
alias valgrind-checkmem 'valgrind --tool=memcheck --leak-check=full' #檢查內存泄漏
最好的教材
最好的教材莫過於man手冊,真的什么都有了。
man tcsh
##################
http://www.oschina.net/question/12_6576
一、選擇一個好SHELL
Unix 中常見的 shell 主要分為兩大門派:
sh:
burne shell (sh)
burne again shell (bash)
csh:
c shell (csh)
tc shell (tcsh)
korn shell (ksh)
本人的教學環境是 FreeBSD6.1 + sh ,你也可以使用bash來學習,bash兼容sh。我盡量將所有的SHELL語句也在Redhat上面驗證一下。
FreeBSD上bash的安裝方法有二:
1、pkg_add -r bash
2、cd /usr/ports/shell/bash2 && make install clean
Linux 上默認的SHELL已經是bash了。
查看自己機器上支持 Shell 種類的方法:
# cat /etc/shells
/bin/sh
/bin/csh
/bin/tcsh
/usr/local/bin/bash
設置自己的SHELL為sh
# chsh
# vipw
使用chsh命令會打開一個編輯器(類似vi),需要修改其中的Shell: /bin/csh一項為Shell: /bin/sh
使用vipw命令會打開一個編輯器(類似vi),需要修改指定用戶所在行的最后一項為/bin/sh
如果你是在FreeBSD上安裝了 bash ,一般修改為 /usr/local/bin/bash
二、SHELL基礎(UNIX中的常用命令)
[color=Red]列出目錄中的內容[/color]
ls
[color=Red]FreeBSD需要使用使用-G參數,才能按文件類型顯示為約定的顏色[/color]
ls -G
[color=Red]使用長格式,更出目錄中的內容[/color]
ls -l
[color=Red]顯示一個文本文件的內容[/color]
cat <文件名>
cat -n /etc/passwd (顯示文件,並加行號)
less <文件名>
more <文件名>
[color=Red]復制文件[/color]cp <源文件名> <目標文件名>
[color=Red]文件更名或移動文件至其他目錄[/color]
mv <文件名1> <文件名2>
mv <目錄1> <文件名> <目錄2> <文件名>
[color=Red]顯示當前工作的目錄[/color]
pwd
[color=Red]建立目錄(-p 建立多級目錄)[/color]
mkdir <目錄名>
mkdir -p <目錄1> / <目錄2>
[color=Red]刪除文件(或目錄)[/color]
rm <文件名>
rm -rf <目錄>
[color=Red]顯示時間和日期[/color]
date
[color=Red]顯示N天前的時間和日期[/color]
date -v -2d
[color=Red]其他格式請自己試一下,或查看手冊 man date[/color]
date +%F
date "+DATE: %Y-%m-%d%nTIME: %H:%M:%S"
[color=Red]顯示字符串[/color]
echo "hello c shell"
printf "hello c shell\n"
[color=Red]顯示帶顏色的字符串[/color]
echo -e "\e[31mRed String\e[0m"
printf "\e[31mRed String\e[0m\n"
具體的顏色代碼,請參考: http://www.51sincere.com/2006-11/20061123123521.htm