Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Saturday, 8 October 2016

Ubuntu1.6下安装ORACLE-XE SQL

之前一直用postgres,这次换了个学校老师要求也变了,非要用oracle...话说这个公司对广大linux用户不好啊,才出了一个rpm格式的安装包只服务部分linux用户。。这个安装很费神,网上也只有英文版教程,安装过程也出了不少差错。
进入正题,直接上安装步骤吧
1.下载地址: 戳我
    我下的是LINUX64BIT那个版本

    注意:想要下载这个东西还要在它官网注册账号,尼玛为什么注册个账号还要写公司,手机号码,什么鸟都写。搞家庭调查吗!?!

2. 下载完后得到的是一个zip文件,先解压(我解压到了/opt 里):
     $unzip oracle-xe-11.2.0-1.0.x86_64.rpm.zip
     解压后你会得到一个名为 Disk1的文件夹,里面会有一个rpm文件和两个其他文件夹:




3.然后安装alien包把rpm包转换成deb包, 这个过程会相当长,可以先做第4和第5步,另外不要打断转换,耐心是美德:
    $sudo apt-get install alien libaio1 unixodbc vim
  $sudo alien --scripts -d oracle-xe-11.2.0-1.0.x86_64.rpm
   这一步完了以后,会得到一个 oracle-xe_11.2.0-2_amd64.deb 的文件,如上图。

4.为了解决Linux版本之间的兼容问题(大概是这样),还要去/sbin/里写个文件:
$sudo vim /sbin/chkconfig
文件内容:
#!/bin/bash
# Oracle 11gR2 XE installer chkconfig hack for Ubuntu
file=/etc/init.d/oracle-xe
if [[ ! `tail -n1 $file | grep INIT` ]]; then
echo >> $file
echo '### BEGIN INIT INFO' >> $file
echo '# Provides: OracleXE' >> $file
echo '# Required-Start: $remote_fs $syslog' >> $file
echo '# Required-Stop: $remote_fs $syslog' >> $file
echo '# Default-Start: 2 3 4 5' >> $file
echo '# Default-Stop: 0 1 6' >> $file
echo '# Short-Description: Oracle 11g Express Edition' >> $file
echo '### END INIT INFO' >> $file
fi
update-rc.d oracle-xe defaults 80 01
保存设定权限:
$ sudo chmod 755 /sbin/chkconfig

5.设定kernel的参数(告诉kernel这个应用能使用的ram内存大小,文件大小等等):
sudo vim /etc/sysctl.d/60-oracle.conf 
文件内容:
# Oracle 11g XE kernel parameters  
fs.file-max=6815744  
net.ipv4.ip_local_port_range=9000 65000  
kernel.sem=250 32000 100 128 
kernel.shmmax=536870912 

装载刚刚写入的内容:
$sudo service procps start
用sysctl命令检查一下:


6.终于可以安装了,这也是很耗费时间的,耐心是美德,我的小电脑大概用了20分钟= =:
$sudo dpkg --install /opt/Disk1/oracle-xe_11.2.0-2_amd64.deb 

7.安装完成后会有提示用 /etc/init.d/oracle-xe configure 来设置应用的基本参数,端口用默认的就行了:
$sudo /etc/init.d/oracle-xe configure 

  • HTTP端口8080
  • 数据库监听端口1521
  • 数据库root SYS和SYSTEM的密码
  • 初始化你的数据库(耗时间,大概7-8分钟吧
8.设置环境参数,方便你启动数据库:
$vim ./bashrc
加入环境变量内容:

export ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe
export ORACLE_SID=XE
export NLS_LANG=`$ORACLE_HOME/bin/nls_lang.sh`
export ORACLE_BASE=/u01/app/oracle
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export PATH=$ORACLE_HOME/bin:$PATH


更新环境变量:$. ./.profile 或者 $source ./bashrc

9.使用服务$sudo service oracle-xe start

用root身份进入:$sqlplus sys as sysdba


再来说下我安装过程中遇到的问题:
在第9步的时候我无法使用sys的身份进入sysdba,会出现这样的错误提示:
ORA-01017: invalid username/password; logon denied.
这是因为ubuntu当前用户没有加入dba mod的原因,所以没有权限通过sys进入sysdba。但是在加入这个mod之前,我建议大家新建一个拥有sudo权限的用户,因为笔者通过命令把自己tearsyu用户加入dba mod以后,莫名其妙地就被移除了sudo的权限,导致无法使用sudo这个命令很头疼,又没有启用root,只好去recovery mode来把tearsyu又加入sudoer中,很麻烦。但不是一定会发生,我查了半天也没搞清楚我到底干了什么把自己从sudoer名单中移除了,为了保险起见,我建议大家添加一个新用户:
$sudo useradd xxx
$passwd xxx
$sudo usermod  -aG sudo xxx

再把自己加入dba(笔者用的命令是sudo -i usermod -G dba tearsyu,-G 是在原来的基础上添加新mod,-g才是只加入制定mod,我确实没把G打成g不知为何就被移除权限了,所以为了更加保险,加入a):
$sudo -i usermod -aG dba tearsyu

那么到这里就完了。感谢博客主:Manish Raj 以及文章:http://meandmyubuntulinux.blogspot.fr/2012/05/installing-oracle-11g-r2-express.html

Saturday, 24 September 2016

关于PokemonGo黑科技

        由于童年对于神奇宝贝的梦想,这个游戏一出我就四处找apk下载。令人悲伤的是我是个死宅女。。两个月过去了,我依然只有12级,最强的神奇宝贝就是一只CP600左右的大比鸟= =/,并且这个游戏仍然处于探索阶段,很多功能依然没有开发出来,比如玩家的互动,与神奇宝贝的互动。。加上我最爱的卡蒂狗一次也没遇见过,我就失望了,再也不碰了。
        然而有一天,一个好朋友的到来又让我燃起来,我们俩在巴黎晃,她带我去打Gym,让我尝到胜利的滋味,然后一发不可收拾。回家后我就开始探索此游戏的各种外挂。
       首先是夜神模拟器,这个模拟器嘛只有Windows系统的版本,大概就是模拟一个android系统的环境的APP,再装上pokemon go的游戏,当然也可以装其他各种安卓游戏和应用(我想不出来,除了极少情况比如pokemon treating,谁会在电脑上玩手机游戏),功能齐全,可以虚拟定位,改变速度,键盘操作,但问题也挺多的:
1.在法国这POKEMONGO已经升级到4.7的版本,夜神的虚拟环境没升级,只能去找旧版本安装,而且要禁止google play的强制升级,否则进入游戏会出现:device incompatible之类的错误提示。
2.手动键盘操作人物走向其实并不是很方便,要时常纠正指南针,否则对于我这样脑子笨的人,经常反应不过来,会走错方向。
3.我用原有的帐号是无法登陆虚拟安卓系统的,会被google安全系统限制,要解除限制相当麻烦。除非重新开一个账户,这样的情况可能比较适合国内。

       所以我并不满足,继续谷歌其他外挂。于是发现了pokemongo-bot这款神器! 这是一个可以自动模拟玩家行为移动,捕捉神奇宝贝,摇点,丢弃多余物品,还可以替代玩家打Gym的程序。这款神器除了安装稍微麻烦点,目前为止都很完美,而且是开源的(开源什么的最有爱了。。),这个码源放到了Github上托管:点我去他们的Github项目托管处
       由于我是在Linux上安装使用的,我只说Linux的安装, 当然这个项目的使用说明也写的很详细清楚。我推荐傻瓜化安装(因为一开始我手动安装,但是项目依赖的python包有点多,缺这缺那。。)
      1.为这个应用创建一个文件夹,git init,然后再克隆项目:
        $git clone https://github.com/PokemonGoF/PokemonGo-Bot
      2.运行包里的shell script让一切自动化(这个过程有点长,我大概用了半个小时):
     $./setup.sh -i

   3.然后去PokemonGo-Bot/config/auth.json设置你的位置帐号信息(注意json的格式):
你可以在google map上选择好几个喜欢的常用的地点的经纬度(最好在同一个城市不要距离太远)然后给个名字name,写在favorite_locations里,之后每次启动Bot的时候想设置初始地点,只要在l这个json文件里location行上写登陆地点的名字就行了。 也可以直接填写地点的经纬度。因为每次app启动的时候都会先读取这个文件的内容,通过这里的google帐号信息和地点信息初始化bot。

在config文件夹里还有很多其他的json.example字样的文件,都是一些设置文件,你可以通过这些文件告诉Bot如何行动,比如是否升级你的pokemon如何升级,是否可以用双倍蛋增加经验,给你最喜欢的pkemon增加一个标签。这样遇到的时候Bot会在控制台高亮显示等等。

     4.在开始之前,我建议大家使用python运行的虚拟环境(避免各种幺蛾子情况出现):
        $virtualenv .
        $source bin/activate


     5. 最后点燃BOT:
     $./run.sh如果./run.sh 没成功,出现各种错误提示,可以尝试:
    $git pull 
    $pip install -r requirements.txt再通过 $python pokecli.py 启动。

关于这款神奇的几点重要建议:
1.不要瞬间改变你的位置,比如1分钟前你的位置在巴黎铁塔,周围全是小拉达,之后用神奇宝贝扫描器(比如:非常好的网页pokemon扫描器)发现科尔马小威尼斯附近有100只暴鲤龙,然后你你立马退出程序并在auth.json修改了你的地理位置到科尔马重新登陆,这样你会立马被Niantic的外挂监测器监测到,然后。。你会发现你一条暴力龙也抓不到,而且球扔出去,必定抓不到,对面必定跑,礼物必定一个也摇不出,好在 Pokemongo-bot也能处理这样被机器ban的情况(貌似只要连续对同一只神奇宝贝扔球,而且要故意不扔到,连续扔10多次,再试试看能不能抓到,能抓到就是处理了,抓不到继续找下一只试),然而如果你连续好几次都干同样的事情被监测到,那估计就直接把你帐号处理了,喜闻乐见:D
但是,如果你在巴黎铁塔发现周围全是小拉达,然后扫描到巴黎圣母院附近有100只皮卡丘,可以退出程序,设置好位置,再 算好时间大概10分钟这样登陆BOT,是不会出问题的。

2.这个程序为了避免被监测到,有一个休眠系统:SleepSchedule,会出现在一天中任意时刻,因为没有哪个真人会一天24小时都在移动抓精灵,即使你手机受得了,你的胃和膀胱也受不了。所以如果出现了类似:

这样的信息,不要惊慌焦急,就乖乖等到下午5点6点这样再试一试。通常这个休眠时间会有1个小时左右的随机变化,可能会比它显示的更加长,也可能会更加短。你也可以通过修改config里的config.json文件来取消这个机制,但是最好不要,否则很容易出现情况1.这样喜闻乐见的事。另外,也不要修改你电脑的时间来欺骗程序,这是掩耳盗铃的行为!!!(虽然一开始不了解的时候我就这样做过。。成功让程序动了,但是容易出现一个bug,就是bot登陆游戏以后有可能会强制下线log out, relog in..,来来回回。。但是只要修正时间又会正常。)

最后看看,这是4天成果(部分):




终端:


Saturday, 16 April 2016

Intellij IDEA:libXtst.so.6: cannot open shared object file: No such file or directory

I am doing a *** java project of my school.
We should implement a shipbattle game, I never play it, but it seems very boring.
The JFrame method is provided, all we should code is just.....implement the rest part:


When I run this program, an error stopped it.
Exception in thread "main" java.lang.UnsatisfiedLinkError: /home/tearsyu/idea-IC-145.597.3/jdk1.8.0_77/jre/lib/i386/libawt_xawt.so: libXtst.so.6: cannot open shared object file: No such file or directory
It's strange becase I did download and install libXtst.
By the way, I learn a new great command because of this error----locate(read more)
java/Day2$ locate libXtst/usr/lib/x86_64-linux-gnu/libXtst.so.6/usr/lib/x86_64-linux-gnu/libXtst.so.6.1.0
But, my libXtst works for 64bit while Jre search a version 32bit so I need  to download 32bit version of libXtst.
sudo apt-get install libxtst6:i386
THEN IT WORKS.

 (tucao: hao luan chou de jie mian)

Monday, 14 March 2016

Linux 下解决WINE中文乱码

引子

刚刚脱离WINDOWS进入LINUX甜蜜怀抱,我还保持着极高的热情来弄linux的各种文件,代码包。然而有些软件确实只有windows系统版本实在麻烦,想来想去还是决定下个wine来模拟windows环境。
吐槽一下:wine居然有731M!!!都快赶上UBUNTU系统大小了。。而且还不是虚拟机。

Wine 原理

先来介绍一下wine的原理: wine是通过从底层winAPI移植到Unix like环境下的,由于操作系统始终区别很大(线程,kernel mode等),使用wine来执行exe程序的时候实际上就是用wine来进行api的转换。

Wine 安装

安装就不说了。更新包库以后直接sudo apt-get install wine

Wine中文乱码

老娘性冲冲打开播布课软件,第一次转换用了5分钟,心凉了半截(其实是我电脑不给力),打开一看中文全都成了框框,心凉完了。不过遇到问题就要解决嘛,否则对不起谷歌提供这么好的搜索引擎。刚开始找了好几个解决方法都是说要替换ttf文件,或者下新的依赖库,步骤又乱七八糟的。实在没心情跟着做,不过大概明白了之所以显示乱码是因为字体的问题。
于是又找到了中文Linux维基:戳这里
就解决了问题。
步骤:
随便在一个地方编辑个注册表文档 file_name.reg:
REGEDIT4
 
[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\FontLink\SystemLink]
"Lucida Sans Unicode"="wqy-microhei.ttc"
"Microsoft Sans Serif"="wqy-microhei.ttc"
"MS Sans Serif"="wqy-microhei.ttc"
"Tahoma"="wqy-microhei.ttc"
"Tahoma Bold"="wqy-microhei.ttc"
"SimSun"="wqy-microhei.ttc"
"Arial"="wqy-microhei.ttc"
"Arial Black"="wqy-microhei.ttc"

这大概意思就是:当一种字体中不存在某个字时,可以尝试从另一个字体文件中寻找相应的字形。所以只要把当前系统中的中文字体设为"fallback"字体,汉字通常就能正确显示了。

然后在打开注册表:~$wine regedit
把刚刚写的文件导入,检查一下内容:

再看看播布课:

Friday, 11 March 2016

关于ASUS无法禁止触摸版

用了两年,华硕还是很不错的,不论打游戏还是工作。
不过华硕笔记本(型号Y581C)有个非常不方便的地方,就是触摸版不好用,太灵敏。
打字经常不小心碰到鼠标就会到处乱跑, 按了快捷键Fn+F9也没用。
在windows下就直接去搜个华硕触摸版小应用就可以进行傻瓜化操作了,但是linux下要下一些tools package。
我是ubuntu15.01的系统,用synclient touchpadoff = 1命令的方法不管用。
真正有用的是:
 
sudo add-apt-repository ppa:hanipouspilot/focaltech-dkms
sudo apt-get update
sudo apt-get install focaltech-dkms

 
然后用命令来禁用或者启动触摸版:
sudo -r modprobe 
sudo modprobe 
 
感谢这位大神提供的方法:
大神链接

Thursday, 19 November 2015

C网络编程基础

这两个星期万恶的ACU们又下达新的作业了,是写一个httpd服务器/客户端的project。
首先我要了解IOS模型,之前两年都在学这个模型我已经熟悉了。其次是socket API, 进程和线程的并行。

sockets API:
 Linux中的网络通过socket接口实现,socket是一种特殊的IO,也是一个file discriptor。一个完整的sockets都有一个相关的描述(协议,本地地址,本地端口,远程地址,远程端口)。每个端口都有本地唯一的sockets号,由系统分配。
- 应用: #incldue
      int socket(int domain,int type, int protocol)
      int domain:AF_INET =>internet IPv4
             AF_INET6 = IPv6
      int type: SOCK_STREAM = transfer in bytes stream
             SOCK_DGRAM =   transfer in bytes stream without checking
      int protocol: 0 =  lets system choose which protocol will be used.

 -基本套接字系统调有有如下一些:    
创建套接字: socket()    
绑定本机端口: bind()    
建立连接: connect(),accept()    
侦听端口: listen()    
数据传输: send(), recv()    
输入/输出多路复用: select()    
关闭socket:   closesocket()

-数据类型    struct sockaddr    {       
unsigned short  sa_family;   //地址族, 一般为AF_INET       
char                  sa_data[14];   //14字节的协议地址    }   

 struct sockaddr_in    {       
short int                     sin_family;   //地址族       
unsigned short int      sin_port;      //端口号      
 struct in_addr             in_addr;      //ip地址       
unsigned char             sin_zero[8];  //填充   
}
用socket函数传入地址时要注意字节序转换,每个机器的字节存储顺序不一样,但网络通信时需要统一标准,我们可以用
htons()---host to network short
htonl()---host to network long
ntohs() and ntohl reverse.

线程:
-创建(成功返回0,否则返回错误编号)
  int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg);
  tidp:线程标识符
  attr:线程属性设置
  start_rtn:线程函数起始地址
  arg:传递给start_rtn函数的参数
  

how create a TCP server:
1. create a socket and configure the IP address and port by struct -- socketaddr_in 
2. bind the IP and port
3. listen the signal, tell the client that server is ready to deal requests
4. build a link with requests from clients
5. put these requests into a listen queue and choose one to deal with by function accept()
6. for the request which is dealing  with, we can read and write ....



Thursday, 15 October 2015

File Descriptor

Je suis une formation de "File Descriptor"de JIKEXUEYUAN et j'ai écrit une programmation qui permet de faire copier coller depuis un fichier donné au autre fichier, ceci mes codes:


 Head File:
#ifndef   FILEIO_H
#define  FILEIO_H 
  void copy(int fd_in, int fd_out);  
#endif /*FILEIO_H*/

File filecopy.c#include "fileio.h"
#include <stdio.h>
#include <string.h>
#include <error.h>
#include <fcnlt.h>#include <unistd.h>#define BUFFER_LEN 1024
void copy(int fd_in, int fd_out) 
{    
char buffer[BUFFER_LEN] = {"\0"};    
ssize n ;
 while(n = read(fd_in, buffer, BUFFER_LEN) != 0)     
//read(int fd, char *buffer, size_t count) lire count bytes depuis le descripteur du fichier fd à partir *buffer.    
{        
if(n < 0)        
{            
fprintf(stderr, "read failed. %s\n", strerror(errno));             
//fprintf ici fonction sert à imprimer les infos d'erreur qui sont recuperées par  strerro(errno)        
} else if (n > 0)        
{            
if (write(fd_out, buffer, n) != n)        
 {          
    fprintf(stderr, "write failed. %s\n", strerror(errno));   
   }      
  }  
 } 
} 


File main 
#include "fileio.h"
#include <stdio.h>
#include <string.h>
#include <error.h>
#include <fcnlt.h>
#include <unistd.h>
int main(int argc, char *argv[2]) 
//argc est le nombre d'argument est ajouté dans la main fonction, argv est le contenu d'argument, ici, on va donner le chemin de fichier qui est copié et la destination de fichier copie. 
{  
if (argc < 3) 
//en fait, on transfert deux argument dans ce programme, mais dans ce cas il y a 3 argument, argc[0] est lui même.  
 {      
fprintf(stderr, "argument number error %s\n", strerror(errno) );   
 exit(1); //exit() est dans la bibliotheque de <stdlib.h>  
 }     
int fd_in = open(argv[1], O_RDONLY); 
// fd est définit ici par open      
if(fd_in < 0)    
  {          
fprintf(stderr, "open 1 failed. %s\n", strerror(errno) );       
exit(1);      
}  else { printf("open file %d\n", fd_in); } 

 int fd_out = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, 0644)     if(fd_out < 0)    
{          
fprintf(stderr, "open 2 failed. %s\n", strerror(errno) );         
exit(1);    
  }  else { printf("open file 2: %s\n")} 

copy(fd_in, fd_out);    
close(fd_in);  
close(fd_out); 
return 0;

}

Quand je complie ce programme, ceci les commendes que j'ai saisi:
mkdir bin // bin est un répertoire qui sert à mettre les fichiers temporaire, comme make
gcc -Iinclude mycp.c filecopy.c -o /bin/mycp //compiler
./bin/mycp /etc/passwd ./copypasswd.txt // transférer les arguments





Linux文件属性及系统结构

stat结构体
-Struct stat is a system call that returns files attributes about an inode. 

-Inode is a data structure used to represent a file system object, echo inode stores the attributes and disk block locations of the file system object's data.  And stat() return a file's  information in the inode and retrieves the file's inode number.

-Filesystem object attributes may include manipulation metadata (e.g. change,  access, modify time), as well as owner and permission data (e.g. group-id, user-id, permissions).
-Directories are lists of names assigned to inodes. The directory contains an entry for itself, its parent, and each of its children.
struct stat() is defined in <sys/stat.h> header file:
struct stat()
{
    mode_t    st_mode; /*file type & permission*/
    ino_t   st_ino; /*i-node number*/
    dev_t   st_dev /*device number*/
    nlink_t st_nlink /*number of links*/
    uid_t   st_uid /*user ID of owner -user id*/
    gid_t   st_gid /*group ID of owner*/
    off_t   st_size /*total size, in bytes unit*/
    time_t  st_atime /*time of last access*/
    time_t  st_mtime /*time of last modification*/
    ....
}


There are 9 types authority of visit a file(t_mode):
S_IRUSR, S_IWUSR, S_IXUSR
S_IRGRP, S_IWGRP, S_IXGRP
S_IROTH, S_IWOTH, S_IXOTH

We can use "t_mode  S_IXXXX" to juge the file, or we can use also the function "int access=(char *filepath, int mode)" to compare, if the result is positive,it return 0.

Let's understand how the system calculate the file's authority.
In Linux, the file's default authority is 666, and mask(掩码) is 
002 ==> 000 000 010(in binary) and we take the inverse number:
111 111 101 then it caculate 111 111 101 & 110 110 110 = 110 110 100 (664 in decimal)



File descriptor 文件描述符:
A file descriptor is an abstract indicator used to access a file or other input/output resource.
There three standard POSIX file descriptors, corresponding the three streams(define in head file <unistd.h>), which presumably every process should expect to have:
  1. 0 input STDIN_FILENO stdin
  2. 1 output STDOUT_FILENO stout
  3. 2 error STDERR_FILENO stderr



Sunday, 27 September 2015

LINUX GREP 进阶用法以及 regular expression, globbing

Regular expressions
Regular expressions, called regexp or regex, are an essential support for many UNIX.
A regular expression is a pattern that describes a set of strings. Regular expressions are constructed as arithmetic: they use different operators to combine smaller expressions.
Builtins
The builtins are commands integrated to the shell and executed by the shell itself.
To check whether a command is a builtin or not, we can use the builtin builtin.

Quoting
double quotes "
It is strongly recommended to use double quotes at the use of variable containing a string of characters.

simple quotes '
 The single quotes have the same behavior as double quotes, but they inhibit the expansion of variables.

Back-quotes `
They allow to run a command in a sub-shell.


RE 字符意义与范例
^word意义:待搜寻的字串(word)在行首!
范例:搜寻行首为 # 开始的那一行,并列出行号
grep -n '^#' regular_express.txt
word$意义:待搜寻的字串(word)在行尾!
范例:将行尾为 ! 的那一行列印出来,并列出行号
grep -n '!$' regular_express.txt
.意义:代表『一定有一个任意字节』的字符!
范例:搜寻的字串可以是 (eve) (eae) (eee) (e e), 但不能仅有 (ee) !亦即 e 与 e 中间『一定』仅有一个字节,而空白字节也是字节!
grep -n 'e.e' regular_express.txt
\意义:跳脱字符,将特殊符号的特殊意义去除!
范例:搜寻含有单引号 ' 的那一行!
grep -n \' regular_express.txt
*意义:重复零个到无穷多个的前一个 RE 字符
范例:找出含有 (es) (ess) (esss) 等等的字串,注意,因为 * 可以是 0 个,所以 es 也是符合带搜寻字串。另外,因为 * 为重复『前一个 RE 字符』的符号, 因此,在 * 之前必须要紧接著一个 RE 字符喔!例如任意字节则为 『.*』 !
grep -n 'ess*' regular_express.txt
[list]意义:字节集合的 RE 字符,里面列出想要撷取的字节!
范例:搜寻含有 (gl) 或 (gd) 的那一行,需要特别留意的是,在 [] 当中『谨代表一个待搜寻的字节』, 例如『 a[afl]y 』代表搜寻的字串可以是 aay, afy, aly 即 [afl] 代表 a 或 f 或 l 的意思!
grep -n 'g[ld]' regular_express.txt
[n1-n2]意义:字节集合的 RE 字符,里面列出想要撷取的字节范围!
范例:搜寻含有任意数字的那一行!需特别留意,在字节集合 [] 中的减号 - 是有特殊意义的,他代表两个字节之间的所有连续字节!但这个连续与否与 ASCII 编码有关,因此,你的编码需要配置正确(在 bash 当中,需要确定 LANG 与 LANGUAGE 的变量是否正确!) 例如所有大写字节则为 [A-Z]
grep -n '[A-Z]' regular_express.txt
[^list]意义:字节集合的 RE 字符,里面列出不要的字串或范围!
范例:搜寻的字串可以是 (oog) (ood) 但不能是 (oot) ,那个 ^ 在 [] 内时,代表的意义是『反向选择』的意思。 例如,我不要大写字节,则为 [^A-Z]。但是,需要特别注意的是,如果以 grep -n [^A-Z] regular_express.txt 来搜寻,却发现该文件内的所有行都被列出,为什么?因为这个 [^A-Z] 是『非大写字节』的意思, 因为每一行均有非大写字节,例如第一行的 "Open Source" 就有 p,e,n,o.... 等等的小写字
grep -n 'oo[^t]' regular_express.txt
\{n,m\}意义:连续 n 到 m 个的『前一个 RE 字符』
意义:若为 \{n\} 则是连续 n 个的前一个 RE 字符,
意义:若是 \{n,\} 则是连续 n 个以上的前一个 RE 字符!
范例:在 g 与 g 之间有 2 个到 3 个的 o 存在的字串,亦即 (goog)(gooog)
grep -n 'go\{2,3\}g' regular_express.txt
*注意 ^ 和[^]的区别!

Globbing
[:alnum:]代表英文大小写字节及数字,亦即 0-9, A-Z, a-z
[:alpha:]代表任何英文大小写字节,亦即 A-Z, a-z
[:blank:]代表空白键与 [Tab] 按键两者
[:cntrl:]代表键盘上面的控制按键,亦即包括 CR, LF, Tab, Del.. 等等
[:digit:]代表数字而已,亦即 0-9
[:graph:]除了空白字节 (空白键与 [Tab] 按键) 外的其他所有按键
[:lower:]代表小写字节,亦即 a-z
[:print:]代表任何可以被列印出来的字节
[:punct:]代表标点符号 (punctuation symbol),亦即:" ' ? ! ; : # $...
[:upper:]代表大写字节,亦即 A-Z
[:space:]任何会产生空白的字节,包括空白键, [Tab], CR 等等
[:xdigit:]代表 16 进位的数字类型,因此包括: 0-9, A-F, a-f 的数字与字节

EXEMPLE:
grep [-A] [-B] [--color=auto] '搜寻字串' filename
选项与参数:
-A :后面可加数字,为 after 的意思,除了列出该行外,后续的 n 行也列出来;
-B :后面可加数字,为 befer 的意思,除了列出该行外,前面的 n 行也列出来;
--color=auto 可将正确的那个撷取数据列出颜色 
用grep命令查找非小写a-i开头,且有 p的句子  
 





用grep查找以非小写字母开头且有字母p的句子
grep -v '^$'   意思是不要空白行。
.* 表示零个或多个任意字节在g 和g 之间