??xml version="1.0" encoding="utf-8" standalone="yes"?> http://blog.csdn.net/mark_qi/article/details/7919498 首先创徏我们l习grep命o旉要用到的demo文gdemo_file?pre>$ cat demo_file grep的基用法是如下例的从指定的文件中搜烦特定的字丌Ӏ?pre>语法Q?br>grep "literal_string" filename 先拷贝demo_file为demo_file1。grep的结果在W合条g的行前将包括文g名。当文g名包含元字符Ӟlinux shell会将匚w的所有文件作入到grep中去?pre>$ cp demo_file demo_file1 也是一个基本用法,Ҏ(gu)索的字串忽略大小写,因此下例中匹配“the? “THE?and “The”?pre>$ grep -i "the" demo_file 如果你能有效地利用正则表辑ּQ这是个很有用的特点。在下面的例子中Q搜索全部以“lines”开始以“empty”结束的字串Q如搜烦“lines[之间L字]empty?Qƈ且忽略大写?pre>$ grep -i "lines.*empty" demo_file 正则表达式遵循的几个重复的操?
使用-w选项搜烦一个单词,q且避免搜烦到词中的部分字串?br>下例搜烦"is"。如果不?w选项Q将昄“is? “his? “this?{所有包含“is”的行?pre>$ grep -i "is" demo_file 下例使用?w选项Q请注意l果中不包含 “This Line Has All Its First Character Of The Word With Upper Case? 虽然 “This”中包含“is”?pre>$ grep -iw "is" demo_file 当用grep搜烦大文件时Q显C匹配行附近的多行数据是一个很有用的功能?
创徏如下文g -A 下例昄匚w行和之后?行数?pre>$ grep -A 3 -i "example" demo_text -B 下例昄匚w行和之前?行数?pre>$ grep -B 2 "single WORD" demo_text -C 昄之前的n行,之后的n行数? 如果你希望搜索的字串高亮昄在结果中Q可以试用以下的办法?
通过修改GREP_OPTIONSҎ(gu)索字串高亮显C?pre>$ export GREP_OPTIONS='--color=auto' GREP_COLOR='100;8' 如果x扑ֽ前目前以及其子目录的全部文gӞ可以使用 -r 选项。如下例 可以使用-v选项昄不匹配搜索字串的行。下例显Cdemo_text文g中不包含“go”的?pre>$ grep -v "go" demo_text 创徏如下例子文g l计不匹配的行数 ~省昄匚w字串的所在行Q可以?o选项只显C匹配的字串。这功能当使用正则表达式时比较有用处?
$ grep -o "is.*line" demo_file 注意: 以上输出昄的不是行内的位置Q而是整个文g中的字节byte位置
行号?开?pre>$ grep -n "go" demo_text 版权所有,重他h力_成果Q{载时h明作者和原始出处及本声明?/em> 原文名称Q《Show All Running Processes in Linux?/em> 原文地址Qhttp://www.cyberciti.biz/faq/show-all-running-processes-in-linux/ 在linux中怎样查看所有运行中的进E? 你可以用ps命o。它能显C当前运行中q程的相关信息,包括q程的PID。Linux和UNIX都支持ps命oQ显C所有运行中q程的相关信息。ps命o能提供一份当前进E的快照。如果你想状态可以自动刷斎ͼ可以使用top命o? ps命o 输入下面的ps命oQ显C所有运行中的进E: # ps aux | less 其中Q? -AQ显C所有进E? aQ显C终端中包括其它用户的所有进E? xQ显C无控制l端的进E? dQ查看系l中的每个进E? # ps -A # ps -e dQ查看非rootq行的进E? # ps -U root -u root -N dQ查看用户vivekq行的进E? # ps -u vivek dQtop命o top命o提供了运行中pȝ的动态实时视图。在命o提示行中输入topQ? # top 输出Q? ?Qtop命oQ显CLinuxd 按q退出,按hq入帮助? dQ显CE的树状图? pstree以树状显C正在运行的q程。树的根节点为pid或init。如果指定了用户名,q程树将以用h拥有的进E作为根节点? $ pstree 输出CZQ? ?Qpstree - 昄q程的树状图 dQ用ps列印q程? # ps -ejH # ps axjf dQ获得线E信? 输入下列命oQ? # ps -eLf # ps axms dQ获得安全信? 输入下列命oQ? # ps -eo euser,ruser,suser,fuser,f,comm,label # ps axZ # ps -eM dQ将q程快照储存到文件中 输入下列命oQ? # top -b -n1 > /tmp/process.log 你也可以结果通过邮g发给自己Q? # top -b -n1 | mail -s 'Process snapshot' you@example.com dQ查找进E? 使用pgrep命o。pgrep能查扑ֽ前正在运行的q程q列出符合条件的q程ID。例如显Cfirefox的进EIDQ? $ pgrep firefox 下面命o显CE名为sshd、所有者ؓroot的进E? $ pgrep -u root sshd 向htop和atop说hello htop是一个类似top的交互式q程查看工具Q但是可以垂直和水^滚动来查看所有进E和他们的命令行。进E的相关操作QkillingQrenicingQ不需要输入PID。要安装htop输入命oQ? # apt-get install htop ? # yum install htop 在命令提C中输入htopQ? # htop 输出CZQ? ?Qhtop - Interactive Linux / UNIX process viewer atop工具 atop是一个用来查看Linuxpȝ负蝲的交互式监控工具。它能展现系l层U的关键g资源Q从性能角度Q的使用情况Q如CPU、内存、硬盘和|络? 它也可以Ҏ(gu)q程层的CPU和内存负载显C哪个进E造成了特定的负蝲Q如果已l安装内核补丁可以显C每个进E的盘和网l负载。输入下面的命o启动atopQ? # atop 输出CZQ? ?QAT Computing's System & Process Monitor 前两天有人问了个关于Unix的fork()pȝ调用的面试题Q这个题正好是我大约十年前找工作时某公司问我的一个题Q我觉得比较有趣Q写文章与大家分n一下。这个题是这LQ? 题目Q请问下面的E序一p出多个?”? 如果你对fork()的机制比较熟(zhn)的话,q个题ƈ不难Q输出应该是6个?”,但是Q实际上q个E序会很tricky地输?个?”?/p>
要讲清这个题Q我们首先需要知道fork()pȝ调用的特性,
所以,上面的那个程序ؓ什么会输入8个?”,q是因ؓprintf(??;语句Q我们知道,Unix下的讑֤有?a >块设?/a>”和?a >字符讑֤”的概念Q所谓块讑֤Q就是以一块一块的数据存取的设备,字符讑֤是一ơ存取一个字W的讑֤。磁盘、内存、显C器都是块设备,字符讑֤如键盘和串口?strong>块设备一般都有缓存,而字W设备一般都没有~存?
所以,对于上述E序Qprintf(??;把?”放C~存中,q没有真正的输出Q参看?a >C语言的迷?/a>》中的第一题)Q?strong>在fork的时候,~存被复制到了子q程I间Q所以,多了两个,成?个,而不?个?
我们如果修改一下上面的printf的那条语句ؓQ?
或是
没有问题了Q因为程序遇到“\n”或是EOFQ或是缓中区满,或是文g描述W关闭,或是dflushQ就会把数据刷出~冲区?
我估计有些朋友可能对于fork()q不是很了解Q那么我们把上面的程序改成下面这P 于是Q上面这D늨序会输出下面的结果,Q注Q编译出的可执行的程序名为forkQ?
面对q样的图你可能还是看不懂Q没事,我好事做到底Q画个图l你看看Q?
注意Q上图中的我用了几个色彩Q相同颜色的是同一个进E。于是,我们的pstree的图C就可以成ؓ下面q个样子Q(下图中的颜色与上囑֯应)
q样Q对于printf(??;q个语句Q我们就可以很清楚的知道Q哪个子q程复制了父q程标准输出~中区里的的内容Q而导致了多次输出了。(如下图所C,是我阴影ƈ双边框了那两个子q程Q?
现在你明白了吧。(另,对于图中的我本h拙劣的配Ԍ误?Q?
Q全文完Q?
tab=补全 朋友l了两个email文gQ一?00行左?a.txt)Q一个不?000?b.txt)。两个有很多重复的emailQ要扑ևb.txt里除了a.txt之外的所有行?br />Ҏ(gu)评论Q可以这么做Q?span style="color: red; ">grep -vxFf a.txt b.txt 于是想C直接利用shell里的wcQuniqQsort{?/p> 其实像这些命令,选项参数很多Q大概要知道某个用法Q可以实C么,然后再查也不q?/p> 先写下我的方法,再分析: cat a.txt > total.txt cat b.txt >> total.txt sort total.txt > total.txt.sort uniq –d total.txt.sort > total.txt.sort.uniq cat b.txt >> total.txt.sort.uniq sort total.txt.sort.uniq > total.txt.sort.uniq.sort uniq –u total.txt.sort.uniq.sort > result.txt 中间生成了一些时文Ӟ不知道怎么样通过pipe能减数量?/p> uniq介绍Q?/strong> uniq [选项] 文g 说明Q这个命令读取输入文Ӟq比较相ȝ行。在正常情况下,W二个及以后更多个重复行被删去Q行比较是根据所用字W集的排序序列进行的。该命o加工后的l果写到输出文g中。输入文件和输出文g必须不同。如果输入文件用“- ”表示Q则从标准输入读取? 该命令各选项含义如下Q? – c 昄输出中,在每行行首加上本行在文g中出现的ơ数。它可取? u? d选项? – d 只显C重复行? – u 只显C文件中不重复的各行? – n 前n个字D与每个字段前的I白一赯忽略。一个字D|一个非I格、非制表W的字符Ԍ彼此由制表符和空格隔开(字段?开始编?? +n 前n个字W被忽略Q之前的字符被蟩q?字符?开始编?? – f n ? n相同Q这里n是字D|? – s n ?n相同Q这里n是字W数? sort介绍Q?/strong> sort的选项更多Q大概浏览下有个印象知道可以做什么即可? 语 法:sort [-bcdfimMnr][-o<输出文g>][-t<分隔字符>][+<起始栏位>-<l束栏位>][--help][--verison][文g] http://blog.csdn.net/free_program_1314/article/details/7731073 ȝ下三U方法: 首先都需要用time函数获取旉?/p>
都在#include <time.h>里定义?/p>
用到的函数原型: time_t time(time_t *t); char *ctime(const time_t *timep); struct tm *localtime(const time_t *timep); size_t strftime(char *s, size_t max, const char *format, char *asctime(const struct tm *tm); 我的感觉,W二U最为好用。格式有很多Qman一下就看到了。摘抄下用到的: %y The year as a decimal number without a century (range 00 to 99). %m The month as a decimal number (range 01 to 12). %d The day of the month as a decimal number (range 01 to 31). %H The hour as a decimal number using a 24-hour clock (range 00 to 23). %M The minute as a decimal number (range 00 to 59). %S The second as a decimal number (range 00 to 60). (The range is up to 60 to allow for occasional leap seconds.) 原帖地址Q?a >Classical 10 Examples for learning AWK 很久不用awk了,一直认为学习的最x式是通读->实践->ȝ的过E?/p> 原帖讲的很详l了Q很不错Q都是很单的题目。我在这里记录下自己关于每个题目的ȝQ?/p> e1: 1.?-s”是左对齐,?s”是叛_齐,寚w方式由正负号表示?/p> e2: note:grep "Europe" contries一样可以达到效果?/p> e5: awk可以直接从命令行d或从文gd awk [options] 'script' var=value file(s) awk [options] -f scriptfile var=value file(sQ?/p> e6: 应该q么写? #!/usr/bin/awk noteQprint会自动换行,而printf不会?/p> e7: FILENAME: 当前文g?/p> OFS:输出字段分隔W(默认I格Q?/p> ORS:输出记录分隔W(默认回RQ?/p> 比如可以q么重写下: 输出l果Q?/p>
contries-1-Canada-3852-25-North America-$ 最q看到automake的几文章,Z重新复习了下?/p> 感觉最主要的就是这张图了?/p> 其中椭圆形的命o是我们需要手动输入或者修改的?/p> 文章有很多: http://www.shnenglu.com/sunrise/archive/2012/06/27/180440.html http://www.shnenglu.com/wc250en007/archive/2012/06/27/180478.aspx 都是最q发在cpp主页的?/p> 以第一文章ؓ例?/p> W?步有些不明确 我写的是Q?/p> AUTOMAKE_OPTIONS=foreign q样写也是可以的Q生成的可执行文件就是helloworld AUTOMAKE_OPTIONS=foreign %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 在生成MakefileӞq行automake --add-missing命o出现以下错误Q? configure.in: installing './install-sh': error while making link: 不允许的操作 l过在网上查找,发现有一文章也出现了类似的情况Q以下ؓq篇文章的内容: //=========================================================================== fedora 9自带的Glade?.xx版的Q而且AnjutaҎ(gu)没有。删掉换成新的Glade 3.xx和AnjutaQ准备试试在linux下写gtk+. //========================================================================== 分析一下自q原因Q才知道原来是因q代码文g攑֜linux和windows的共享目录下Q也是FAT32分区Q最后把q些代码文gUdext3上就解决了,呵呵Q太谢谢q位哥们你了Q? %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 之前猜测是在虚拟机linux和主机win下共享文件的原因Q看了下我的是NTFS的,看来同样不支持link? 另外关于automakeQ感兴趣的可以看下这里: http://www.gnu.org/software/automake/manual/automake.html 参考: http://hi.baidu.com/huaan031/blog/item/11849039056fc6c4d5622595.html #include <getopt.h> int getopt_long(int argc, char * const argv[], int getopt_long_only(int argc, char * const argv[], q是看下man里的解释Q?/strong> The getopt_long() function works like getopt() except that it also accepts long options, started with two dashes. (If the program accepts only long options, then longopts is a pointer to the first element of an array of struct option declared in <getopt.h> as struct option { The meanings of the different fields are: name is the name of the long option. has_arg flag specifies how results are returned for a long option. If flag is NULL, then getopt_long() returns val. (For example, the calling program may set val to val is the value to return, or to load into the variable pointed to by flag. The last element of the array has to be filled with zeros. If longindex is not NULL, it points to a variable which is set to the index of the long option relative to longopts. getopt_long_only() is like getopt_long(), but '-' as well as "--" can indicate a long option. If an option that starts with '-' (not "--") doesn't match a long 我来译下: 前面说的-h可以由getopt实现Q那么—help则由getopt_long实现了。所谓的镉K项即helpQ短选项是h?/p> argcQargvQoptstring都同前面?/p> name:如”help?”version”等 has_arg: [W号帔R][数值][含义] no_argument 0 该选项没有参数 required_argument 1 选项需要参?/p> optional_argument 2 选项参数可?/p> int *flagQ?strong>int val: flag和val怺依赖Q主要分两种情况Q? Q?Q、flag为NULLQval值用于确定该镉K项Q所以需要ؓ镉K项指定唯一的val倹{这里也为长选项和短选项建立了桥梁? Q?Q、flag不ؓNULLQ则val值存攑ֈflag所指向的存储空_用于标识该长选项出现q? q回| E序中用短选项Q则q回短选项字符Q如‘n'Q,当需要参数是Q则在返回之前将参数存入到optarg中? E序中用长选项Q返回值根据flag和val定。当flag为NULLQ则q回val倹{所以根据val值做不同的处理,q也说明了val必须唯一。当val值等于短选项|则可以用短选项解析函数解析镉K项Q当flag不ؓNULLQ则val值存入flag所指向的存储空_getopt_longq回0 出现未定义的镉K项或者短选项Qgetopt_longq回Q? 解析完毕Qgetopt_longq回-1 copy参考里的一个例子,略微修改了下Q?/p> Q: 1.另外—versionQ即镉K项Q后不知道如何加可选参敎ͼ试了下修改程序后—debug –version后都是空格加参数的,参数用optargd?/p>
2.最后一个参数没看懂。参考里说是调试用?/p>
参考: http://www.cnitblog.com/zouzheng/archive/2007/04/02/25034.aspx http://en.wikipedia.org/wiki/Getopt http://blog.csdn.net/lanyan822/article/details/7692013 http://hi.baidu.com/agodliness/blog/item/554a2d516366711b367abeb2.html 首先man下看下基本的介绍Q注意要 $man 3 getopt 因ؓgetopt也是shell下的一个命?/p> 基本介绍Q?/font> 原型Q?/strong> #include <unistd.h> int getopt(int argc, char * const argv[], extern char *optarg; 作用Q?/p> 可以用来解析命o行选项参数Q而不用自己再dE序分析了?/p> 参数介绍Q?/strong> 1.argc:即传入main函数的argc 2.argv:即传入main函数的argv 3.optstring:指定预期的选项以及该选项是否存在参数?/p> 格式如下Q?/p> 1.单个字符Q表C选项Q如’x’表C?x?br>2.单个字符后接一个冒P表示该选项后必跟一个参数。参数紧跟在选项后或者以I格隔开。该参数的指针赋loptarg。如’x:’表C?x argument?但argument在这里可有可无?br>3 单个字符后跟两个冒号Q表C选项后必跟一个参数。参数必ȝ跟在选项后不能以I格隔开。该参数的指针赋loptarg。如’x::’表C?x argument’(q个Ҏ(gu)是GNU的扩张) 举个例子Q? 如optstring="ab:c::d::",命o行ؓgetopt.exe -a -b host -ckeke -d haha 英文好的直接看这里(从getopt.h里抄的)Q? /* For communication from `getopt' to the caller. extern char *optarg; /* Index in ARGV of the next element to be scanned. On entry to `getopt', zero means this is the first call; initialize. When `getopt' returns -1, this is the index of the first of the Otherwise, `optind' communicates from one call to the next extern int optind; /* Callers store zero here to inhibit the error message `getopt' prints extern int opterr; /* Set to an option character which was unrecognized. */ extern int optopt; 1.extern char* optarg;//选项的参数指?/p> 2.extern int optind;//储存该位|,下次从该位|处开始检查选项Q检查时遇到选项或者参敎ͼ位置+1Q?/p> 3.extern int opterr;//当opterr=0Ӟgetopt不像stderr输出错误信息 4.extern int optopt;//当选项字符不在optstring中或者缺必要的参数Ӟ该选项存储在optoptQgetoptq回??/p> 调用一ơ,q回一个选项?/p> 在命令行选项参数再也查不到optstring中包含的选项Ӟq回Q?Q同时optind储存W一个不包含选项的命令行参数?/p> 其实看个例子比较容易了Q?/p> y@y-VirtualBox:~/Training$ ./getopt_l -a -d -b foo 逐行解释下输出: 1.-a在命令行里位|ؓ1,下次d位置?Q因此optind=2 2-3.optstring里有aQ同时a是不带参数的Q因此检到-a选项Q同时参Cؓnull 4.optstring里没有d(注,q里的输出时getopt本n输出Q通过讄opterr可以讄昄q是不显C? 5.下次?位置Q即-b开始读?/p>
6.optstirng没有dQ返回?Qoptopt会存储预期之外的上一个选项?/p>
7.d-b同时d其参数fooQ因此下一个位|ؓ5 8optstring里有bQ读取正ƈ打印 9.打印b的参数fooQ读取不到其他预期之内的选项Q完毕返?1 注意Q?/p>
默认情况下getopt会重新排列命令行参数的顺序,所以到最后所有不包含选项的命令行参数都排到最后?br>如getopt.exe -a ima -b host -ckeke -d haha, 都最后命令行参数的顺序是Q?-a -b host -ckeke -d ima haha 看个例子Q?/p> ȝQ?/p>
函数说明 getopt()用来分析命o行参数。参数argc和argv是由main()传递的参数个数和内宏V参数optstring 则代表欲处理的选项字符丌Ӏ此函数会返回在argv 中下一个的选项字母Q此字母会对应参数optstring 中的字母。如果选项字符串里的字母后接着冒号?”,则表C有相关的参数Q全域变量optarg 即会指向此额外参数。如果getopt()找不到符合的参数则会印出错信息,q将全域变量optopt设ؓ?”字W,如果不希望getopt()印出错信息,则只要将全域变量opterr设ؓ0卛_?br>q回?nbsp; 如果扑ֈW合的参数则q回此参数字母,如果参数不包含在参数optstring 的选项字母则返回?”字W,分析l束则返?1?
最后实战一下,假设有以下需求:
1.同大多数E序一P-h输出help信息
2.-c 指定文g路径Q如果没有默认ؓ/tmp/c.conf
3.-d 指定目标文gQ必L定参敎ͼ同时该选项必须指定?
我实现的Q?pre class="code">/*
* =====================================================================================
* Filename: getopt_l3.c
* Description: -h for help info
* -c set the config file, default is /tmp/c.conf
* -d set destination file, could not be empty.
*
* Version: 1.0
* Created: 06/27/2012 07:12:00 PM
*
* Author: zhy (), izualzhy@163.com
* =====================================================================================
*/
#include <unistd.h>
#include <stdio.h>
int main(int argc, char *argv)
{
int result;
int hflag = 0, cflag = 0, dflag = 0;
opterr = 0;
char helpinfo[] = "[Usage]: ./a.out \n\
-h, For Help Info\n\
-c, Set the config file, default is /tmp/c.conf\n\
-d, Set the destination file, could not be empty";
while ((result=getopt(argc, argv, "hc::d:")) != -1) {
switch (result) {
case 'h':
hflag = 1;
break;
case 'c':
cflag = 1;
if (NULL != optarg) {
printf("config file set: %s.\n", optarg);
} else {
printf("config file set to default: /tmp/c.conf.\n");
}
break;
case 'd':
dflag = 1;
if (NULL != optarg) {
printf("destination file set to: %s.\n", optarg);
} else {
printf("args could not be empty for -d options.\n");
return;
}
break;
case '?':
printf("unexpected option: %c.\n", optopt);
break;
default:
printf("default, %c", result);
}
}
printf("options(h:%d, c:%d, d:%d)\n", hflag, cflag, dflag);
if (hflag && !cflag && !dflag) {//如果只有h选项Q打印ƈ直接q回Q否则不打印.
printf("%s.\n", helpinfo);
return;
}
if (!dflag) {
printf("-d option must be setted\n");
return;
}
//参数完毕,E序真正开始干zM......
//
printf("Args Setting Right.\n");
return 0;
}
参考: http://www.cnitblog.com/zouzheng/archive/2007/04/02/25034.aspx http://en.wikipedia.org/wiki/Getopt http://hi.baidu.com/agodliness/blog/item/554a2d516366711b367abeb2.html
#string的长?/span>
echo ${#string}
#expr同样可以获取长度
#但在文g里执行下面这句会出错Qؓ什么?h?/span>
#expr length ${string}
echo
#提取子串
#${string:position} ?string中,从位|?position开始提取子?/span>
echo ${string:2}
#${string:poistion:length} ?string中,从位|?position开始提取长度ؓ$length的子?/span>
echo ${string:2:5}
echo
#删除操作
#${string#substring} 从变?string的开_删除最短匹?substring的子?/span>
#${string##substring} 从变?string的开_删除最长匹?substring的子?/span>
echo ${string#This is a test}
echo ${string#*is}
echo ${string##*is}
echo
#${string%substring} 从变?string的结,删除最短匹?substring的子?/span>
#${string%%substring} 从变?string的结,删除最长匹?substring的子?/span>
string="i|ban|banana"
echo ${string%ban*}
echo ${string%%ban*}
#关于#%q个如果觉得难记Q可以看下键?q么来记Q?/span>
# #?前面Q??后面Q?的作用就是取字符?/span>
#使用下上面介l过的功能,猜下输出?
string="/etc/init.d/profile"
echo "Dir: " ${string%/*}
echo "File: " ${string##*/}
FileName=${string##*/}
echo "FileName Length: " ${#FileName}
#Note:
#${变量?substring正则表达式} 从字W串开头开始匹配substirng,删除匚w上的表达?/span>
#${变量?substring正则表达式} 从字W串l尾开始匹配substring,删除匚w上的表达?/span>
#${string/substring/replacement} 使用$replacement,来代替第一个匹配的$substring
#${string//substring/replacement} 使用$replacement,来代替每一个匹配的$substring
string="piapiapia"
echo ${string/pia/ufo}
echo ${string//pia/ufo}
#{string/#substring/replacement} 如果$stirng的前~匚w$substring,那么q$replacement来代替匹配到?substring
#{string/%substring/replacement} 如果$stirng的后~匚w$substring,那么q$replacement来代替匹配到?substring
string="i hate myself"
echo ${string/#you/ufo}
echo ${string/#i/ufo}
echo ${string/%self/slefish}
string="/etc/init.d/profile"
#更改W一个文件夹
#当查扑ֆ容中出现?,使用\/转义
echo ${string/#\/etc/etc1}
#如果是下面的语句则会输出Q?/span>
#/etc/etc1/etc/init.d/profile
#因ؓ /#/被处理掉,/etc/ect1被当作了$replacement
echo ${string/#/etc/etc1}
]]>
THIS LINE IS THE 1ST UPPER CASE LINE IN THIS FILE.
this line is the 1st lower case line in this file.
This Line Has All Its First Character Of The Word With Upper Case.
Two lines above this line is empty.
And this is the last line.
1.从单个文件中搜烦指定的字?/h5>
$ grep "this" demo_file
this line is the 1st lower case line in this file.
Two lines above this line is empty.
And this is the last line.2. 在多个文件中索指定的字串
语法Q?br>grep "string" FILE_PATTERN
$ grep "this" demo_*
demo_file:this line is the 1st lower case line in this file.
demo_file:Two lines above this line is empty.
demo_file:And this is the last line.
demo_file1:this line is the 1st lower case line in this file.
demo_file1:Two lines above this line is empty.
demo_file1:And this is the last line.
3. ?grep -i q行大小写无关的搜烦
语法Q?br>grep -i "string" FILE
THIS LINE IS THE 1ST UPPER CASE LINE IN THIS FILE.
this line is the 1st lower case line in this file.
This Line Has All Its First Character Of The Word With Upper Case.
And this is the last line.
4. 使用用正则表辑ּ
语法Q?br>grep "REGEX" filename
Two lines above this line is empty.
5. 用grep -w搜烦整个词,而不是词中的部分字串
THIS LINE IS THE 1ST UPPER CASE LINE IN THIS FILE.
this line is the 1st lower case line in this file.
This Line Has All Its First Character Of The Word With Upper Case.
Two lines above this line is empty.
And this is the last line.
THIS LINE IS THE 1ST UPPER CASE LINE IN THIS FILE.
this line is the 1st lower case line in this file.
Two lines above this line is empty.
And this is the last line.
6. 使用grep -A, -B and -C昄之前、之后、前后的几行
$ cat demo_text
4. Vim Word Navigation
You may want to do several navigation in relation to the words, such as:
* e - go to the end of the current word.
* E - go to the end of the current WORD.
* b - go to the previous (before) word.
* B - go to the previous (before) WORD.
* w - go to the next word.
* W - go to the next WORD.
WORD - WORD consists of a sequence of non-blank characters, separated with white space.
word - word consists of a sequence of letters, digits and underscores.
Example to show the difference between WORD and word
* 192.168.1.1 - single WORD
* 192.168.1.1 - seven words.6.1 昄匚w行之后的N?/h6>
语法Q?br>grep -A "string" FILENAME
Example to show the difference between WORD and word
* 192.168.1.1 - single WORD
* 192.168.1.1 - seven words.
6.2昄匚w行之前的N?/h6>
语法Q?br>grep -B "string" FILENAME
Example to show the difference between WORD and word
* 192.168.1.1 - single WORD
6.3昄匚w行前后的N?/h6>
$ grep -C 2 "Example" demo_text
word - word consists of a sequence of letters, digits and underscores.
Example to show the difference between WORD and word
* 192.168.1.1 - single WORD7.通过GREP_OPTIONS高亮昄搜烦的字?/h5>
$ grep this demo_file
this line is the 1st lower case line in this file.
Two lines above this line is empty.
And this is the last line.
8. 用grep -r递归搜烦全部的文?/h5>
$ grep -r "ramesh" *
9. 使用grep -vq行不匹?/h5>
4. Vim Word Navigation
You may want to do several navigation in relation to the words, such as:
WORD - WORD consists of a sequence of non-blank characters, separated with white space.
word - word consists of a sequence of letters, digits and underscores.
Example to show the difference between WORD and word
* 192.168.1.1 - single WORD
* 192.168.1.1 - seven words.
10. 昄不匹配全部模式的?/h5>
语法Q?br>grep -v -e "pattern" -e "pattern"
$ cat test-file.txt
a
b
c
d
$ grep -v -e "a" -e "b" -e "c" test-file.txt
d11.用grep -c l计匚w的行?/h5>
语法Q?br>grep -c "pattern" filename
$ grep -c "go" demo_text
6$ grep -v -c this demo_file
412. 用grep -l 只显C文件名
$ grep -l this demo_*
demo_file
demo_file113. 只显C匹配的字串
is line is the 1st lower case line
is line
is is the last line14. 昄匚w的位|?/h5>
语法Q?br>grep -o -b "pattern" file
$ cat temp-file.txt
12345
12345
$ grep -o -b "3" temp-file.txt
0:3
6:315. ?grep -n 在输出时昄行号
5: * e - go to the end of the current word.
6: * E - go to the end of the current WORD.
7: * b - go to the previous (before) word.
8: * B - go to the previous (before) WORD.
9: * w - go to the next word.
10: * W - go to the next WORD.
1: #include <stdio.h>
2:
3: #include <sys/types.h>
4:
5: #include <unistd.h>
6:
7: int main(void)
8:
9: {
10:
11: int i;
12:
13: for(i=0; i<2; i++){
14:
15: fork();
16:
17: printf("-");
18:
19: }
20:
21: return 0;
22:
23: }
printf
(
"-\n"
);
printf
(
"-"
);
flush();
1: #include <stdio.h>
2:
3: #include <sys/types.h>
4:
5: #include <unistd.h>
6:
7: int main(void)
8:
9: {
10:
11: int i;
12:
13: for(i=0; i<2; i++){
14:
15: fork();
16:
17: //注意Q下面的printf有“\n?/span>
18:
19: printf("ppid=%d, pid=%d, i=%d \n", getppid(), getpid(), i);
20:
21: }
22:
23: sleep(10); //让进E停留十U,q样我们可以用pstree查看一下进E树
24:
25: return 0;
26:
27: }
28:
ppid=8858, pid=8518, i=0
ppid=8858, pid=8518, i=1
ppid=8518, pid=8519, i=0
ppid=8518, pid=8519, i=1
ppid=8518, pid=8520, i=1
ppid=8519, pid=8521, i=1
$ pstree -p |
grep
fork
|-
bash
(8858)-+-fork(8518)-+-fork(8519)---fork(8521)
| | `-fork(8520)
ctrl+a=开始位|?
ctrl+e=最后位|?
ctrl+k=删除此处x所有内?
ctrl+u=删除此处臛_始所有内?
ctrl+d=删除当前字母
ctrl+w=删除此处到左边的单词
ctrl+y=_脓(chung)由ctrl+uQctrl+dQctrl+w删除的单?
ctrl+r=正在试Q还没弄明白Q呵c?
ctrl+l=相当于clear
ctrl+b=向回Ud
ctrl+f=向前Ud
ctrl+p=向上昄~存命o
ctrl+n=向下昄~存命o
ctrl+d=关闭l端
shift+上或?l端上下滚动
shift+pgup或pgdown=l端上下页滚动
ctrl+shift+f=全屏Q仅限于konsoleQ?
ctrl+shift+n=新终端(terminal和konsole有所不同Q?
ctrl+c=l止
]]>
补充说明Qsort可针Ҏ(gu)本文件的内容Q以行ؓ单位来排序?br />参 敎ͼ
-b 忽略每行前面开始出的空格字W?br /> -c 查文件是否已l按照顺序排序?br /> -d 排序Ӟ处理英文字母、数字及I格字符外,忽略其他的字W?br /> -f 排序Ӟ小写字母视为大写字母?br /> -i 排序Ӟ除了040?76之间的ASCII字符外,忽略其他的字W?br /> -m 几个排序好的文件进行合q?br /> -M 前?个字母依照月份的~写q行排序?br /> -n 依照数值的大小排序?br /> -o<输出文g> 排序后的结果存入指定的文g?br /> -r 以相反的序来排序?br /> -t<分隔字符> 指定排序时所用的栏位分隔字符?br /> +<起始栏位>-<l束栏位> 以指定的栏位来排序,范围pv始栏位到l束栏位的前一栏位?br /> --help 昄帮助?br /> --version 昄版本信息
]]>/*
* =====================================================================================
* Filename: getCurrentTime.c
* Description: methods of get current time
*
* Version: 1.0
* Created: 07/10/2012 09:50:09 AM
*
* Author: zhy (), izualzhy@163.com
* =====================================================================================
*/
#include <time.h>
#include <stdio.h>
int main()
{
time_t curTime = time(NULL);
char* curDate = ctime(&curTime);
printf("%s\n",curDate);
struct tm* localTime = localtime(&curTime);
char s[50];
char* format = "%y-%m-%d %H:%M:%S";
size_t max_size = 49;
size_t result = strftime(s, max_size, format, localTime);
if (result!=0) {
printf("%s\n",s);
}
char* cTime = asctime(localTime);
printf("%s\n", cTime);
return 0;
}
const struct tm *tm);
]]>
{print $0}#!/usr/bin/awk
BEGIN{FS=":";OFS="-";ORS="$\n"}
{
printf FILENAME OFS\
NR OFS\
$1 OFS\
$2 OFS\
$3 OFS\
$4 OFS\
ORS
}
contries-2-USA-3615-237-North America-$
contries-3-Brazil-3286-134-South America-$
contries-4-England-94-56-Europe-$
contries-5-France-211-55-Europe-$
contries-6-Japan-144-120-Asia-$
contries-7-Mexico-762-78-North America-$
contries-8-China-3705-1032-Asia-$
contries-9-India-1267-746-Asia-$
]]>
bin_PROGRAMS=hello
hello_SOURCES=hello.c
bin_PROGRAMS=helloworld
helloworld_SOURCES=hello.c
]]>
configure.in: installing './mkinstalldirs': error while making link: 不允许的操作
configure.in: installing './missing': error while making link: 不允许的操作
configure.in: installing './depcomp': error while making link: 不允许的操作 Linux下的GTK{等?/a>
menphix 发表?2008-06-03 21:09:14
l果q行autogen.shMq不厅R要不是Anjuta的输出高亮还真发C了这L错误Q?br>configure.ac:6: installing `./install-sh'; error while making link: 不允许的操作
configure.ac:6: installing `./missing'; error while making link: 不允许的操作
src/Makefile.am: installing `./depcomp'; error while making link: 不允许的操作
Makefile.am: installing `./INSTALL'; error while making link: 不允许的操作
仔细分析才知道原来是因ؓ把工E放在FAT32分区上了Q而它不支持link!
挪到ext3上就解决了。呵c?
]]>
const char *optstring,
const struct option *longopts, int *longindex);
const char *optstring,
const struct option *longopts, int *longindex);
optstring should be specified as an empty string (""), not NULL.) Long option names may be abbreviated if the abbreviation is unique or is an exact match for
some defined option. A long option may take a parameter, of the form --arg=param or --arg param.
const char *name;
int has_arg;
int *flag;
int val;
};
is: no_argument (or 0) if the option does not take an argument; required_argument (or 1) if the option requires an argument; or optional_argument (or 2) if
the option takes an optional argument.
the equivalent short option character.) Otherwise, getopt_long() returns 0, and flag points to a variable which is set to val if the option is found, but
left unchanged if the option is not found.
option, but does match a short option, it is parsed as a short option instead./*
* =====================================================================================
* Filename: getopt_long_l.c
* Description: getopt_long() learn notes
*
* Version: 1.0
* Created: 06/27/2012 08:25:20 PM
*
* Author: zhy (), izualzhy@163.com
* =====================================================================================
*/
#include <stdio.h>
#include <getopt.h>
int main(int argc, char* argv[])
{
int result, deb;
struct option opts[] = {{"username", required_argument, NULL, 'n'},
{"version", optional_argument, NULL, 'v'},
{"debug", no_argument, &deb, 2},//flag!=NULLӞargument没有用?
{0,0,0,0}//why?
};
while ((result = getopt_long(argc, argv, "n:v::", opts, NULL))!=-1) {
switch (result) {
case 'n'://-n 或?-username
printf("username is %s\n", optarg);
break;
case 'v'://-v 或?--version
printf("version is 1.0.0, %s\n", optarg);
break;
case 0://flag不ؓNULL
printf("debug is %d\targs:%s\n", deb, optarg);
break;
case '?'://未定义的选项
printf("?: %c %c\n", result, optopt);
break;
default:
printf("default: %c\n", result);
break;
}
}
return 0;
}
]]>
const char *optstring);
extern int optind, opterr, optopt;
host是b的参敎ͼkeke是c的参数。但hahaq不是d的参敎ͼ因ؓ它们中间有空格隔开?
When `getopt' finds an option that takes an argument,
the argument value is returned here.
Also, when `ordering' is RETURN_IN_ORDER,
each non-option ARGV-element is returned here. */
This is used for communication to and from the caller
and for communication between successive calls to `getopt'.
non-option elements that the caller should itself scan.
how much of ARGV has been scanned so far. */
for unrecognized options. *//*
* =====================================================================================
* Filename: getopt_l.c
* Description: getopt learning
*
* Version: 1.0
* Created: 06/26/2012 08:13:49 PM
*
* Author: zhy (), izualzhy@163.com
* =====================================================================================
*/
#include <unistd.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
int aflag = 0, bflag = 0, cflag = 0;
int ch;
while ((ch = getopt(argc, argv, "ab:c")) != -1) {
printf("optind: %d\n", optind);
switch (ch) {
case 'a':
printf("Have option: -a\n");
aflag = 1;
printf("The argument of -a is %s\n", optarg);
break;
case 'b':
printf("Have option: -b\n");
bflag = 1;
printf("The argument of -b is %s\n", optarg);
break;
case 'c':
printf("Have option: -c\n");
cflag = 1;
break;
case '?':
printf("Unknown option: %c\n", (char)optopt);
break;
}
}
}
可以自己先试着写下输出的结果:
optind: 2
Have option: -a
The argument of -a is (null)
./getopt_l: invalid option -- 'd'
optind: 3
Unknown option: d
optind: 5
Have option: -b
The argument of -b is foo
如果optstring中的字符串以'+'加号开头或者环境变量POSIXLY_CORRE被设|。那么一遇到不包含选项的命令行参数Qgetopt׃停止Q返?1?
/*
* =====================================================================================
* Filename: getopt_l2.c
* Description:
*
* Version: 1.0
* Created: 06/26/2012 08:37:11 PM
*
* Author: zhy (), izualzhy@163.com
* =====================================================================================
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
int result;
opterr = 0;//?
while ((result = getopt(argc, argv, "ab:c::")) != -1) {
switch (result) {
case 'a':
printf("option=a, optopt=%c, optarg=%s\n", optopt, optarg);
break;
case 'b':
printf("option=b, optopt=%c, optarg=%s\n", optopt, optarg);
break;
case 'c':
printf("option=c, optopt=%c, optarg=%s\n", optopt, optarg);
break;
case '?':
printf("result=?, optopt=%c, optarg=%s\n", optopt, optarg);
default:
printf("default, result=%c\n", result);
break;
}
printf("argv[%d]=%s\n", optind, argv[optind]);
}
printf("result = -1, optind = %d\n", optind);
for ( result = optind; result<argc; result++)
printf("------ argv[%d] = %s\n", result, argv[result]);
printf("\n");
for ( result = 1; result < argc; result++)
printf("at the end------argv[%d] = %s\n", result, argv[result]);
return 0;
}
]]>
在做shell批处理程序时候,l常会涉及到字符串相x作。有很多命o语句Q如Qawk,sed都可以做字符串各U操作?其实shell内置一pd操作W号Q可以达到类似效果,大家知道Q用内部操作符会省略启动外部程序等旉Q因此速度会非常的快?
一、判断读取字W串?/strong> 表达?br>含义 ${var} ${var-DEFAULT} ${var:-DEFAULT} ${var=DEFAULT} ${var:=DEFAULT} ${var+OTHER} ${var:+OTHER} ${var?ERR_MSG} ${var:?ERR_MSG} ${!varprefix*} ${!varprefix@} 加入了??nbsp; 不是意思是Q?当然, 如果变量var已经被设|的? 那么其值就?var. [chengmo@localhost ~]$ echo ${abc-'ok'} [chengmo@localhost ~]$ echo ${abc='ok'} 如果abc 没有声明?" q会labc赋倹{? [chengmo@localhost ~]$ var1=11;var2=12;var3= ${!varprefix*}?{!varprefix@}怼Q可以通过变量名前~字符Q搜索已l定义的变量,无论是否为空倹{?/p> 二、字W串操作Q长度,dQ替换) 表达?br>含义 ${#string} ${string:position} ${string:position:length} ${string#substring} ${string##substring} ${string%substring} ${string%%substring} ${string/substring/replacement} ${string//substring/replacement} ${string/#substring/replacement} ${string/%substring/replacement} 说明Q?* $substring”可以是一?em>正则表达?/em>. 1.长度 [web97@salewell97 ~]$ test='I love china' ${#变量名}得到字符串长? 2.截取字串 [chengmo@localhost ~]$ test='I love china' ${变量?起始:长度}得到子字W串 3.字符串删?/strong> [chengmo@localhost ~]$ test='c:/windows/boot.ini' [chengmo@localhost ~]$ echo ${test%/*} ${变量?substring正则表达式}从字W串开头开始配备substring,删除匚w上的表达式? ${变量?substring正则表达式}从字W串l尾开始配备substring,删除匚w上的表达式? 注意Q?{test##*/},${test%/*} 分别是得到文件名Q或者目录地址最单方法? 4.字符串替?/strong> [chengmo@localhost ~]$ test='c:/windows/boot.ini' ${变量/查找/替换值} 一个?”表C替换第一个,?/”表C替换所?当查找中出现了:?”请加{义符”\/”表C?/p> 三、性能比较 在shell中,通过awk,sed,expr {都可以实现Q字W串上述操作。下面我们进行性能比较? [chengmo@localhost ~]$ test='c:/windows/boot.ini' real 0m0.173s [chengmo@localhost ~]$ time for i in $(seq 10000);do a=$(expr length $test);done; real 0m9.734s 速度相差上百倍,调用外部命o处理Q与内置操作W性能相差非常大。在shell~程中,量用内|操作符或者函数完成。用awk,sedcM会出现这L果?/p> 分类: linux
变量var的? ?var相同
如果var没有被声? 那么׃$DEFAULT作ؓ其?*
如果var没有被声? 或者其gؓI? 那么׃$DEFAULT作ؓ其?*
如果var没有被声? 那么׃$DEFAULT作ؓ其?*
如果var没有被声? 或者其gؓI? 那么׃$DEFAULT作ؓ其?*
如果var声明? 那么其值就?OTHER, 否则׃ؓnull字符?
如果var被设|了, 那么其值就?OTHER, 否则׃ؓnull字符?
如果var没被声明, 那么打?ERR_MSG *
如果var没被讄, 那么打?ERR_MSG *
匚w之前所有以varprefix开头进行声明的变量
匚w之前所有以varprefix开头进行声明的变量
ok
[chengmo@localhost ~]$ echo $abc
ok
[chengmo@localhost ~]$ echo $abc
ok
[chengmo@localhost ~]$ echo ${!v@}
var1 var2 var3
[chengmo@localhost ~]$ echo ${!v*}
var1 var2 var3
$string的长?
?string? 从位|?position开始提取子?
?string? 从位|?position开始提取长度ؓ$length的子?
从变?string的开? 删除最短匹?substring的子?
从变?string的开? 删除最长匹?substring的子?
从变?string的结? 删除最短匹?substring的子?
从变?string的结? 删除最长匹?substring的子?
使用$replacement, 来代替第一个匹配的$substring
使用$replacement, 代替所?/em>匚w?substring
如果$string?em>前缀
如果$string?em>后缀匚w$substring, 那么q$replacement来代替匹配到?substring
[web97@salewell97 ~]$ echo ${#test}
12
[chengmo@localhost ~]$ echo ${test:5}
e china
[chengmo@localhost ~]$ echo ${test:5:10}
e china
[chengmo@localhost ~]$ echo ${test#/}
c:/windows/boot.ini
[chengmo@localhost ~]$ echo ${test#*/}
windows/boot.ini
[chengmo@localhost ~]$ echo ${test##*/}
boot.ini
c:/windows
[chengmo@localhost ~]$ echo ${test%%/*}
[chengmo@localhost ~]$ echo ${test/\//\\}
c:\windows/boot.ini
[chengmo@localhost ~]$ echo ${test//\//\\}
c:\windows\boot.ini
[chengmo@localhost ~]$ time for i in $(seq 10000);do a=${#test};done;
user 0m0.139s
sys 0m0.004s
user 0m1.628s
]]>
Wireless Tools For LinuxQ?/p>
http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/Tools.html
可以看到最新的E_版本是v29Q不q我在用的时候经常碰到这个错误:
[root@y root]# iwlist scanning
lo Interface doesn't support scanning.
usb0 Interface doesn't support scanning.
print_scanning_info: Allocation failed
于是下蝲?9的源码,错误的出处:
realloc: /* (Re)allocate the buffer - realloc(NULL, len) == malloc(len) */ newbuf = realloc(buffer, buflen); if(newbuf == NULL) { if(buffer) free(buffer); fprintf(stderr, "%s: Allocation failed\n", __FUNCTION__); return(-1); } buffer = newbuf; /* Try to read the results */ wrq.u.data.pointer = buffer; wrq.u.data.flags = 0; wrq.u.data.length = buflen; if(iw_get_ext(skfd, ifname, SIOCGIWSCAN, &wrq) < 0) { /* Check if buffer was too small (WE-17 only) */ if((errno == E2BIG) && (range.we_version_compiled > 16)) { /* Some driver may return very large scan results, either * because there are many cells, or because they have many * large elements in cells (like IWEVCUSTOM). Most will * only need the regular sized buffer. We now use a dynamic * allocation of the buffer to satisfy everybody. Of course, * as we don't know in advance the size of the array, we try * various increasing sizes. Jean II */ /* Check if the driver gave us any hints. */ if(wrq.u.data.length > buflen) buflen = wrq.u.data.length; else buflen *= 2; /* Try again */ goto realloc; } E2BIG错误发出后,会修改要realloc的内存块长度
buflen*=2
很让h费解了,加入了些打印消息后编译了下发玎ͼlength=0时也会发出E2BIG的errnoQ很让h费解Q不q以自己目前的知识积累,没法l箋研究下去了?/font>
试着修改了下Q修改的q程中,发现了最开始的|址的这么一块:
slightly bigger scan buffer
于是下蝲了该版本看了下,相关处已l改成了Q?/font>
realloc: /* (Re)allocate the buffer - realloc(NULL, len) == malloc(len) */ newbuf = realloc(buffer, buflen); if(newbuf == NULL) { if(buffer) free(buffer); fprintf(stderr, "%s: Allocation failed\n", __FUNCTION__); return(-1); } buffer = newbuf; /* Try to read the results */ wrq.u.data.pointer = buffer; wrq.u.data.flags = 0; wrq.u.data.length = buflen; if(iw_get_ext(skfd, ifname, SIOCGIWSCAN, &wrq) < 0) { /* Check if buffer was too small (WE-17 only) */ if((errno == E2BIG) && (range.we_version_compiled > 16) && (buflen < 0xFFFF)) { /* Some driver may return very large scan results, either * because there are many cells, or because they have many * large elements in cells (like IWEVCUSTOM). Most will * only need the regular sized buffer. We now use a dynamic * allocation of the buffer to satisfy everybody. Of course, * as we don't know in advance the size of the array, we try * various increasing sizes. Jean II */ /* Check if the driver gave us any hints. */ if(wrq.u.data.length > buflen) buflen = wrq.u.data.length; else buflen *= 2; /* wrq.u.data.length is 16 bits so max size is 65535 */ if(buflen > 0xFFFF) buflen = 0xFFFF; /* Try again */ goto realloc; }
?/p>
不过q里出错Ӟ所得的buffer是空字符Ԍ而不是截断的字符Ԍ所以用处不大,对自q处不大。o(╯□?o
做个记录Q深感自q知识U篏太少Q^时没事拿q这U代码来p学习下?/p>
先看下help
# iwconfig -h
Usage: iwconfig [interface]
interface essid {NNN|any|on|off}
interface mode {managed|ad-hoc|master|...}
interface freq N.NNN[k|M|G]
interface channel N
interface bit {N[k|M|G]|auto|fixed}
interface rate {N[k|M|G]|auto|fixed}
interface enc {NNNN-NNNN|off}
interface key {NNNN-NNNN|off}
interface power {period N|timeout N|saving N|off}
interface nickname NNN
interface nwid {NN|on|off}
interface ap {N|off|auto}
interface txpower {NmW|NdBm|off|auto}
interface sens N
interface retry {limit N|lifetime N}
interface rts {N|auto|fixed|off}
interface frag {N|auto|fixed|off}
interface modulation {11g|11a|CCK|OFDMg|...}
interface commit
Check man pages for more details.
看了下比较需要注意的两个地方Q?/font>
1.essid即wifi热点名称Qiwlist wlan0 scan可以查看当前搜烦到的wifi炏V其中wlan0是你的无U设备名U?/p>
[root@kindle /DuoKan]# iwlist
Usage: iwlist [interface] scanning [essid NNN] [last]
[interface] frequency
[interface] channel
[interface] bitrate
[interface] rate
[interface] encryption
[interface] keys
[interface] power
[interface] txpower
[interface] retry
[interface] ap
[interface] accesspoints
[interface] peers
[interface] event
[interface] auth
[interface] wpakeys
[interface] genie
[interface] modulation
2.key关键字的使用Q数字与ascii是不同的?br>
转篇文章Q写的非常详l:
iwconfig是Linux Wireless Extensions(LWE)的用户层配置工具之一。LWE是Linux下对无线|络配置的工P包括内核的支持、用户层配置工具和驱动接口的支持三部分。目前很多无U网卡都支持LWEQ而且L的Linux发布版本Q比如Redhat Linux、Ubuntu Linux都已l带了这个配|工兗?
1、iwconfig
用法: iwconfig interface [essid {NN|on|off}]
[nwid {NN|on|off}]
[mode {managed|ad-hoc|...}
[freq N.NNNN[k|M|G]]
[channel N]
[ap {N|off|auto}]
[sens N]
[nick N]
[rate {N|auto|fixed}]
[rts {N|auto|fixed|off}]
[frag {N|auto|fixed|off}]
[enc {NNNN-NNNN|off}]
[power {period N|timeout N}]
[retry {limit N|lifetime N}]
[txpower N {mW|dBm}]
[commit]
说明Qiwconfig是LWE最主要的工P可以Ҏ(gu)U网卡的大部分参数进行配|?br>参数Q?br>essidQ设|无U网卡的ESSID(Extension Service Set ID)。通过ESSID来区分不同的无线|络Q正常情况下只有相同ESSID的无U站?br> 才可以互盔R讯Q除非想监听无线|络。其后的参数为双引号括v的ESSID字符Ԍ或者是any/on/offQ如果ESSID字符串中包含
any/no/offQ则需要在前面?--"?br> CZQ?br> #iwconfig eth0 essid any 允许MESSIDQ也是h模式
#iwconfig eth0 essid "My Network" 讄ESSID?My Network"
#iwconfig eth0 essid -- "ANY" 讄ESSID?ANY"
nwid: Network IDQ只用于pre-802.11的无U网卡,802.11|卡利用ESSID和AP的MAC地址来替换nwidQ现在基本上不用讄?br> CZQ?br> #iwconfig eth0 nwid AB34
#iwconfig eth0 nwid off
nick: NicknameQ一些网卡需要设|该参数Q但?02.11协议栈、MAC都没有用到该参数Q一般也不用讄?br> CZQ?br> #iwconfig eth0 nickname "My Linux Node"
modeQ设|无U网卡的工作模式Q可以是
Ad-hocQ不带AP的点对点无线|络
ManagedQ通过多个APl成的网l,无线讑֤可以在这个网l中漫游
MasterQ设|该无线|卡Z个AP
RepeaterQ设|ؓ无线|络中讑֤Q可以{发网l包
SecondaryQ设|ؓ备䆾的AP/Repeater
MonitorQ监听模?br> AutoQ由无线|卡自动选择工作模式
CZQ?br> #iwconfig eth0 mode Managed
#iwconfig eth0 mode Ad-Hoc
freq/channelQ设|无U网卡的工作频率或者频道,于1000的参数被认ؓ是频道,大于10000的参数被认ؓ是频率。频率单位ؓHzQ?br> 可以在数字后面附带k, M, G来改变数量Q比?.4G。频道从1开始。用lwlist工具可以查看无线|卡支持的频?br> 和频道。参数off/auto指示无线|络自动挑选频率?br> 注意Q如果是Managed模式QAP会指C无U网卡的工作频率Q因此该讄的参C被忽略。Ad-hoc模式下只使用该设定的频率
初始无线|络Q如果加入已l存在的Ad-hoc|络则会忽略该设|的频率参数?br> CZQ?br> #iwconfig eth0 freq 2422000000
#iwconfig eth0 freq 2.422G
#iwconfig eth0 channel 3
#iwconfig eth0 channel auto
apQ连接到指定的AP或者无U网l,后面的参数可以是AP的MAC地址Q也可以是iwlist scan出来的标识符。如果是Ad-hocQ则q接?br> 一个已l存在的Ad-hoc|络。用off参数让无U网卡不改变当前已连接的AP下进入自动模式。any/auto参数Q无U网卡自动选择
最好的AP?br> 注意Q如果无U信号低C定程度,无线|络会进入自动选择AP模式?br> CZQ?br> #iwconfig eth0 ap 00:60:1D:01:23:45
#iwconfig eth0 ap any
#iwconfig eth0 ap off
rate/bitQ如果无U网卡支持多速率Q则可以通过该命令设|工作的速率。小?000的参数由具体的无U网卡驱动定义,一般是传输?br> 率的索引|大于1000的ؓ速率Q单位bpsQ可以在数字后面附带k, M, G来指定数量。auto参数让无U网卡自动选择速率
fixed参数让无U网卡不使用自动速率模式?br> CZQ?br> #iwconfig eth0 rate 11M
#iwconfig eth0 rate auto
#iwconfig eth0 rate 5.5M auto //自动选择5.5M以下的速率
txpowerQ如果无U网卡支持多发射功率讑֮Q则使用该参数设定发,单位为dBmQ如果指定ؓWQ毫瓦)Q只转换公式为:
dBm=30+log(W)。参数on/off可以打开和关闭发单元,auto和fixed指定无线是否自动选择发射功率?br> CZQ?br> #iwconfig eth0 txpower 15
#iwconfig eth0 txpower 30mW
#iwconfig eth0 txpower auto
#iwconfig eth0 txpower off
sensQ设|接收灵敏度的下限,在该下限之下Q无U网卡认无线|络信号太差Q不同的|卡会采取不同的措施Q一些现代的无线|卡
会自动选择新的AP。正的参Cؓraw dataQ直接传l无U网卡驱动处理,一般认为是癑ֈ比。负DCdBm倹{?br> CZQ?br> #iwconfig eth0 sens -80
#iwconfig eth0 sens 2
retryQ设|无U网卡的重传机制。limit ‘value?指定最大重传次敎ͼlifetime ‘value’指定最镉K试时_单位为秒Q可以附带m和u?br> 指定单位为毫U和微秒。如果无U网卡支持自动模式,则在limit和lifetime之前q可以附加min和max来指定上下限倹{?br> CZQ?br> #iwconfig eth0 retry 16
#iwconfig eth0 retry lifetime 300m
#iwconfig eth0 retry min limit 8
rtsQ指定RTS/CTS握手方式Q用RTS/CTS握手会增加额外开销Q但如果无线|络中有隐藏无线节点或者有很多无线节点时可以提高性能?br> 后面的参数指定一个用该机制的最包的大,如果该值等于最大包大小Q则相当于禁止用该机制。可以用auto/off/fixed
参数?br> CZQ?br> #iwconfig eth0 rts 250
#iwconfig eth0 rts off
fragQ设|发送数据包的分片大。设|分片会增加额外开销Q但在噪声环境下可以提高数据包的到达率。一般情况下该参数小于最大包
大小Q有些支持Burst模式的无U网卡可以设|大于最大包大小的值来允许Burst模式。还可以使用auto/fixed/off参数?br> CZQ?br> #iwconfig eth0 frag 512
#iwconfig eth0 frag off
key/enc[ryption]Q设|无U网卡用的加密密钥Q此处ؓ讄WEP模式的加密keyQ如果要使用WPAQ需要wpa_supplicant工具包?br> 密钥参数可以?XXXX-XXXX-XXXX-XXXX 或?XXXXXXXX 格式的十六进制数|也可以是s:xxxxxx的ASCII字符。如果在密钥参数之前
加了[index]Q则只是讄该烦引值对应的密钥Qƈ不改变当前的密钥。直接指定[index]值可以设|当前用哪一个密钥。指定on/
off可以控制是否使用加密模式。open/restricted指定加密模式Q取决于不同的无U网卡,大多数无U网卡的open模式不用加密且
允许接收没有加密的数据包Qrestricted模式使用加密。可以用多个key参数Q但只有最后一个生效?br> WEP密钥可以?0bitQ用10个十六进制数字或?个ASCII字符表示Q也可以?28bitQ用26个十六进制数字或?3个ASCII字符?br> C?
CZQ?br> #iwconfig eth0 key 0123-4567-89
#iwconfig eth0 key [3] 0123-4567-89
#iwconfig eth0 key s:password [2]
#iwconfig eth0 key [2]
#iwconfig eth0 key open
#iwconfig eth0 key off
#iwconfig eth0 key restricted [3] 0123456789
#iwconfig eth0 key 01-23 key 45-67 [4] key [4]
powerQ设|无U网卡的甉|理模式。period ‘value?指定唤醒的周期,timeout ‘value’指定进入休眠的{待旉Q这两个参数之前可以
加min和max修饰Q这些值的单位为秒Q可以附加m和u来指定毫U和微秒。off/on参数指定是否允许甉|理Qall/unicast/multicast
指定允许唤醒的数据包cd?br> CZQ?br> #iwconfig eth0 power period 2
#iwconfig eth0 power 500m unicast
#iwconfig eth0 power timeout 300u all
#iwconfig eth0 power off
#iwconfig eth0 power min period 2 power max period 4
commitQ提交所有的参数修改l无U网卡驱动。有些无U网卡驱动会先缓存无U网卡参CQ用这个命令来让无U网卡的参数修改生效。不q一
般不需要用该命oQ因为无U网卡驱动最l都会是参数的修改生效,一般在debug时会用到?br>2、参考文档:
iwconfig(8) 工具 Man手册?
sudo /etc/init.d/nfs-kernel-server restart
可以了Q如果还是不行,用rpc.mountd试一下?/p>
对于内核而言Q所有打开的文仉通过文g描述W引用。例如对于Linux应用E序员来Ԍ音频~程接口实际上就是一l音频设备文Ӟ通过它们可以从声卡读取数据,或者向声卡写入数据Qƈ且能够对声卡q行控制Q设|采样频率和声道数目{等?
当读或写一个文件时Q用open或createq回的文件描q符标识该文Ӟ其作ؓ参数传送给read或write?
UNIXpȝshell使用文g描述W?与进E的标准输入相关联,文g描述W?与标准输出相兌Q文件描q符2与标准出错相兌。在依从POSIX的应用程序中Q?Q?Q?应当替换成常?/p>
/* Standard file descriptors. */
#define STDIN_FILENO 0 /* Standard input. */
#define STDOUT_FILENO 1 /* Standard output. */
#define STDERR_FILENO 2 /* Standard error output. */
//defined in /usr/include/unistd.h?/span>
1. open, creat - 用来 打开和创?一?文g或设?
描述Q?/p>
int open(const char *pathname, int flags);
int open(const char *pathname, int flags, mode_t mode)
int creat(const char *pathname, mode_t mode);
open() 通常 用于 ?路径?转换?一?文g描述W?(一?非负??整数, ?read , write {?I/O操作?会被?. ?open() 调用 成功, 它会 q回 一?新的 文g描述W?(永远?未用 描述W的 最?. q个调用 创徏 一?新的 打开文g, ?分配 一?新的 独一?二的 文g描述W? 不会?q行中的 M 其他E序 ׃n (?可以 通过 fork (2) pȝ调用 实现 ׃n). q个 新的 文g描述W?在其??打开文g操作 的函??使用.(参?fcntl(2)). 文g?d 指针 ?|于 文g头参?flags 是通过 O_RDONLY, O_WRONLY ?O_RDWR (指明 文g 是以 只读 , 只写 ?d 方式 打开? ?下面?零个
?多个 可选模?按位 -or 操作 得到的(模式很多Q就不脓(chung)了,直接man看下卛_Q以上描qC是从man 2 open里复制的Q?
create函数{效?open(pathname, O_WRONLY | O_CREAT | O_TRUNC, mode);
两个函数?lt;fcntl.h>都可以找到函数声明?
2. close函数用来关闭一个文?
描述Q?/p>
#include <unistd.h>
int close(int fd);
当一个进E终止时Q内核自动关闭它所有打开的文件。很多程序利用了q一功能而不昑ּ的用close关闭打开文g?
3. lseekQ设|文件偏U量
描述Q?
每个打开的文仉有一个与其相兌的“当前文件偏U量?current file offset)。它通常是一个非负整敎ͼ用以度量从文件开始处计算的字节数。通常Q读、写操作都从文g偏移量处开始,打开一个文件时Q除非指定O_APPENDQ否则该偏移量设|ؓ0.
#include<unistd.h>
off_t lseek(int fileds, off_t offset, int whence);
SEEK_SET
The offset is set to offset bytes.
SEEK_CUR
The offset is set to its current location plus offset bytes.
SEEK_END
The offset is set to the size of the file plus offset bytes.
可以用下列方式确定打开文g的当前偏U量Q?
off_t currpos = lseek(fd, 0, SEEK_CUR);
q种Ҏ(gu)也可以用来确定所涉及的文件是否可以设|偏U量。如果文件描q符引用的是一个管道、FIFO或网l套接字Q则lseekq回-1Qƈerrno讄为ESPIPE?
lseek仅将当前的文件偏U量记录在内怸Q它q不引vMIO操作。然后,该偏U量用于下一个读写操作?
4. readQ从打开文g中读数据
描述Q?
ssize_t read(int fd, void *buf, size_t count);
成功q回d的字节数Q若已到文gl尾则返?Q若出错则返?1.
5. writeQ向打开的文件写入数据?
ssize_t write(int fd, const void *buf, size_t count);
代码CZQ?/b>
从标准输入读取,写到标准输出Q?/p>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
const int BUFFSIZE = 4096;
int main()
{
int n;
char buf[BUFFSIZE];
while ((n=read(STDIN_FILENO, buf, BUFFSIZE)) > 0)
if (write(STDOUT_FILENO, buf, n) != n) {
printf("write error\n");
exit(1);
}
if (n < 0) {
printf("read error\n");
exit(1);
}
exit(0);
}
@desktop:/media/C0FE-F76A/a$ ls
createFile.cpp doubleherit2.cpp doubleherit.cpp myfind.sh test.os test.tt translation如何加下划线 新文?br>@desktop:/media/C0FE-F76A/hanvon/a$ myfind void fun_a
virtual void fun_a() {
void fun_a() {
doubleherit2.cpp
void fun_a() {
void fun_a() {
doubleherit.cpp
@desktop:/media/C0FE-F76A/a$