分类目录归档:linux

python升级导致yum使用报错

刚开始怀疑是不是yum源出问题了,把阿里云的源重新下载加载

cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-7.repo 
yum clean all  
yum makecache

发现不行,还是报错

检查下python版本

python
# python
Python 2.7.5 (default, Oct 30 2018, 23:45:53) 

发现python已经被升级到2.7.5,而yum需要的python版本是2.6,导致的报错

修改yum启动文件前缀

# cat /usr/bin/yum
#!/usr/bin/python2.7

发现没有用,没有备份,python直接被更新到2.7.5,yum用的库不能加载,不能加载模块

There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
 
   No module named yum
 
Please install a package which provides this module, or
verify that the module is installed correctly.

查找资料,尝试再安装个python2.6.6版本,修改yum启动文件,但是还是出现模块不能加载
重装python和yum

1、卸载现有的python,强制删除已安装程序及其关联

rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps

强制删除所有残余文件

whereis python |xargs rm -frv

2、卸载现有的yum

rpm -qa|grep yum|xargs rpm -ev --allmatches --nodeps

强制删除所有残余文件

whereis yum |xargs rm -frv

3、下载版本对应的rpm包

wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/libxml2-python-2.9.1-6.el7_2.3.x86_64.rpm

wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/rpm-4.11.3-35.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/rpm-build-4.11.3-35.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/rpm-build-libs-4.11.3-35.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/rpm-libs-4.11.3-35.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/rpm-sign-4.11.3-35.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/rpm-python-4.11.3-35.el7.x86_64.rpm

wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-2.7.5-76.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-devel-2.7.5-76.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-libs-2.7.5-76.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-pycurl-7.19.0-19.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-setuptools-0.9.8-7.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-urlgrabber-3.10-9.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-backports-1.0-8.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-chardet-2.2.1-1.el7_1.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-ipaddress-1.0.16-2.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-kitchen-1.1.1-5.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-virtualenv-15.1.0-2.el7.noarch.rpm

wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/yum-3.4.3-161.el7.centos.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/yum-utils-1.1.31-50.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-50.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/yum-plugin-protectbase-1.1.31-50.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/yum-plugin-aliases-1.1.31-50.el7.noarch.rpm

下载完成后安装这些包(–force强制安装)

rpm -Uvh --force --nodeps --replacepkgs *.rpm

安装完这些rpm包后,yum就可以正常使用了,如果还是报下面这个,说明你rpm包没下载全

There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:

   /usr/lib64/python2.7/site-packages/rpm/_rpm.so: undefined symbol: rpmpkgVerifySi

Please install a package which provides this module, or
verify that the module is installed correctly.

It's possible that the above module doesn't match the
current version of Python, which is:
2.7.5 (default, Apr 11 2018, 07:36:10)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)]

If you cannot solve this problem yourself, please go to
the yum faq at:
  http://yum.baseurl.org/wiki/Faq

重要的事情说三遍
python升级用下载的包升级,升级前先备份旧版本!!!

来源:https://www.cnblogs.com/guantou1992/p/10472121.html

linux shell 返回值的含义

Linux 下,在terminal下,控制台下运行命令,所有的命令在结束时,都会返回一个数字值,这个值即为返回值,每个返回值都对应着一个错误号,根据错误号我们可以大致推断这个函数执行的情况。另外在terminal下,有一个特殊的环境变量 $?,保存着前一个程序的返回值,我们可以试试:

[root@localhost ~]# ls
anaconda-ks.cfg  Documents  initial-setup-ks.cfg  Pictures  Templates
Desktop          Downloads  Music                 Public    Videos
[root@localhost ~]# echo $?
0

上面通过echo观察执行ls的返回值,发现是0,说明该命令执行成功,也就是说,如果 $? 变量的值不是 0 的话,就表示上一个命令在执行的过程中出错了。我们可以试着 ls 一个不存在的文件:

[root@localhost ~]# ls a
ls: cannot access a: No such file or directory
[root@localhost ~]# echo $?
2
[root@localhost ~]#

错误对照表:

"OS error code 1: Operation not permitted" "OS error code 2: No such file or directory" "OS error code 3: No such process" "OS error code 4: Interrupted system call"
"OS error code   5:  Input/output error"
"OS error code   6:  No such device or address"
"OS error code   7:  Argument list too long"
"OS error code   8:  Exec format error"
"OS error code   9:  Bad file descriptor"
"OS error code  10:  No child processes"
"OS error code  11:  Resource temporarily unavailable"
"OS error code  12:  Cannot allocate memory"
"OS error code  13:  Permission denied"
"OS error code  14:  Bad address"
"OS error code  15:  Block device required"
"OS error code  16:  Device or resource busy"
"OS error code  17:  File exists"
"OS error code  18:  Invalid cross-device link"
"OS error code  19:  No such device"
"OS error code  20:  Not a directory"
"OS error code  21:  Is a directory"
"OS error code  22:  Invalid argument"
"OS error code  23:  Too many open files in system"
"OS error code  24:  Too many open files"
"OS error code  25:  Inappropriate ioctl for device"
"OS error code  26:  Text file busy"
"OS error code  27:  File too large"
"OS error code  28:  No space left on device"
"OS error code  29:  Illegal seek"
"OS error code  30:  Read-only file system"
"OS error code  31:  Too many links"
"OS error code  32:  Broken pipe"
"OS error code  33:  Numerical argument out of domain"
"OS error code  34:  Numerical result out of range"
"OS error code  35:  Resource deadlock avoided"
"OS error code  36:  File name too long"
"OS error code  37:  No locks available"
"OS error code  38:  Function not implemented"
"OS error code  39:  Directory not empty"
"OS error code  40:  Too many levels of symbolic links"
"OS error code  42:  No message of desired type"
"OS error code  43:  Identifier removed"
"OS error code  44:  Channel number out of range"
"OS error code  45:  Level 2 not synchronized"
"OS error code  46:  Level 3 halted"
"OS error code  47:  Level 3 reset"
"OS error code  48:  Link number out of range"
"OS error code  49:  Protocol driver not attached"
"OS error code  50:  No CSI structure available"
"OS error code  51:  Level 2 halted"
"OS error code  52:  Invalid exchange"
"OS error code  53:  Invalid request descriptor"
"OS error code  54:  Exchange full"
"OS error code  55:  No anode"
"OS error code  56:  Invalid request code"
"OS error code  57:  Invalid slot"
"OS error code  59:  Bad font file format"
"OS error code  60:  Device not a stream"
"OS error code  61:  No data available"
"OS error code  62:  Timer expired"
"OS error code  63:  Out of streams resources"
"OS error code  64:  Machine is not on the network"
"OS error code  65:  Package not installed"
"OS error code  66:  Object is remote"
"OS error code  67:  Link has been severed"
"OS error code  68:  Advertise error"
"OS error code  69:  Srmount error"
"OS error code  70:  Communication error on send"
"OS error code  71:  Protocol error"
"OS error code  72:  Multihop attempted"
"OS error code  73:  RFS specific error"
"OS error code  74:  Bad message"
"OS error code  75:  Value too large for defined data type"
"OS error code  76:  Name not unique on network"
"OS error code  77:  File descriptor in bad state"
"OS error code  78:  Remote address changed"
"OS error code  79:  Can not access a needed shared library"
"OS error code  80:  Accessing a corrupted shared library"
"OS error code  81:  .lib section in a.out corrupted"
"OS error code  82:  Attempting to link in too many shared libraries"
"OS error code  83:  Cannot exec a shared library directly"
"OS error code  84:  Invalid or incomplete multibyte or wide character"
"OS error code  85:  Interrupted system call should be restarted"
"OS error code  86:  Streams pipe error"
"OS error code  87:  Too many users"
"OS error code  88:  Socket operation on non-socket"
"OS error code  89:  Destination address required"
"OS error code  90:  Message too long"
"OS error code  91:  Protocol wrong type for socket"
"OS error code  92:  Protocol not available"
"OS error code  93:  Protocol not supported"
"OS error code  94:  Socket type not supported"
"OS error code  95:  Operation not supported"
"OS error code  96:  Protocol family not supported"
"OS error code  97:  Address family not supported by protocol"
"OS error code  98:  Address already in use"
"OS error code  99:  Cannot assign requested address"
"OS error code 100:  Network is down"
"OS error code 101:  Network is unreachable"
"OS error code 102:  Network dropped connection on reset"
"OS error code 103:  Software caused connection abort"
"OS error code 104:  Connection reset by peer"
"OS error code 105:  No buffer space available"
"OS error code 106:  Transport endpoint is already connected"
"OS error code 107:  Transport endpoint is not connected"
"OS error code 108:  Cannot send after transport endpoint shutdown"
"OS error code 109:  Too many references: cannot splice"
"OS error code 110:  Connection timed out"
"OS error code 111:  Connection refused"
"OS error code 112:  Host is down"
"OS error code 113:  No route to host"
"OS error code 114:  Operation already in progress"
"OS error code 115:  Operation now in progress"
"OS error code 116:  Stale NFS file handle"
"OS error code 117:  Structure needs cleaning"
"OS error code 118:  Not a XENIX named type file"
"OS error code 119:  No XENIX semaphores available"
"OS error code 120:  Is a named type file"
"OS error code 121:  Remote I/O error"
"OS error code 122:  Disk quota exceeded"
"OS error code 123:  No medium found"
"OS error code 124:  Wrong medium type"
"OS error code 125:  Operation canceled"
"OS error code 126:  Required key not available"
"OS error code 127:  Key has expired"
"OS error code 128:  Key has been revoked"
"OS error code 129:  Key was rejected by service"
"OS error code 130:  Owner died"
"OS error code 131:  State not recoverable"
"MySQL error code 132: Old database file"
"MySQL error code 133: No record read before update"
"MySQL error code 134: Record was already deleted (or record file crashed)"
"MySQL error code 135: No more room in record file"
"MySQL error code 136: No more room in index file"
"MySQL error code 137: No more records (read after end of file)"
"MySQL error code 138: Unsupported extension used for table"
"MySQL error code 139: Too big row"
"MySQL error code 140: Wrong create options"
"MySQL error code 141: Duplicate unique key or constraint on write or update"
"MySQL error code 142: Unknown character set used"
"MySQL error code 143: Conflicting table definitions in sub-tables of MERGE table"
"MySQL error code 144: Table is crashed and last repair failed"
"MySQL error code 145: Table was marked as crashed and should be repaired"
"MySQL error code 146: Lock timed out; Retry transaction" 
"MySQL error code 147: Lock table is full; Restart program with a larger locktable"
"MySQL error code 148: Updates are not allowed under a read only transactions" 
"MySQL error code 149: Lock deadlock; Retry transaction" 
"MySQL error code 150: Foreign key constraint is incorrectly formed" 
"MySQL error code 151: Cannot add a child row" 
"MySQL error code 152: Cannot delete a parent row"
--------------------- 

参考原文:https://blog.csdn.net/IAMoldpan/article/details/79163325

Linux终端彩色文字输出

1. 格式

echo "\033[字背景颜色;字体颜色m字符串\033[0m"

例如:

echo "\033[41;36m something here \033[0m"

其中41的位置代表底色, 36的位置是代表字的颜色

那些ascii code 是对颜色调用的始末.
\033[ ; m …… \033[0m

2.颜色

字背景颜色范围:40-49 字颜色范围:30-39
40:黑
41:深红
42:绿
43:黄色
44:蓝色
45:紫色
46:深绿
47:白色
30:黑
31:红
32:绿
33:黄
34:蓝色
35:紫色
36:深绿
37:白色

3.ANSI控制码的说明

\33[0m 关闭所有属性
\33[1m 设置高亮度
\33[4m 下划线
\33[5m 闪烁
\33[7m 反显
\33[8m 消隐
\33[30m – \33[37m 设置前景色
\33[40m – \33[47m 设置背景色
\33[nA 光标上移n行
\33[nB 光标下移n行
\33[nC 光标右移n行
\33[nD 光标左移n行
\33[y;xH设置光标位置
\33[2J 清屏
\33[K 清除从光标到行尾的内容
\33[s 保存光标位置
\33[u 恢复光标位置
\33[?25l 隐藏光标
\33[?25h 显示光标

代码演示:

#include <stdio.h>

int main(int argc,char **argv)
{
    printf(“\033[31m The ……\n\033[0m”);
    printf(“\033[2;7;1mHEOO.\n\033[2;7;0m”);
    printf(“\033[41;36msomthe here\n\033[0m”);
    return 0;
}

CentOS6系统”libc.so.6: version ‘GLIBC_2.15’ not found”解决方法

出现”libc.so.6: version ‘GLIBC_2.15’ not found”问题,是由于glibc版本过低,升级glibc即可。
可以将解决CentOS系统GLIBC_2.12版本低的问题
由于CentOS系统RPM源目前glibc最高版本是2.12,所以只能采用源码升级
一、查看系统glibc支持的版本

    strings /lib64/libc.so.6 |grep GLIBC  
    #查看当前glibc版本  
    ll /lib64/libc.so.6   
    lrwxrwxrwx. 1 root root 12 Oct  9  2014 /lib64/libc.so.6 -> libc-2.12.so  

二、下载glibc源码包

    cd /usr/src/  
    wget http://mirror.bjtu.edu.cn/gnu/glibc/glibc-2.15.tar.gz  
    wget http://mirror.bjtu.edu.cn/gnu/glibc/glibc-ports-2.15.tar.gz      #glibc插件  

三、解压安装升级glibc

    tar zxvf glibc-2.15.tar.gz  
    tar zxvf glibc-ports-2.15.tar.gz  
    mv glibc-ports-2.15 glibc-2.15/ports  
    mkdir build  
    cd build  
    ../glibc-2.15/configure  --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin  
    make -j4  
    make install  

四、验证

查看当前系统glibc支持的版本

    strings /lib64/libc.so.6 |grep GLIBC  

五、误删libc.so.6解决办法

命令行执行如下:

LD_PRELOAD=/lib/libc-2.12.so ln -s /lib/libc-2.12.so lib/libc.so.6

来源:http://blog.csdn.net/hnhuangyiyang/article/details/50392997

CentOS 6通过yum安装GCC4.7 4.8 4.9 5.3 6.3 7.3等高版本GCC

再说一下已经停止支持的devtoolset4(gcc 5.2)及之前版本的安装方法
gcc 4.7 安装

    wget http://people.centos.org/tru/devtools-1/devtools-1.repo -O /etc/yum.repos.d/devtoolset-1.repo
    yum install centos-release-scl
    yum install devtoolset-1-toolchain
    scl enable devtoolset-1 bash
    gcc --version

gcc 4.8 安装

curl -Lks http://www.hop5.in/yum/el6/hop5.repo > /etc/yum.repos.d/hop5.repo
yum install gcc gcc-g++
gcc --version

或者使用官方工具

    wget http://people.centos.org/tru/devtools-2/devtools-2.repo -O /etc/yum.repos.d/devtoolset-2.repo
    yum install centos-release-scl
    yum install devtoolset-2-toolchain
    scl enable devtoolset-2 bash
    gcc --version

gcc 4.9 安装

    yum install centos-release-scl
    yum install devtoolset-3-toolchain
    scl enable devtoolset-3 bash
    gcc --version

gcc 5.3 安装

    yum install centos-release-scl
    yum install devtoolset-4-toolchain
    scl enable devtoolset-4 bash
    gcc --version

gcc 6.3 安装

    yum install centos-release-scl
    yum install devtoolset-6-toolchain
    scl enable devtoolset-6 bash
    gcc --version

gcc 7.3 安装

    yum install centos-release-scl
    yum install devtoolset-7-toolchain
    scl enable devtoolset-7 bash
    gcc --version

scl enable devtoolset-3 bash 只是临时覆盖系统原有的GCC引用,重启后恢复原来的GCC,如果想永久覆盖,
可在/etc/bashrc文件中添加

source /opt/rh/devtoolset-3/enable

或者:如果root单独使用,在/root/.bashrc文件中添加

source /opt/rh/devtoolset-3/enable

重启后生效。

文件参考: https://www.quyu.net/info/876.html
https://www.dwhd.org/20160724_085212.html

Linux下的tar压缩解压缩命令详解

tar

-c: 建立压缩档案
-x:解压
-t:查看内容
-r:向压缩归档文件末尾追加文件
-u:更新原压缩包中的文件

这五个是独立的命令,压缩解压都要用到其中一个,可以和别的命令连用但只能用其中一个。下面的参数是根据需要在压缩或解压档案时可选的。

-z:有gzip属性的
-j:有bz2属性的
-Z:有compress属性的
-v:显示所有过程
-O:将文件解开到标准输出

下面的参数-f是必须的

-f: 使用档案名字,切记,这个参数是最后一个参数,后面只能接档案名。

# tar -cf all.tar *.jpg
这条命令是将所有.jpg的文件打成一个名为all.tar的包。-c是表示产生新的包,-f指定包的文件名。

# tar -rf all.tar *.gif
这条命令是将所有.gif的文件增加到all.tar的包里面去。-r是表示增加文件的意思。

# tar -uf all.tar logo.gif
这条命令是更新原来tar包all.tar中logo.gif文件,-u是表示更新文件的意思。

# tar -tf all.tar
这条命令是列出all.tar包中所有文件,-t是列出文件的意思

# tar -xf all.tar
这条命令是解出all.tar包中所有文件,-t是解开的意思

压缩

tar -cvf jpg.tar *.jpg //将目录里所有jpg文件打包成jpg.tar

tar -czf jpg.tar.gz *.jpg   //将目录里所有jpg文件打包成jpg.tar后,并且将其用gzip压缩,生成一个gzip压缩过的包,命名为jpg.tar.gz

tar -cjf jpg.tar.bz2 *.jpg //将目录里所有jpg文件打包成jpg.tar后,并且将其用bzip2压缩,生成一个bzip2压缩过的包,命名为jpg.tar.bz2

tar -cZf jpg.tar.Z *.jpg   //将目录里所有jpg文件打包成jpg.tar后,并且将其用compress压缩,生成一个umcompress压缩过的包,命名为jpg.tar.Z

rar a jpg.rar *.jpg //rar格式的压缩,需要先下载rar for linux

zip jpg.zip *.jpg //zip格式的压缩,需要先下载zip for linux

解压

tar -xvf file.tar //解压 tar包

tar -xzvf file.tar.gz //解压tar.gz

tar -xjvf file.tar.bz2   //解压 tar.bz2

tar -xZvf file.tar.Z   //解压tar.Z

unrar e file.rar //解压rar

unzip file.zip //解压zip

总结

1、*.tar 用 tar -xvf 解压

2、*.gz 用 gzip -d或者gunzip 解压

3、*.tar.gz和*.tgz 用 tar -xzf 解压

4、*.bz2 用 bzip2 -d或者用bunzip2 解压

5、*.tar.bz2用tar -xjf 解压

6、*.Z 用 uncompress 解压

7、*.tar.Z 用tar -xZf 解压

8、*.rar 用 unrar e解压

9、*.zip 用 unzip 解压

linux 控制台显示中文乱码

linux 控制台显示乱码

linux 语言编码设置在/etc/sysconfig/i18n文件中。建议设置UTF-8
全局语言编码设置具体如下,这个是针对所有的语言编码设置(包括控制台,窗体标题,GUI内容显示等等)

#vi /etc/sysconfig/i18n

在文件中添加如下代码:

LANG="zh_CN.UTF-8"

下面针对控制台设置如下

#vi ~/bash_profile

将LANG代码更改成如下代码:

LANG=zh_CN.UTF-8
export LANG

给linux配置虚拟内存swap交换页

1.新建swap交换页文件:

首先转到root用户,Ubuntu用户请直接在下面命令前加”su ”

dd if=/dev/zero of=/swapfile bs=1024k count=1024

dd:利用/dev/zero文件创建文件/swapfile,文件大小为1024*1024K【bs表示每一块的大小,count表示有多少快】

2.将文件创建为swap文件

mkswap /swapfile

3.启动swap

swapon /swapfile

4.设置开机启动swap空间

vi /etc/fstab

编辑fstab文件,在文件末尾添加如下命令

LABEL=SWAP-FILES /swapfile swap default 0 0

5.删除swap分区

swapoff /swapfile

rm -f /swapfile

6.从fstab中移出开机启动swap空间配置

删除/etc/stab文件中相应的行即可。

CentOS 6下VNC 配置方法

VNC是一款优秀的远程控制工具

  VNC是一款优秀的远程控制工具软件,由著名的AT&T的欧洲研究实验室开发的。VNC是在基于UNIX和Linux操作系统的免费的开放源码软件,远程控制能力强大,高效实用,其性能可以和Windows和MAC中的任何远程控制软件媲美。

  首先是安装了 CentOS 6.0 的 64 位版。本文讲解的是一种方法。VNC 配置网上搜了有很多,但是貌似写的都不够基础,这里仔细按步骤记录一下。

一、安装 VNC

  首先检查一下本机是否安装了 VNC,默认情况下,CentOS 6.0 是没有安装的。

  检查是否安装,输入:

[root@localhost ~]# rpm -q vnc vnc-server

  得到:

package vnc is not installed

package vnc-server is not installed

  提示没有安装,那么就开始安装,输入:

[root@localhost ~]# yum install vnc vnc-server

  注:如果是 Ubuntu 则输入:

[root@localhost ~]# apt-get install vnc vnc-server

  在一串指令提示后,会让你确认一些选项,输入两次 “Y” 并确认,稍作等待,提示 “Complete!” 即完成安装。

二、设置 VNC 密码

  启动 VNC,输入:

[root@localhost ~]# vncserver

  此时会提示你输入密码,因为是第一次配置。重复输入两次即可。
继续阅读

c语言统计文本单词计数

统计文本中字符信息

实现linux中wc命令的最简模式:

[lhf@localhost 1.5]$ wc 01.c 02.c 03.c
 15  23 131 01.c
 13  18 127 02.c
 14  20 128 03.c
 42  61 386 总用量

使用C语言重现命令(50行左右)

/*
 * Name:        count.c
 * Title:       the number of line, word, characters in file
 * Descripts:   count the number of line, word, characters in file
 * Author:      lnesuper
 * Copyrighte:  GPL
 * Date:        2015.5.25
 * Use:         count [file1] [file2]...
 */
#include <stdio.h>
#include <stdlib.h>

#define IN 1    /* inside a word */
#define OUT 0   /* outside a word */

int main(int argc, char * argv[])
{
        if (argc == 1) {
                printf("\aUsing: count [file1] [file2]...\n");
                exit(EXIT_FAILURE);
        }

        int c, nl, nw, nc, state;       /* line, word, character */

        int nl_total, nw_total, nc_total;
        nl_total = nw_total = nc_total = 0;

        int n;
        for (n = 1; n < argc; n++) {
                FILE * file = fopen(argv[n], "r");
                if (file == NULL) {
                        printf("Can't open file %s\n", argv[n]);
                        exit(EXIT_FAILURE);
                }
                nl = nw = nc = 0;
                state = OUT;
                while ((c = fgetc(file)) != EOF) {
                        ++nc;
                        if (c == '\n')
                                ++nl;
                        if (c == ' ' || c == '\t' || c == '\n')
                                state = OUT;
                        else if (state == OUT) {
                                ++nw;
                                state = IN;
                        }
                }
                nl_total += nl;
                nw_total += nw;
                nc_total += nc;
                printf("%d %d %d %s\n", nl, nw, nc, argv[n]);
                fclose(file);
        }
//      printf("total information:\n");
        printf("%d %d %d total\n", nl_total, nw_total, nc_total);

        return 0;
}

程序编辑

编译 -Wall 用于显示全部警告信息,最后对比而这结果,显示完全相同。

[lhf@localhost 1.5]$ gcc -Wall -o count count.c
[lhf@localhost 1.5]$ ./count 01.c 02.c 03.c
15 23 131 01.c
13 18 127 02.c
14 20 128 03.c
42 61 386 total
[lhf@localhost 1.5]$ wc 01.c 02.c 03.c
 15  23 131 01.c
 13  18 127 02.c
 14  20 128 03.c
 42  61 386 总用量
[lhf@localhost 1.5]$