Linux系统下选择自己喜欢的vim配色方案

vi ~/.vimrc

加一行

colorscheme zenburn

/usr/share/vim/vim*/colors 目录下有很多配色方案,如果没有自己喜欢的方案,可以去

http://www.vim.org/search.php

搜索配色方案,下载后保存在/usr/share/vim/vim63/colors目录中或者~/.vim/colors目录中即可

如果终端用SecureCRT登陆,需要在会话选项中设置终端仿真为ANSI或者Linux,并且打开颜色方案。

40 Basic Linux Command-line Tips and Tricks

1.  Everything in Linux is a file including the hardware and even the directories.

2. # : Denotes the super(root) user

3.  : Denotes the normal user

4.  /root: Denotes the super user’s directory

/home: Denotes the normal user’s directory.

5.  Switching between Terminals

§  Ctrl + Alt + F1-F6: Console login

§  Ctrl + Alt + F7: GUI login

6.  The Magic Tab: Instead of typing the whole filename if the unique pattern for a particular file is given then the remaining characters need not be typed and can be obtained automatically using the Tab button.

7.   ~(Tilde): Denotes the current user’s home directory

8.   Ctrl + Z: To stop a command that is working interactively without terminating it.

9.  Ctrl + C: To stop a command that is not responding. (Cancellation).

10.  Ctrl + D: To send the EOF( End of File) signal to a command normally when you see ‘>’.

11.  Ctrl + W: To erase the text you have entered a word at a time.

12.  Up arrow key: To redisplay the last executed command. The Down arrow key can be used to print the next command used after using the Up arrow key previously.

13.  The history command can be cleared using a simple option –c (clear).

14.  cd :   The cd command can be used trickily in the following ways:

cd : To switch to the home user

cd * : To change directory to the first file in the directory (only if the first file is a directory)

cd .. : To move back a folder

cd – : To return to the last directory you were in

15.  Files starting with a dot (.) are a hidden file.

16.   To view hidden files: ls -a

17.   ls: The ls command can be use trickily in the following ways:

ls -lR : To view a long list of all the files (which includes directories) and their subdirectories recursively .

ls *.* : To view a list of all the files with extensions only.

18.   ls -ll: Gives a long list in the following format

drwxr-xr-x 2 root root 4096 2010-04-29 05:17 bin where

drwxr-xr-x : permission where d stands for directory, rwx stands for owner privilege, r-x stands for the group privilege and r-x stands for others permission respectively.

Here r stands for read, w for write and x for executable.

2=> link count

root=>owner

root=>group

4096=> directory size

2010-04-29=>date of creation

05:17=> time of creation

bin=>directory file(in blue)

The color code of the files is as follows:

Blue: Directory file

White: Normal file

Green: Executable file

Yellow: Device file

Magenta: Picture file

Cyan: link file

Red: Compressed file

File Symbol

-(Hyphen) : Normal file

d=directory

l=link file

b=Block device file

c=character device file

19.  Using the rm command: When used without any option the rm command deletes the file or directory ( option –rf) without any warning. A simple mistake like rm / somedir instead of rm /somedir can cause major chaos and delete the entire content of the /(root) directory. Hence it is always advisable to use rm command with the –i(which prompts before removal) option. Also there is no undelete option in Linux.

20.  Copying hidden files: cp .* (copies hidden files only to a new destination)

21. dpkg -l : To get a list of all the installed packages.

23. Use of ‘ > ‘ and ‘ >> ‘ : The ‘ > ‘ symbol ( input redirector sign) can be used to add content to a file when used with the cat command. Whereas ‘ >> ‘ can be used to append to a file. If the ‘ >> ‘ symbol is not used and content is added to a file using only the ‘>’ symbol the previous content of the file is deleted and replaced with the new content.

e.g: $ touch text (creates an empty file)

$ cat >text

This is text’s text. ( Save the changes to the file using Ctrl +D)

$cat >> text

This is a new text. (Ctrl + D)

 

Output of the file:

This is text’s text.

This is a new text.

23.  To count the number of users logged in : who |wc –l

24.  cat:  The cat command can be used to trickly in the following way:

– To count no. of lines from a file : cat <filename> |wc -l

– To count no. of words from a file : cat <filename> |wc -w

– To count no. of characters from a file : cat <filename> |wc –c

25.  To search a term that returns a pattern: cat <filename> |grep [pattern]

26.  The ‘tr’ command: Used to translate the characters of a file.

tr ‘a-z’ ‘A-Z’ <text >text1 : The command for example is used to translate all the characters from lower case to upper case of the ‘text’ file and save the changes to a new file ‘text1′.

 

27.  File permission using chmod: ‘chmod’ can be used directly to change the file permission of files in a simple way by giving the permission for root, user and others in a numeric form where the numeric value are as follows:

r(read-only)=>4

w(write)=>2

x(executable)=>1

e.g. chmod 754 text will change the ownership of owner to read, write and executable, that of group to read and executable and that of others to read only of the text file.

28.  more: It is a filter for paging through text one screenful at a time.

Use it with any of the commands after the pipe symbol to increase readability.

e.g. ls -ll |more

29.  cron : Daemon to execute scheduled commands. Cron enables users to schedule jobs (commands or shell scripts) to run periodically at certain times or dates.

1 * * * * echo “hi” >/dev/tty1 displays the text “hi” after every 1 minute in tty1

.—————- minute (0 – 59)

| .————- hour (0 – 23)

| | .———- day of month (1 – 31)

| | | .——- month (1 – 12) OR jan,feb,mar,apr …

| | | | .—– day of week (0 – 7) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat

* * * * * command to be executed

Source of example: Wikipedia

30.  fsck: Used for file system checking. On a non-journaling file system the fsck command can take a very long time to complete. Using it with the option -c displays a progress bar which doesn’t increase the speed but lets you know how long you still have to wait for the process to complete.

e.g. fsck -C

31.  To find the path of the commandwhich command

e.g. which clear

32. Setting up alias: Enables a replacement of a word with another string. It is mainly used for abbreviating a system command, or for adding default arguments to a regularly used command

e.g. alias cls=’clear’ => For buffer alias of clear

33.  The du (disk usage) command can be used with the option -h to print the space occupied in human readable form. More specifically it can be used with the summation option (-s).

e.g. du -sh /home summarizes the total disk usage by the home directory in human readable form.

34.  Two or more commands can be combined with the && operator. However the succeeding command is executed if and only if the previous one is true.

e.g. ls && date lists the contents of the directory first and then gives the system date.

35.  Surfing the net in text only mode from the terminal: elinks [URL]

e.g: elinks www.google.com

Note that the elinks package has to be installed in the system.

36.  The ps command displays a great more deal of information than the kill command does.

37.  To extract a no. of lines from a file:

e.g head -n 4 abc.c is used to extract the first 4 lines of the file abc.c

e.g tail -n 4 abc.c is used to extract the last 4 lines of the file abc.c

38.  Any changes to a file might cause loss of important data unknowingly. Hence    Linux creates a file with the same name followed by ~ (Tilde) sign without the recent changes. This comes in really handy when playing with the configuration files as some sort of a backup is created.

39.   A variable can be defined with an ‘=’ operator. Now a long block of text can be assigned to the variable and brought into use repeatedly by just typing the variable name preceded by a $ sign instead of writing the whole chunk of text again and again.

e.g ldir=/home/my/Desktop/abc

cp abcd $ldir copies the file abcd to /home/my/Desktop/abc.

40. To find all the files in your home directory modified or created today:

e.g. find ~ -type f -mtime 0

Quartz Cron Expression

一个Cron-表达式是一个由六至七个字段组成由空格分隔的字符串,其中6个字段是必须的而一个是可选的,如下:

字段名     允许的值     允许的特殊字符
秒     0-59     , – * /
分     0-59     , – * /
小时     0-23     , – * /
日     1-31     , – * ? / L W C
月     1-12 or JAN-DEC     , – * /
周几     1-7 or SUN-SAT     , – * ? / L C #
年 (可选字段)     empty, 1970-2099     , – * /

‘*’ 字符可以用于所有字段,在“分”字段中设为”*”表示”每一分钟”的含义。

‘?’ 字符可以用在“日”和“周几”字段. 它用来指定 ‘不明确的值’. 这在你需要指定这两个字段中的某一个值而不是另外一个的时候会被用到。在后面的例子中可以看到其含义。

‘-‘ 字符被用来指定一个值的范围,比如在“小时”字段中设为”10-12″表示”10点到12点”.

‘,’ 字符指定数个值。比如在“周几”字段中设为”MON,WED,FRI”表示”the days Monday, Wednesday, and Friday”.

‘/’ 字符用来指定一个值的的增加幅度. 比如在“秒”字段中设置为”0/15″表示”第0, 15, 30, 和 45秒”。而 “5/15″则表示”第5, 20, 35, 和 50″. 在’/’前加”*”字符相当于指定从0秒开始. 每个字段都有一系列可以开始或结束的数值。对于“秒”和“分”字段来说,其数值范围为0到59,对于“小时”字段来说其为0到23, 对于“日”字段来说为0到31, 而对于“月”字段来说为1到12。”/”字段仅仅只是帮助你在允许的数值范围内从开始”第n”的值。 因此 对于“月”字段来说”7/6″只是表示7月被开启而不是“每六个月”, 请注意其中微妙的差别。

‘L’字符可用在“日”和“周几”这两个字段。它是”last”的缩写, 但是在这两个字段中有不同的含义。例如,“日”字段中的”L”表示”一个月中的最后一天” —— 对于一月就是31号对于二月来说就是28号(非闰年)。而在“周几”字段中, 它简单的表示”7″ or “SAT”,但是如果在“周几”字段中使用时跟在某个数字之后, 它表示”该月最后一个星期×” —— 比如”6L”表示”该月最后一个周五”。当使用’L’选项时,指定确定的列表或者范围非常重要,否则你会被结果搞糊涂的。

‘W’ 可用于“日”字段。用来指定历给定日期最近的工作日(周一到周五) 。比如你将“日”字段设为”15W”,意为: “离该月15号最近的工作日”。因此如果15号为周六,触发器会在14号即周五调用。如果15号为周日, 触发器会在16号也就是周一触发。如果15号为周二,那么当天就会触发。然而如果你将“日”字段设为”1W”, 而一号又是周六, 触发器会于下周一也就是当月的3号触发,因为它不会越过当月的值的范围边界。’W’字符只能用于“日”字段的值为单独的一天而不是一系列值的时候。

‘L’和’W’可以组合用于“日”字段表示为’LW’,意为”该月最后一个工作日”。

‘#’ 字符可用于“周几”字段。该字符表示“该月第几个周×”,比如”6#3″表示该月第三个周五( 6表示周五而”#3″该月第三个)。再比如: “2#1” = 表示该月第一个周一而 “4#5” = 该月第五个周三。注意如果你指定”#5″该月没有第五个“周×”,该月是不会触发的。

‘C’ 字符可用于“日”和“周几”字段,它是”calendar”的缩写。 它表示为基于相关的日历所计算出的值(如果有的话)。如果没有关联的日历, 那它等同于包含全部日历。“日”字段值为”5C”表示”日历中的第一天或者5号以后”,“周几”字段值为”1C”则表示”日历中的第一天或者周日以后”。

对于“月份”字段和“周几”字段来说合法的字符都不是大小写敏感的。

下面是一些完整的例子:

表达式     含义
“0 0 12 * * ?”     每天中午十二点触发
“0 15 10 ? * *”     每天早上10:15触发
“0 15 10 * * ?”     每天早上10:15触发
“0 15 10 * * ? *”     每天早上10:15触发
“0 15 10 * * ? 2005”     2005年的每天早上10:15触发
“0 * 14 * * ?”     每天从下午2点开始到2点59分每分钟一次触发
“0 0/5 14 * * ?”     每天从下午2点开始到2:55分结束每5分钟一次触发
“0 0/5 14,18 * * ?”     每天的下午2点至2:55和6点至6点55分两个时间段内每5分钟一次触发
“0 0-5 14 * * ?”     每天14:00至14:05每分钟一次触发
“0 10,44 14 ? 3 WED”     三月的每周三的14:10和14:44触发
“0 15 10 ? * MON-FRI”     每个周一、周二、周三、周四、周五的10:15触发
“0 15 10 15 * ?”     每月15号的10:15触发
“0 15 10 L * ?”     每月的最后一天的10:15触发
“0 15 10 ? * 6L”     每月最后一个周五的10:15触发
“0 15 10 ? * 6L”     每月最后一个周五的10:15触发
“0 15 10 ? * 6L 2002-2005”     2002年至2005年的每月最后一个周五的10:15触发
“0 15 10 ? * 6#3”     每月的第三个周五的10:15触发
———————————————
Field Name  Mandatory?  Allowed Values  Allowed Special Characters
Seconds     YES         0-59             , – * /
Minutes     YES         0-59             , – * /
Hours       YES         0-23             , – * /
Day of month  YES       1-31             , – * ? / L W C
Month         YES        1-12 or JAN-DEC  , – * /
Day of week   YES        1-7 or SUN-SAT   , – * ? / L C #
Year          NO  empty, 1970-2099        , – * /

项目实例:
second  minute  hours  dayOfMonth  month  dayOfWeek  year
每月         0            0           6              ?                    *                6#3            ?
每周        59           59         18            ?                    *                1                ?
自定义    28          47          9             30                 7                ?             2006

每月:每个月的第三个星期五的上午6:00:00 触发
每周:每周的星期日的下午18:59:59 触发
自定义:2006年7月30日上午9:47:28 触发

所有星号对应的段位置,都可以出现后面的符号(, – * /)
(? / L C)这些符号可以出现在”一月哪天”和”星期”段位置
(w)只能出现在”一月哪天”段位置
(#)只能出现在”星期”段位置

解释符号代表的意思:
* 代表任意合法的字段
0 * 17 * * ? :表示在每天的5 PM 到 5:59之间的每一分钟启动scheduler

? 表示没值被指定
如果同时指定”一月哪天”和”星期”,可能两者对应不起来
0 0,15,30,45 * * * ? :表示每刻钟启动scheduler
所以推荐用法是其中一个指定值,另一个用?指定

/ 表示时间的增量
0 0/15 * * * ? :表示每刻钟启动scheduler

– 表示值的范围
0 45 3-8 ? * *

L 如果用在”一月哪天”段上,表示一个月的最后一天;如果用在”星期”段上。表示一个星期的最后一天(星期六)
0 0 8 L * ? :表示每个月最后一天的8点启动scheduler

W 表示最靠近给定时间的一天,(必须是星期一到星期五)

# 例如 6#3表示一个月的第三个星期五

CentOS设置程序开机自启动的方法

在CentOS系统下,主要有两种方法设置自己安装的程序开机启动。
1、把启动程序的命令添加到/etc/rc.d/rc.local文件中,比如下面的是设置开机启动httpd。

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
/usr/local/apache/bin/apachectl start

2、把写好的启动脚本添加到目录/etc/rc.d/init.d/,然后使用命令chkconfig设置开机启动。
例如:我们把httpd的脚本写好后放进/etc/rc.d/init.d/目录,使用

chkconfig --add httpd
chkconfig httpd on

命令即设置好了开机启动。