...
零,由于某种误操作,导致用户账户下的shell配置文件丢失被删除
一,你登录到对应主机后,默认使用的那种shell
$ echo $SHELL
$ pstree
$ pstree -up|grep sshd
二,bash,csh的全局配置,用户配置文件
三,配置对应的ORACLE_HOME,ORACLE_SID
export ORACLE_HOME=
export ORACLE_SID=
=====================================
四,参考资料:
随着在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-
大家要尊重俺的劳动成果,转载请注明出处。本文首发自
俺的百度空间以及俺的ITPUB博客也会同步更新
欢迎共同,交流,本人QQ:398467907 邮箱:
欢迎交换友情链接~~
===================================华丽的分割线=========================================
果然,事情永远不会一帆风顺,在连续出了N次故障后,今天,俺的 11g 终于不甘寂寞,再次的出来“兴风作浪”了。
今天的问题很简单,我登录进oracle用户以后,键入sqlplus出现如下错误:
--------------------------------------------------------------------------------
[oracle@zzb ~]$ sqlplus Command 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 . ~/.bashrcfi# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
unset USERNAMEORACLE_BASE=/u01
ORACLE_HOME=$ORACLE_BASE/oracleORACLE_SID=zzbPATH=$ORACLE_HOME/bin:$PATHexport 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 functionsif [ -f ~/.bashrc ]; then . ~/.bashrcfi# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
unset USERNAMEORACLE_BASE=/u01
ORACLE_HOME=$ORACLE_BASE/oracleORACLE_SID=zzbPATH=$ORACLE_HOME/bin:$PATHexport 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
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=zzbORACLE_BASE=/u01ORACLE_HOME=/u01/oracle[oracle@zzb ~]$
--------------------------------------------------------------------------------
大家可以看到,现在一切正常了。然后再次输入: --------------------------------------------------------------------------------[oracle@zzb ~]$ source .bash_profile
[oracle@zzb ~]$
--------------------------------------------------------------------------------
这次没报错,然后我就:
--------------------------------------------------------------------------------
[oracle@zzb ~]$ sqlplus /nologSQL*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> startupORACLE instance started.Total System Global Area 313860096 bytes
Fixed Size 1299624 bytesVariable Size 226495320 bytesDatabase Buffers 79691776 bytesRedo Buffers 6373376 bytesDatabase 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/passwdroot:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinsync:x:5:0:sync:/sbin:/bin/syncshutdown:x:6:0:shutdown:/sbin:/sbin/shutdownhalt:x:7:0:halt:/sbin:/sbin/haltmail:x:8:12:mail:/var/spool/mail:/sbin/nologinnews:x:9:13:news:/etc/news:/sbin/nologinuucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologinoperator:x:11:0:operator:/root:/sbin/nologingames:x:12:100:games:/usr/games:/sbin/nologingopher:x:13:30:gopher:/var/gopher:/sbin/nologinftp:x:14:50:FTP User:/var/ftp:/sbin/nologinnobody:x:99:99:Nobody:/:/sbin/nologindbus:x:81:81:System message bus:/:/sbin/nologinvcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologinrpm:x:37:37::/var/lib/rpm:/sbin/nologinhaldaemon:x:68:68:HAL daemon:/:/sbin/nologinnetdump:x:34:34:Network Crash Dump user:/var/crash:/bin/bashnscd:x:28:28:NSCD Daemon:/:/sbin/nologinsshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologinrpc:x:32:32:Portmapper RPC user:/:/sbin/nologinmailnull:x:47:47::/var/spool/mqueue:/sbin/nologinsmmsp:x:51:51::/var/spool/mqueue:/sbin/nologinrpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologinnfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologinpcap:x:77:77::/var/arpwatch:/sbin/nologin:x:48:48:Apache:/var/www:/sbin/nologinsquid:x:23:23::/var/spool/squid:/sbin/nologinwebalizer:x:67:67:Webalizer:/var/www/usage:/sbin/nologinxfs:x:43:43:X Font :/etc/X11/fs:/sbin/nologinntp:x:38:38::/etc/ntp:/sbin/nologingdm:x:42:42::/var/gdm:/sbin/nologinpegasus:x:66:65:tog-pegasus OpenPegasus WBEM/CIM services:/var/lib/Pegasus:/sbin/nologinhtt:x:100:103:IIIMF Htt:/usr/lib/im:/sbin/nologinnamed:x:25:25:Named:/var/named:/sbin/nologindovecot:x:97:97:dovecot:/usr/libexec/dovecot:/sbin/nologinerazy0:x:500:500:erazy0:/home/erazy0:/bin/bashoracle:x:501:501::/u01/oracle:/bin/csh <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<注意这行[root@zzb ~]# vi /etc/passwdroot:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinsync:x:5:0:sync:/sbin:/bin/syncshutdown:x:6:0:shutdown:/sbin:/sbin/shutdownhalt:x:7:0:halt:/sbin:/sbin/haltmail:x:8:12:mail:/var/spool/mail:/sbin/nologinnews:x:9:13:news:/etc/news:/sbin/nologinuucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologinoperator:x:11:0:operator:/root:/sbin/nologingames:x:12:100:games:/usr/games:/sbin/nologingopher:x:13:30:gopher:/var/gopher:/sbin/nologinftp:x:14:50:FTP User:/var/ftp:/sbin/nologinnobody:x:99:99:Nobody:/:/sbin/nologindbus:x:81:81:System message bus:/:/sbin/nologinvcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologinrpm:x:37:37::/var/lib/rpm:/sbin/nologinhaldaemon:x:68:68:HAL daemon:/:/sbin/nologinnetdump:x:34:34:Network Crash Dump user:/var/crash:/bin/bashnscd:x:28:28:NSCD Daemon:/:/sbin/nologinsshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologinrpc:x:32:32:Portmapper RPC user:/:/sbin/nologinmailnull:x:47:47::/var/spool/mqueue:/sbin/nologinsmmsp:x:51:51::/var/spool/mqueue:/sbin/nologinrpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologinnfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologinpcap:x:77:77::/var/arpwatch:/sbin/nologinapache:x:48:48:Apache:/var/www:/sbin/nologinsquid:x:23:23::/var/spool/squid:/sbin/nologinwebalizer:x:67:67:Webalizer:/var/www/usage:/sbin/nologinxfs:x:43:43:X Font Server:/etc/X11/fs:/sbin/nologinntp:x:38:38::/etc/ntp:/sbin/nologingdm:x:42:42::/var/gdm:/sbin/nologinpegasus:x:66:65:tog-pegasus OpenPegasus WBEM/CIM services:/var/lib/Pegasus:/sbin/nologinhtt:x:100:103:IIIMF Htt:/usr/lib/im:/sbin/nologinnamed:x:25:25:Named:/var/named:/sbin/nologindovecot:x:97:97:dovecot:/usr/libexec/dovecot:/sbin/nologinerazy0:x:500:500:erazy0:/home/erazy0:/bin/bashoracle: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.
########################
【】ORA-12162: TNS:net service name is incorrectly specified
本文将给大家阐述一个因未设置系统环境变量ORACLE_SID导致ORA-12162错误的案例。希望大家有所思考。1.获得有关ORA-12162报错信息的通用表述信息[oracle@asdlabdb01 ~]$ oerr 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/sysSQL*Plus: Release 10.2.0.3.0 - Production on Sat Aug 27 22:54:02 2010Copyright (c) 1982, 2006, Oracle. All Rights Reserved.ERROR:ORA-12162: TNS:net service name is incorrectly specifiedEnter user-name:2)使用sysdba身份登陆会得到同样的错误信息[oracle@asdlabdb01 ~]$ sqlplus / as sysdbaSQL*Plus: Release 10.2.0.3.0 - Production on Sat Aug 27 22:54:48 2010Copyright (c) 1982, 2006, Oracle. All Rights Reserved.ERROR:ORA-12162: TNS:net service name is incorrectly specifiedEnter user-name:3)但此时,如果使用服务名方式连接数据库,是可以成功的,这也是该问题现象的诡异之处。[oracle@asdlabdb01 ~]$ sqlplus system/sys@ora10gSQL*Plus: Release 10.2.0.3.0 - Production on Sat Aug 27 22:53:41 2010Copyright (c) 1982, 2006, Oracle. All Rights Reserved.Connected to:Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit ProductionWith the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine optionssystem@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_SIDora10g[oracle@asdlabdb01 ~]$ sqlplus / as sysdbaSQL*Plus: Release 10.2.0.3.0 - Production on Sat Aug 27 23:27:34 2010Copyright (c) 1982, 2006, Oracle. All Rights Reserved.Connected to:Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit ProductionWith the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine optionssys@ora10g>OK,此时问题处理完毕。5.小结这个案例给我们的启迪是什么?1)系统默认的错误提示信息有时不具有参考价值。而且,某些情况下这些错误提示还可能给我们带来误导。原因很简单,系统默认的错误提示信息不可能囊括所有故障现象;2)任何系统级别的设置问题都有可能导致数据库系统出现异常;3)在遇到故障的时候,我们需要沉着冷静。有些时候可能需要我们Check最原始的信息,切莫想当然。建议:为了避免出现文章中提到的问题,第一,可以将ORACLE_SID等环境变量写入到系统profile中,但需要确保系统profile文件内容的有效性;第二,不在profile中进行填写,每次登录数据库服务器时手工完成数据库环境变量的指定,这种方法虽然增加了键盘的敲击,但它更直观、更有保障。Good luck.10.08.27-- The End --
#############################
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命令一切正常。
#############################################
选择 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。综上,脚本能力忽略不计。![:-x](http://wiki.freebsdchina.org/lib/images/smileys/icon_silenced.gif)
好了,说了这么多大不敬的话,我们开始切入正题。
配置文件
全局配置文件 /etc/csh.cshrc
个人配置文件 ~/.cshrc或~/.tcshrc为了方便,建议修改全局性的配置文件,这样每个账号都可以享受便利。
按键绑定
通常,我们不设置按键绑定也能很好地工作,
但是对于远程登录,可能需要一些额外的配置。比如,为了避免putty登录后,Home、End、Delete等变成~,你需要如下配置:bindkey '\e[1~' beginning-of-line # Homebindkey '\e[3~' delete-char # Deletebindkey '\e[4~' end-of-line # Endbindkey "^W" backward-delete-word # Deletebindkey -k up history-search-backward # PageUpbindkey -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 % " #对于普通用户,显示“%”号。 endifendif
Konsole中的效果如下:
一种彩色的配置方案如下:
set cr = "%{\e[31m%}" #开始红色set cg = "%{\e[32m%}" #开始绿色set c0 = "%{\e[0m%}" #恢复为默认色彩# Set some variables for interactive shellsif ( $?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 " endifendif
Konsole中的效果如下:
颜色代码:
1 for brighter colors4 for underlined text5 for flashing text30 for black foreground31 for red foreground32 for green foreground33 for yellow (or brown) foreground34 for blue foreground35 for purple foreground36 for cyan foreground37 for white (or gray) foreground40 for black background41 for red background42 for green background43 for yellow (or brown) background44 for blue background45 for purple background46 for cyan background47 for white (or gray) background查看更多参数,及其作用:
man tcsh #查看man手册/%/ #搜索到“%/”开始的地方
环境变量等
你在抱怨 FreeBSD下的 ls 没有显示颜色, grep 出来的东西没有高亮吗? 那么你需要如下的配置:
#让 ls 鲜艳些setenv LSCOLORS ExGxFxdxCxegedabagExExsetenv CLICOLOR yes#让 grep 匹配到的字符高亮setenv GREP_OPTIONS --color=auto
对于在KDE下使用fcitx的人,需要如下三行设置,
其实就是fcitx安装完后所提示的内容,如果你够细心的话。setenv XMODIFIERS @im=fcitxsetenv QT_IM_MODULE ximsetenv 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 treealias update-ports 'portsnap fetch update' #同步ports treealias 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 ##################
一、选择一个好SHELL
Unix 中常见的 shell 主要分为两大门派: sh:burne shell (sh) burne again shell (bash)
c shell (csh) tc shell (tcsh) korn shell (ksh)
1、pkg_add -r bash 2、cd /usr/ports/shell/bash2 && make install clean
/bin/sh /bin/csh /bin/tcsh /usr/local/bin/bash
# chsh # vipw