linux中Cent OS SVN 服务配置学习笔记linux操作系统
“陈锦”通过精心收集,向本站投稿了9篇linux中Cent OS SVN 服务配置学习笔记linux操作系统,以下是小编整理后的linux中Cent OS SVN 服务配置学习笔记linux操作系统,希望能够帮助到大家。
篇1:linux中Cent OS SVN 服务配置学习笔记linux操作系统
这是一自己在配置Cent OS SVN 的一些笔记有需要的朋友可参考一下,
最近研究了下在Cent OS上配置SVN服务及版本库权限设置,下面是我的配置笔记
#安装SVN
yum -y install subversion
#测试SVN是否已经安装好
svn
#创建svn版本库文件夹
mkdir /var/local/svn/
# 编辑自系统启动文件
vi /etc/rc.local
把光标用方向键移动到一个空行
按i输入下面语句
(如果有没有空行,把光标放在任意行按o)
svnserve -d -r /var/local/svn/
按esc,再输入:wq保存退出
启动svn服务
svnserve -d -r /var/local/svn/
=== 创建版本库 ===
#创建新版本库test
svnadmin create /var/local/svn/test
==================
== 配置版本库权限 ==
# 进入版本库配置文件目录
cd /var/local/svn/test/conf
编辑基本权限文件
vi svnserve.conf
输入:%d a清空文件内容
再按i进入编辑模式,输入
[general]
password-db = passwd
anon-access = none
auth-access = write
authz-db = authz
按esc输入:wq保存并退出编辑器
配置用户和密码
vi passwd
按i进入编辑模式按照下列格式输入用户名和密码
[users]
用户名 = 密码
例如:
[users]
echo = 123456
peter = 8888888
colt = 7788414
按esc输入:wq保存并退出编辑器
配置用户访问权限
vi authz
按照下列模板输入分组信息
[groups]
组名 = 用户名,用户名...
举例
[groups]
manager = echo
developer = colt, echo
client = peter
版本库路径及权限设置
格式
[版本库名称:版本库内部文件夹路径]
@组名称 = 读写权限(r读,w写,rw读写)
* = r (全局读写权限)
举例,版本库根目录
[test:/]
@manager = rw
@developer = rw
* = r
举例,用户反馈目录
[test:/feedback]
@client = rw
* = r
编辑完后文件的所有内容应该如下:
[groups]
manager = echo
developer = colt, echo
client = peter
[test:/]
@manager = rw
@developer = rw
* = r
[test:/feedback]
@client = rw
* = r
编辑完毕后按esc输入:wq保存并退出编辑器
客户端checkout svn版本库地址
svn://服务器IP地址:3690/版本库名
例如
svn://192.168.1.1:3690/test
篇2:linux中echo学习笔记linux操作系统
文章来介绍一下关于linux中echo的用法介绍,echo是一个非常简单、直接的LINUX命令,
先介绍一下标准的command line ,它包含三个部件:
command_name option argument
好的,回来,echo就是将argument送出至标准输出(STDOUT),通常就是送到显示器输出。
还是直接跑一下来看看echo命令吧:
是不是觉得奇怪怎么就一个空白行,就回到shell prompt(就是$)上了。
原因就是因为echo在预设上,在显示完argument之后,还会送出一个换行符号。
但是上面的command并没有任何的argument,所以就只有一个换行符号了。
如果觉得不爽,想取消这个换行符号,好说,-n option 就完全可以帮你搞定:
这下舒服了吧,其实echo除了 -n option 之外,还有一些常用选项,如:
-e :启动反斜线控制字符的转换
-E:关闭反斜线控制字符的转换(注意跟上面的不同哦)
-n :取消行末的换行符号 (与 -e 选项下的 c 字符功能相同)
关于 echo 命令所支持的反斜线控制字符如下表:
a:ALERT / BELL (从系统喇叭送出铃声)
b:BACKSPACE ,也就是向左?h除?
c:取消行末的换行符号
E:ESCAPE,跳脱键
f:FORMFEED,换页字符
n:NEWLINE,换行字符
r:RETURN,回车键
t:TAB,表格跳位键
v:VERTICAL TAB,垂直表格跳位键
n:ASCII 八进制编码(以 x 开始为十六进制)
\ :反斜线本身
Ok,有了这些我们就可以输出下面的命令来看看echo的强大了:
上面两个有什么不同呢???试着分析一下吧……
…………………………
有没有想起大学谭浩强的C语言呢?
…………………………….
因为啊,e 字母后面是?h除键(b),因此输出结果就没有 e 了,
在结束时听到一声铃响,别担心,那是 a 的杰作!
由于同时使用了-n 选项,因此 shell prompt 紧接着在第二行之后。
若你不用 -n 的话,还有什么方法呢?……….(在 a 后再加个 c )。
在日后的 shell 操作及 shell script. 设计上,echo 命令是最常被使用的
命令之一。
先小试牛刀,用 echo 来检查变量值:
……(这个变量的事,在以后会向大家娓娓道来)
ok,更多的关于 command line 的格式,以及 echo 命令的选项,
1)echo显示字符串
普通字符串可以在echo后直接输入字符串,但这样当要输出某些字符如“时会有问题(这种写法的时候”是被当作继行符处理过滤掉的,要输出一个“必须打 ”“,跟c语言printf输出的要求相象),所以一般最好用´string´ 或”string“的格式,这样即使是”也可以输出,方便直观。
#echo hello world
hello world
#echo hello“ world
hello world
#echo hello”“ world
hello” world
#echo ´hello“” world´ 或者: echo “hello”“ world”
hello“” world
2)echo的转义显示: 加上-e参数
输出多行
#echo -e ´hello“nworld´
hello
world
输出ascii字符: echo -e ”NNN (NNN为ascii字符的八进制码号,不符合八进制的将会按照字面意义进行打印)
#echo -e ´“61 ”62 “101 ”141´
1 2 A a
篇3:linux中ubuntu server学习笔记linux操作系统
本人总结了一些关于linux中ubuntu server学习笔记,有需要了解学习的朋友可参考参考,
1、解决中文乱码问题。本来想为了方便使用系统,特意选择了中文安装,结果命令行中的中文显示一堆方格符号,既然是玩 server 系统,那还是用英文吧。修改内容:
sudo vim /var/lib/locales/supported.d/local
只保留:en_US.UTF-8 UTF-8
sodu vim /etc/default/locale
把下面内容:
LANG=”zh_CN.UTF-8″
LANGUAGE=”zh_CN:zh”
修改为:
LANG=”en_US.UTF-8″
LANGUAGE=”en_US:en”
最后重启系统。
2、vim 使用方法:按 i 进入编辑模式,按 esc 退出编辑模式,:w 保存内容但不退出 vim 编辑器,:wq 保存内容并退出 vim 编辑器,:q 未修改过内容时退出 vim 编辑器,:q! 放弃编辑过的内容强制退出 vim 编辑器。
3、重启命令:reboot,shutdown -r now;关机命令:halt,poweroff,shutdown -h now
4、设置权限:sudo chmod -R 777 /var/www (开启www的读写权限)
sudo chmod 600 ××× (只有所有者有读和写的权限)
sudo chmod 644 ××× (所有者有读和写的权限,组用户只有读的权限)
sudo chmod 700 ××× (只有所有者有读和写以及执行的权限)
sudo chmod 666 ××× (每个人都有读和写的权限)
sudo chmod 777 ××× (每个人都有读和写以及执行的权限)
5、安装 PHP 环境:
sudo apt-get install php5 libapache2-mod-php5
6、安装 mysql:
sudo apt-get install mysql-server
安装完后会有提示输入密码,
7、安装 phpmyadmin:
sudo apt-get install phpmyadmin
由于该 phpmyadmin 默认是安装在 /usr/share/phpmyadmin,所以需要作个链接,命令为:sudo ln -s /usr/share/phpmyadmin /var/www/,然后就可以通过 x.x.x.x/phpmyadmin 访问了。
8、安装 ftp:
sudo apt-get install vsftpd
安装完后可用该指令查看是否安装成功:netstat -tul l grep ftp
修改前先备份一下:sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.old
修改 vsftp 设定:sudo /etc/vsftpd.conf
修改完后需重新启动:sudo /etc/init.d/vsftpd restart
9、apt-get 使用:
安装软件:sudo apt-get install packagename
删除软件:sudo apt-get remove packagename
完全卸载软件包括删除配置文件:sudo apt-get –purge remove packagename
10、安装 finger,可以查看用户的主目录、启动shell、用户名、地址等等:
sudo apt-get intall finger
查看命令:finger 用户名
篇4:linux中Bash shell学习笔记linux操作系统
今天看到一站长写得非常不错的一篇关于Bash shell速成的学习笔记,下面我把文章并整理了一些其它相关的内容,希望给大家带来帮助,
BASH 的基本语法
•最简单的例子 —— Hello World www.111cn.net !
•关于输入、输出和错误输出
•BASH 中对变量的规定(与 C 语言的异同)
•BASH 中的基本流程控制语法
•函数的使用
2.1 最简单的例子 —— Hello World!
几乎所有的讲解编程的书给读者的第一个例子都是 Hello World 程序,那么我们今天也就从这个例子出发,来逐步了解 BASH。
用 vi 编辑器编辑一个 hello 文件如下:
#!/bin/bash
# This is a very simple example
echo Hello World
这样最简单的一个 BASH 程序就编写完了。这里有几个问题需要说明一下:
一,第一行的 #! 是什么意思
二,第一行的 /bin/bash 又是什么意思
三,第二行是注释吗
四,echo 语句
五,如何执行该程序
#! 是说明 hello 这个文件的类型的,有点类似于 Windows 系统下用不同文件后缀来表示不同文件类型的意思(但不相同)。Linux 系统根据 “#!” 及该字串后面的信息确定该文件的类型,关于这一问题同学们回去以后可以通过 “man magic”命令 及 /usr/share/magic 文件来了解这方面的更多内容。在 BASH 中 第一行的 “#!” 及后面的 “/bin/bash” 就表明该文件是一个 BASH 程序,需要由 /bin 目录下的 bash 程序来解释执行。BASH 这个程序一般是存放在 /bin 目录下,如果你的 Linux 系统比较特别,bash 也有可能被存放在 /sbin 、/usr/local/bin 、/usr/bin 、/usr/sbin 或 /usr/local/sbin 这样的目录下;如果还找不到,你可以用 “locate bash” “find / -name bash 2>/dev/null” 或 “whereis bash” 这三个命令找出 bash 所在的位置;如果仍然找不到,那你可能需要自己动手安装一个 BASH 软件包了。
第二行的 www.111cn.net “# This is a ...” 就是 BASH 程序的注释,在 BASH 程序中从“#”号(注意:后面紧接着是“!”号的除外)开始到行尾的多有部分均被看作是程序的注释。的三行的 echo 语句的功能是把 echo 后面的字符串输出到标准输出中去。由于 echo 后跟的是 “Hello World” 这个字符串,因此 “Hello World”这个字串就被显示在控制台终端的屏幕上了。需要注意的是 BASH 中的绝大多数语句结尾处都没有分号。
如何执行该程序呢?有两种方法:一种是显式制定 BASH 去执行:
$ bash hello 或
$ sh hello (这里 sh 是指向 bash 的一个链接,“lrwxrwxrwx 1 root root 4 Aug 20 05:41 /bin/sh ->bash”)
或者可以先将 hello 文件改为可以执行的文件,然后直接运行它,此时由于 hello 文件第一行的 “#! /bin/bash” 的作用,系统会自动用/bin/bash 程序去解释执行 hello 文件的:
$ chmod u+x hello
$ ./hello
此处没有直接 “$ hello”是因为当前目录不是当前用户可执行文件的默认目录,而将当前目录“.”设为默认目录是一个不安全的设置。
需要注意的是,BASH 程序被执行后,实际上 Linux 系统是另外开设了一个进程来运行的。
2.2 关于输入、输出和错误输出
在字符终端环境中,标准输入/标准输出的概念很好理解。输入即指对一个应用程序 或命令的输入,无论是从键盘输入还是从别的文件输入;输出即指应用程序或命令产生的一些信息;与 Windows 系统下不同的是,Linux 系统下还有一个标准错误输出的概念,这个概念主要是为程序调试和系统维护目的而设置的,错误输出于标准输出分开可以让一些高级的错误信息不干扰正常的输出 信息,从而方便一般用户的使用。
在 Linux 系统中:标准输入(stdin)默认为键盘输入;标准输出(stdout)默认为屏幕输出;标准错误输出(stderr)默认也是输出到屏幕(上面的 std 表示 standard)。在 BASH 中使用这些概念时一般将标准输出表示为 1,将标准错误输出表示为 2。下面我们举例来说明如何使用他们,特别是标准输出和标准错误输出。
输入、输出及标准错误输出主要用于 I/O 的重定向,就是说需要改变他们的默认设置。先看这个例子:
$ ls >ls_result
$ ls -l >>ls_result
上面这两个命令分别将 ls 命令的结果输出重定向到 ls_result 文件中和追加到 ls_result 文件中,而不是输出到屏幕上,
“>”就是输出(标准输出和标准错误输出)重定向的代表符号,连续两个 “>” 符号,即 “>>” 则表示不清除原来的而追加输出。下面再来看一个稍微复杂的例子:
$ find /home -name lost* 2>err_result
这个命令在 “>” 符号之前多了一个 “2”,“2>” 表示将标准错误输出重定向。由于 /home 目录下有些目录由于权限限制不能访问,因此会产生一些标准错误输出被存放在 err_result 文件中。大家可以设想一下 find /home -name lost* 2>>err_result 命令会产生什么结果?
如果直接执行 find /home -name lost* >all_result ,其结果是只有标准输出被存入 all_result 文件中,要想让标准错误输出和标准输入一样都被存入到文件中,那该怎么办呢?看下面这个例子:
$ find /home -name lost* >all_result 2>& 1
上面这个例子中将首先将标准错误输出也重定向到标准输出中,再将标准输出重定向到 all_result 这个文件中。这样我们就可以将所有的输出都存储到文件中了。为实现上述功能,还有一种简便的写法如下:
$ find /home -name lost* >& all_result
如果那些出错信息并不重要,下面这个命令可以让你避开众多无用出错信息的干扰:
$ find /home -name lost* 2>/dev/null
同学们回去后还可以再试验一下如下几种重定向方式,看看会出什么结果,为什么?
$ find /home -name lost* >all_result 1>& 2
$ find /home -name lost* 2>all_result 1>& 2
$ find /home -name lost* 2>& 1 >all_result
另外一个非常有用的重定向操作符是 “-”,请看下面这个例子:
$ (cd /source/directory && tar cf - . ) | (cd /dest/directory && tar xvfp -)
该命令表示把 /source/directory 目录下的所有文件通过压缩和解压,快速的全部移动到 /dest/directory 目录下去,这个命令在 /source/directory 和 /dest/directory 不处在同一个文件系统下时将显示出特别的优势。
条件语句(注意:条件里两边的空格,引号,等号)
if [ “$var” = “abc” ]; then
…
elif [ “$var” = “ac” ]; then
…
else
…
fi
for循环
for var in $(ls *.sh); do
echo $var
done
while循环
var=1
while [ “$var” -le 20 ] ; do
var=$(($var+1))
done
until循环(跟while循环相反的)
until condition
do
…
done
case条件(可用正则,;;相当于break)
case “$var” in
yes | YES | y )
echo “YES”
echo “haha”
;;
[Nn]* ) echo “NO”;;
* ) echo “OTHER”;;
esac
定义/赋值变量
var=xxx (等号两边不能有空格)
变量读取
echo $var
读取用户输入
read var
不输出换行
echo -n
执行命令并捕获返回值
$(command)
其它
shell里默认类型是字符串型
发布在编程算法 已有标签 bash, shell. 将该链接存入书签。 Trackbacks are closed, but you can post a comment.
篇5:linux中软硬链接的学习笔记linux操作系统
下面整理了一些关于在linux中硬连接与软连接之间的区别,希望此学习笔记能给各位同学带来帮助哦,
1:软链接
命令:Ln –s /etc/inittab /test/inittab.soft
查看:ls –l /etc/initab /test/inittab.soft
发现软连接类似于windows的快捷方式,—>表示真实文件的地址
2:硬链接
命令: ln /etc/inittab /test/inittab.hard
查看: ls -l /etc/inittab /test/inittab.hard
发现硬链接与真实文件的大小和创建日期完全相同,类似于copy,同步更新。
3:硬链接与拷贝的区别:
发现拷贝与真实文件的创建日期不同。
4: 若想复制时日期相同,可以通过命令:cp –p /etc/inittab /test/inittab2
5:硬链接的同步更新
软连接类似于快捷方式,访问的就是源文件,所以肯定是跟源文件同步,
而硬链接类似于拷贝,但是却拥有同步更新的功能,再此我们可以验证。
首先在/test目录下创建文件link
(1) 分别穿件link的软连接文件和硬链接文件,link.soft link.hard
(2) 向源文件link 写入数据
(3) 查看三个文件的内容
发现硬链接文件与源文件同步更新
6:删除源文件后,对硬链接和软连接的影响
软连接类似快捷方式,所有当源文件不存在时,它也无效。
而硬链接属于拷贝,仍然存在。
7:为什么硬链接可以同步更新?
同样创建了一个文件link 和它的软链接和硬链接文件,
通过命令ls –i ,发现硬链接文件和源文件的i结点数字相同,而内核是根据文件的i结点来标识文件的,这两个文件的i结点相同,所有被认为是一个文件,所有同时写入和修改数据。
8:硬链接的要求
硬链接不能跨文件系统,即不能跨分区,类似于windows内不能将C盘的硬链接放在D盘。而软链接可以放在任何文件系统。
篇6:Linux中安装配置ftp服务器方法linux操作系统
在linux中ftp服务器的全名叫 vsftpd,我们需要利用相关命令来开启安装ftp服务器,然后再在vsftpd.conf中进行相关配置,下面我来介绍vsftpd安装与配置增加用户的方法,
1. 先用rpm -qa| grep vsftpd命令检查是否已经安装,如果ftp没有安装,使用yum -y install vsftpd 安装,(ubuntu 下使用apt-get install vsftpd)
安装完之后我们要对它进行配置,才能正常使用。编辑vsftpd的配置文件vi /etc/vsftpd/vsftpd.conf
vi编辑器中的搜索使命是斜杠“/”,然后输入要查找的内容,回车确定。以下是要更改的选项
anonymous_enable=NO #禁止匿名访问
ascii_upload_enable #允许使用ascii码上传
ascii_download_enable #允许使用ascii码下载
userlist_deny=NO #(这条需手动添加到最后)使用FTP用户表,表里没有的用户需要添加才能登录
设置完毕之后,ESC,冒号wq回车。启动vsftpd服务/etc/init.d/vsftpd start,看到[确定]即为启动成功。
2. service vsftpd start 启动要让FTP每次开机自动启动,运行命令: chkconfig --level 35 vsftpd on
3. 设置ftp权限
vi /etc/vsftpd/vsftpd.conf
将anonymous_enable=YES 改为 anonymous_enable=NO
ESC返回,输入“:wq”保存并退出
4. 添加ftp帐号和目录
useradd -d /alidata/www/wwwroot -s /sbin/nologin pwftp passwd pwftp chmod -R 755 /alidata/www/wwwroot chown -R pwftp /alidata/www/wwwroot /etc/rc.d/init.d/vsftpd restart
然后用帐号pwftp密码123456
测试下就可以登陆ftp了,
目录是/alidata/www/wwwroot
修改防火墙,允许FTP使用的21端口通过
Linux防火墙配置
重启防火墙service iptables restart之后关闭selinux。不然就不连接不上FTP。
linux关闭selinux
然后reboot重启Linux服务器。
本人使用FlashFXP客户端软件连接,直到出现用户主目录(一般位于/home/用户名),则vsftpd成功安装并运行。然后就能进行文件的上传和下载了。
FTP客户端连接
篇7:Linux服务器Shell编程学习笔记linux操作系统
Shell是系统的用户界面,提供了用户与内核进行交互操作的一种接口,它接收用户输入的命令并把它送入内核去执行。实际上Shell是一个命令解释器,它解释由用户输入的命令并且把它们送到内核。
Shell脚本编程学习入门是本文要介绍的内容,我们可以使用任意一种文字编辑器,比如gedit、kedit、emacs、vi等来编写shell脚本,它必须以如下行开始(必须放在文件的第一行):
代码如下复制代码#!/bin/sh
...注意:最好使用“!/bin/bash”而不是“!/bin/sh”,如果使用tc shell改为tcsh,其他类似。
符号#!用来告诉系统执行该sell脚本的程序,本例使用/bin/sh。编辑结束并保存后,如果要执行该shell脚本,必须先使其可执行:
chmod +x filename此后在该shell脚本所在目录下,输入 ./filename 即可执行该shell脚本。
Shell里的一些特殊符号
a []
shell离得函数
如果你写过比较复杂的shell脚本,就会发现可能在几个地方使用了相同的代码,这时如果用上函数,会方便很多。函数的大致样子如下:
代码如下复制代码functionname{
# inside the body $1 is the first argument given to the function
# $2 the second ...
body
}
你需要在每个脚本的开始对函数进行声明。
下面是一个名为xtitlebar的shell脚本,它可以改变终端窗口的名称。这里使用了一个名为help的函数,该函数在shell脚本中使用了两次:
代码如下复制代码#!/bin/sh
# vim: set sw=4 ts=4 et:
help()
{
cat << HELP
xtitlebar -- change the name of an xterm, gnome-terminal or kde konsole
USAGE: xtitlebar [-h] “string_for_titelbar”
OPTIONS: -h help text
EXAMPLE: xtitlebar “cvs”
HELP
exit 0
}
# in case of error or if -h is given we call the function help:
[ -z “$1” ] && help
[ “$1” = “-h” ] && help
# send the escape sequence to change the xterm titelbar:
echo -e “33]0;$107”
#在shell脚本中提供帮助是一种很好的编程习惯,可以方便其他用户(和自己)使用和理解脚本。
命令行参数
我们已经见过$* 和 $1, $2 … $9 等特殊变量,这些特殊变量包含了用户从命令行输入的参数。迄今为止,我们仅仅了解了一些简单的命令行语法(比如一些强制性的参数和查看帮助的-h选项)。 但是在编写更复杂的程序时,您可能会发现您需要更多的自定义的选项。通常的惯例是在所有可选的参数之前加一个减号,后面再加上参数值 (比如文件名)。
有好多方法可以实现对输入参数的分析,但是下面的使用case表达式的例子无疑是一个不错的方法。
代码如下复制代码#!/bin/sh
help()
{
cat << HELP
This is a generic command line parser demo.
USAGE EXAMPLE: cmdparser -l hello -f -- -somefile1 somefile2
HELP
exit 0
}
while [ -n “$1” ]; do
case $1 in
-h) help;shift 1;; # function help is called
-f) opt_f=1;shift 1;; # variable opt_f is set
-l) opt_l=$2;shift 2;; # -l takes an argument ->shift by 2
--) shift;break;; # end of options
-*) echo “error: no such option $1. -h for help”;exit 1;;
*) break;;
esac
done
echo “opt_f is $opt_f”
echo “opt_l is $opt_l”
echo “first arg is $1”
echo “2nd arg is $2”
你可以这样运行该脚本:
代码如下复制代码cmdparser -l hello -f -- -somefile1 somefile2
返回结果如下:
opt_f is 1
opt_l is hello
first arg is -somefile1
2nd arg is somefile2
这个shell脚本是如何工作的呢?脚本首先在所有输入命令行参数中进行循环,将输入参数与case表达式进行比较,如果匹配则设置一个变量并且移除该参数。根据unix系统的惯例,首先输入的应该是包含减号的参数。
shell脚本示例
一般编程步骤
现在我们来讨论编写一个脚本的一般步骤。任何优秀的脚本都应该具有帮助和输入参数。写一个框架脚本(framework.sh),该shell脚本包含了大多数脚本需要的框架结构,是一个非常不错的主意。这样一来,当我们开始编写新脚本时,可以先执行如下命令:
代码如下复制代码cp framework.sh myscript
然后再插入自己的函数。
让我们来看看如下两个示例。
二进制到十进制的转换
脚本 b2d 将二进制数 (比如 1101) 转换为相应的十进制数。这也是一个用expr命令进行数学运算的例子:
代码如下复制代码#!/bin/sh
# vim: set sw=4 ts=4 et:
help()
{
cat << HELP
b2d -- convert binary to decimal
USAGE: b2d [-h] binarynum
OPTIONS: -h help text
EXAMPLE: b2d 111010
will return 58
HELP
exit 0
}
error()
{
# print an error and exit
echo “$1”
exit 1
}
lastchar()
{
# return the last character of a string in $rval
if [ -z “$1” ]; then
# empty string
rval=“”
return
fi
# wc puts some space behind the output this is why we need sed:
numofchar=`echo -n “$1” | sed 's/ //g' | wc -c `
# now cut out the last char
rval=`echo -n “$1” | cut -b $numofchar`
}
chop()
{
# remove the last character in string and return it in $rval
if [ -z “$1” ]; then
# empty string
rval=“”
return
fi
# wc puts some space behind the output this is why we need sed:
numofchar=`echo -n “$1” | wc -c | sed 's/ //g' `
if [ “$numofchar” = “1” ]; then
# only one char in string
rval=“”
return
fi
numofcharminus1=`expr $numofchar “-” 1`
# now cut all but the last char:
rval=`echo -n “$1” | cut -b -$numofcharminus1`
#原来的 rval=`echo -n “$1” | cut -b 0-${numofcharminus1}`运行时出错.
#原因是cut从1开始计数,应该是cut -b 1-${numofcharminus1}
}
while [ -n “$1” ]; do
case $1 in
-h) help;shift 1;; # function help is called
--) shift;break;; # end of options
-*) error “error: no such option $1. -h for help”;;
*) break;;
esac
done
# The main program
sum=0
weight=1
# one arg must be given:
[ -z “$1” ] && help
binnum=“$1”
binnumorig=“$1”
while [ -n “$binnum” ]; do
lastchar “$binnum”
if [ “$rval” = “1” ]; then
sum=`expr “$weight” “+” “$sum”`
fi
# remove the last position in $binnum
chop “$binnum”
binnum=“$rval”
weight=`expr “$weight” “*” 2`
done
echo “binary $binnumorig is decimal $sum”
#该shell脚本使用的算法是利用十进制和二进制数权值 (1,2,4,8,16,..),比如二进制”10″可以这样转换成十进制:
代码如下复制代码0 * 1 + 1 * 2 = 2
为了得到单个的二进制数我们是用了lastchar 函数,
该函数使用wc –c计算字符个数,然后使用cut命令取出末尾一个字符。Chop函数的功能则是移除最后一个字符。
文件循环
你可能有这样的需求并一直都这么做:将所有发出邮件保存到一个文件中。但是过了几个月之后,这个文件可能会变得很大以至于该文件的访问速度变慢;下 面的shell脚本 rotatefile 可以解决这个问题。这个脚本可以重命名邮件保存文件(假设为outmail)为outmail.1,而原来的outmail.1就变成了 outmail.2 等等…
代码如下复制代码#!/bin/sh
# vim: set sw=4 ts=4 et:
ver=“0.1”
help()
{
cat << HELP
rotatefile -- rotate the file name
USAGE: rotatefile [-h] filename
OPTIONS: -h help text
EXAMPLE: rotatefile out
This will e.g rename out.2 to out.3, out.1 to out.2, out to out.1[BR]
and create an empty out-file
The max number is 10
version $ver
HELP
exit 0
}
error()
{
echo “$1”
exit 1
}
while [ -n “$1” ]; do
case $1 in
-h) help;shift 1;;
--) break;;
-*) echo “error: no such option $1. -h for help”;exit 1;;
*) break;;
esac
done
# input check:
if [ -z “$1” ] ; then
error “ERROR: you must specify a file, use -h for help”
fi
filen=“$1”
# rename any .1 , .2 etc file:
for n in 9 8 7 6 5 4 3 2 1; do
if [ -f “$filen.$n” ]; then
p=`expr $n + 1`
echo “mv $filen.$n $filen.$p”
mv $filen.$n $filen.$p
fi
done
# rename the original file:
if [ -f “$filen” ]; then
echo “mv $filen $filen.1”
mv $filen $filen.1
fi
echo touch $filen
touch $filen
这个shell脚本是如何工作的呢?在检测到用户提供了一个文件名之后,首先进行一个9到1的循环;文件名.9重命名为文件名.10,文件名.8重 命名为文件名. 9……等等。循环结束之后,把原始文件命名为文件名.1,同时创建一个和原始文件同名的空文件(touch $filen)
脚本调试
最简单的调试方法当然是使用echo命令。你可以在任何怀疑出错的地方用echo打印变量值,这也是大部分shell程序员花费80%的时间用于调试的原因。Shell脚本的好处在于无需重新编译,而插入一个echo命令也不需要多少时间。
shell也有一个真正的调试模式,如果脚本”strangescript”出错,可以使用如下命令进行调试:
代码如下复制代码sh -x strangescript7
上述命令会执行该脚本,同时显示所有变量的值。
shell脚本中还有一个不执行脚本只检查语法的模式,命令如下:
代码如下复制代码sh -n your_script
这个命令会返回所有语法错误。
我们希望你现在已经可以开始编写自己的shell脚本了,尽情享受这份乐趣吧!
篇8:Linux中网络如何设置配置linux操作系统
使用linux系统内核的系统有很多,目前比较主流的有centos,fdeora,redha系统,这些有一些收费有一些免费的,但此方法可用于我讲述的三种系统中哦,
安装Linux系统后,登陆进去,修改一下文件:
代码如下复制代码# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=”eth0″
BOOTPROTO=”none”
HWADDR=”00:50:56:BE:7A:D8″
IPADDR=192.168.2.108 #IP地址,必须设置
GATEWAY=192.168.2.21 #网关地址,这个很重要,如果不设置这个就智能是局域网无法和外部网络互联了
NBOOT=”yes” #开机启动设置为yes
UUID=”fe45f058-9ce7-42a4-823c-abe472aad9f2″
IPV6INIT=no
NETMASK=255.255.255.0 #子网掩码
设置好之后,编辑域名服务器设置文件
代码如下复制代码# cat /etc/resolv.conf
nameserver 192.168.2.01 #域名服务器的地址,如果不设置这个,则无法以域名的方式访问网站
search hostname #这个相当于你本机的域名
设置好了之后重启network服务
代码如下复制代码# /etc/init.d/network restart
这样执行以下ifconfig命令就能看到你本机已经联网了,可以使用ping 命令去测试是否联网,
友情提示:
直接修改/etc/resolv.conf这个文件是没用的,网络服务重启以后会根据/etc/sysconfig/network-scripts/ifcfg-eth0来重载配置,如果ifcfg-eth0没有配置DNS,那么resolv.conf会被冲掉,重新变成空值。
怎么办呢?下面有两种解决方法:
1、通过ifcfg-eth0也可以设置DNS服务器地址,并自动修改或生成resolv.conf文件.
2、在ifcfg-eth0中可以通过PEERDNS参数决定是否修改resolv.conf文件,设置PEERDNS=yes(这也是系统的默认配置)则启用该网络设备时,会修改或生成resolv.conf文件,设置PEERDNS=no,则不对resolv.conf做任何变动.
补充的部分:
当有应用需要进行域名解析时(如:ping www.111cn.net),会首先读取resolv.conf文件获取dns服务器地址,然后再向该dns服务器发送域名解析请求,若resolv.conf设置的不对或者没有resolv.conf都会导致域名解析失败.
若ifcfg-eth0被配置为DHCP模式,则系统默认PEERDNS=no,也就是会用DHCP获取的DNS地址修改或生成resolv.conf文件.
我觉得没有特殊情况,不用在resolv.conf中设置DNS,应在ifcfg-eth0中设定DNS服务器地址方便些,即符合正常思维也更便于维护和管理.
注意:设置网络的方法仅限于fedora,redhat,centos之类的以rpm包管理的Linux系统,其他系统可能有点差异
篇9:linux中redis安装配置linux操作系统
MySQL是关系型数据库,并不擅长分布式数据出路,因为它缺乏并行执行查询的能力,这时候,可以使用其他工具。如redis。
redis是非关系型数据库。Nosql的一个开源项目。对于简单的键值存储,在复制严重落后的非常高速的访问场景中可以使用redis替代mysql。
redis安装如下。
1、下载安装包,下载地址是servicestack。如我下载的版本是redis-2.0.2.rar。
2、解压文件到相应目录。可以看到解压后内有文件:
3、其中配置文件需要自己创建,现将源代码附在下面:
代码如下复制代码# Redis configuration file example# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize no
# When run as a daemon, Redis write a pid file in /var/run/redis.pid by default.
# You can specify a custom pid file location here.
pidfile /var/run/redis.pid
# Accept connections on the specified port, default is 6379
port 6379
# If you want you can bind a single interface, if the bind option is not
# specified all the interfaces will listen for connections.
#
# bind 127.0.0.1
# Close the connection after a client is idle for N seconds (0 to disable)
timeout 300
# Set server verbosity to 'debug'
# it can be one of:
# debug (a lot of information, useful for development/testing)
# notice (moderately verbose, what you want in production probably)
# warning (only very important / critical messages are logged)
loglevel debug
# Specify the log file name. Also 'stdout' can be used to force
# the demon to log on the standard output. Note that if you use standard
# output for logging but daemonize, logs will be sent to /dev/null
logfile stdout
# Set the number of databases. The default database is DB 0, you can select
# a different one on a per-connection basis using SELECT
# dbid is a number between 0 and 'databases'-1
databases 16
################################ SNAPSHOTTING #################################
#
# Save the DB on disk:
#
# save
#
# Will save the DB if both the given number of seconds and the given
# number of write operations against the DB occurred.
#
# In the example below the behaviour will be to save:
# after 900 sec (15 min) if at least 1 key changed
# after 300 sec (5 min) if at least 10 keys changed
# after 60 sec if at least 10000 keys changed
save 900 1
save 300 10
save 60 10000
# Compress string objects using LZF when dump .rdb databases?
# For default that's set to 'yes' as it's almost always a win.
# If you want to save some CPU in the saving child set it to 'no' but
# the dataset will likely be bigger if you have compressible values or keys.
rdbcompression yes
# The filename where to dump the DB
dbfilename dump.rdb
# For default save/load DB in/from the working directory
# Note that you must specify a directory not a file name.
dir ./
################################# REPLICATION #################################
# Master-Slave replication. Use slaveof to make a Redis instance a copy of
# another Redis server. Note that the configuration is local to the slave
# so for example it is possible to configure the slave to save the DB with a
# different interval, or to listen to another port, and so on.
#
# slaveof
# If the master is password protected (using the “requirepass” configuration
# directive below) it is possible to tell the slave to authenticate before
# starting the replication synchronization process, otherwise the master will
# refuse the slave request.
#
# masterauth
################################## SECURITY ###################################
# Require clients to issue AUTH
before processing any other
# commands. This might be useful in environments in which you do not trust
# others with access to the host running redis-server.
#
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
#
# requirepass foobared
################################### LIMITS ####################################
# Set the max number of connected clients at the same time. By default there
# is no limit, and it's up to the number of file descriptors the Redis process
# is able to open. The special value '0' means no limts.
# Once the limit is reached Redis will close all the new connections sending
# an error 'max number of clients reached'.
#
# maxclients 128
# Don't use more memory than the specified amount of bytes.
# When the memory limit is reached Redis will try to remove keys with an
# EXPIRE set. It will try to start freeing keys that are going to expire
# in little time and preserve keys with a longer time to live.
# Redis will also try to remove objects from free lists if possible.
#
# If all this fails, Redis will start to reply with errors to commands
# that will use more memory, like SET, LPUSH, and so on, and will continue
# to reply to most read-only commands like GET.
#
# WARNING: maxmemory can be a good idea mainly if you want to use Redis as a
# 'state' server or cache, not as a real DB. When Redis is used as a real
# database the memory usage will grow over the weeks, it will be obvious if
# it is going to use too much memory in the long run, and you'll have the time
# to upgrade. With maxmemory after the limit is reached you'll start to get
# errors for write operations, and this may even lead to DB inconsistency.
#
# maxmemory
############################## APPEND ONLY MODE ###############################
# By default Redis asynchronously dumps the dataset on disk. If you can live
# with the idea that the latest records will be lost if something like a crash
# happens this is the preferred way to run Redis. If instead you care a lot
# about your data and don't want to that a single record can get lost you should
# enable the append only mode: when this mode is enabled Redis will append
# every write operation received in the file appendonly.log. This file will
# be read on startup in order to rebuild the full dataset in memory.
#
# Note that you can have both the async dumps and the append only file if you
# like (you have to comment the “save” statements above to disable the dumps).
# Still if append only mode is enabled Redis will load the data from the
# log file at startup ignoring the dump.rdb file.
#
# The name of the append only file is “appendonly.log”
#
# IMPORTANT: Check the BGREWRITEAOF to check how to rewrite the append
# log file in background when it gets too big.
appendonly no
# The fsync() call tells the Operating System to actually write data on disk
# instead to wait for more data in the output buffer. Some OS will really flush
# data on disk, some other OS will just try to do it ASAP.
#
# Redis supports three different modes:
#
# no: don't fsync, just let the OS flush the data when it wants. Faster.
# always: fsync after every write to the append only log . Slow, Safest.
# everysec: fsync only if one second passed since the last fsync. Compromise.
#
# The default is “always” that's the safer of the options. It's up to you to
# understand if you can relax this to “everysec” that will fsync every second
# or to “no” that will let the operating system flush the output buffer when
# it want, for better performances (but if you can live with the idea of
# some data loss consider the default persistence mode that's snapshotting).
appendfsync always
# appendfsync everysec
# appendfsync no
############################### ADVANCED CONFIG ###############################
# Glue small output buffers together in order to send small replies in a
# single TCP packet. Uses a bit more CPU but most of the times it is a win
# in terms of number of queries per second. Use 'yes' if unsure.
glueoutputbuf yes
# Use object sharing. Can save a lot of memory if you have many common
# string in your dataset, but performs lookups against the shared objects
# pool so it uses more CPU and can be a bit slower. Usually it's a good
# idea.
#
# When object sharing is enabled (shareobjects yes) you can use
# shareobjectspoolsize to control the size of the pool used in order to try
# object sharing. A bigger pool size will lead to better sharing capabilities.
# In general you want this value to be at least the double of the number of
# very common strings you have in your dataset.
# www.111cn.net
# WARNING: object sharing is experimental, don't enable this feature
# in production before of Redis 1.0-stable. Still please try this feature in
# your development environment so that we can test it better.
# shareobjects no
# shareobjectspoolsize 1024
4、命令行进入安装目录下(或者配置环境变量),
如图,
5、另开一个cmd,输入redis_cli.exe -h 127.0.0.1 -p 6349。接下来,你就可以玩了。
【linux中Cent OS SVN 服务配置学习笔记linux操作系统】相关文章:
2.linux系统下rsync文件同步配置工作笔记linux操作系统
3.linux中Ubuntu Server安装和配置VNCServer介绍linux操作系统
5.党员学习笔记
6.学习笔记范文
7.java学习笔记
8.excel中LOOKUP函数学习笔记excel办公/数码
9.党员学习笔记标准
10.9月党员学习笔记






文档为doc格式