楼主: changyongid

一天一个Linux命令

[复制链接]
发表于 2009-9-4 17:20:08 | 显示全部楼层
加精是应该的。
快速插入一楼。
 楼主| 发表于 2009-9-4 17:32:37 | 显示全部楼层
本帖最后由 changyongid 于 2009-9-4 17:57 编辑

我们还是先来help一下,因为看帮助文档是一个非常好的习惯。

[changyongid@localhost src]$ od --help
Usage: od [OPTION]... [FILE]...
  or:  od [-abcdfilosx]... [FILE] [[+]OFFSET[.]]
  or:  od --traditional [OPTION]... [FILE] [[+]OFFSET[.] [+][LABEL][.]]

Write an unambiguous representation, octal bytes by default,
of FILE to standard output.  With more than one FILE argument,
concatenate them in the listed order to form the input.
With no FILE, or when FILE is -, read standard input.

All arguments to long options are mandatory for short options.
  -A, --address-radix=RADIX   decide how file offsets are printed 指定地址基数,这里的RADIX在help下面有详细的解释。
  -j, --skip-bytes=BYTES      skip BYTES input bytes first
  -N, --read-bytes=BYTES      limit dump to BYTES input bytes
  -S, --strings[=BYTES]       output strings of at least BYTES graphic chars
  -t, --format=TYPE           select output format or formats 数据显示格式 ,同样的,TYPE在help的下面也有详细的解释。
  -v, --output-duplicates     do not use * to mark line suppression
  -w, --width[=BYTES]         output BYTES bytes per output line
      --traditional           accept arguments in traditional form
      --help     显示此帮助信息并退出
      --version  输出版本信息并退出

我们比较常用的就是-A 和 -t参数了。。
RADIX的说明如下:

RADIX is d for decimal, o for octal, x for hexadecimal or n for none.

即:
d -十进制
o -八进制
x -十六进制
n -不打印偏移植

TYPE的说明如下:
TYPE is made up of one or more of these specifications:

  a          named character, ignoring high-order bit
  c          ASCII character or backslash escape ASCII字符或反斜杠序列
  d[SIZE]    signed decimal, SIZE bytes per integer有符号十进制数
  f[SIZE]    floating point, SIZE bytes per integer浮点数
  o[SIZE]    octal, SIZE bytes per integer八进制(系统默认值为02)
  u[SIZE]    unsigned decimal, SIZE bytes per integer无符号十进制数
  x[SIZE]    hexadecimal, SIZE bytes per integerx 十六进制数

除了选项c以外的其他选项后面都可以跟一个十进制数n,指定每个显示值所包含的字节数。

说明:od命令系统默认的显示方式是八进制,这也是该命令的名称由来(Octal Dump)。但这不是最有用的显示方式,用ASCII码和十六进制组合的方式能提供更有价值的信息输出。
 楼主| 发表于 2009-9-4 17:59:29 | 显示全部楼层
来个列子,其中mmu为我编译一个程序后生成的可执行文件。输出太多,我没有贴全。
[changyongid@localhost mmu]$ od -Ax mmu
000000 000007 165000 177776 165377 177776 165377 177776 165377
000010 177776 165377 177776 165377 170000 162637 177776 165377
000020 040160 030000 155001 161640 000033 165400 000041 165400
000030 000141 165400 000351 165400 000361 165400 150100 162637
000040 170100 162637 000542 165400 000626 165400 170322 161441
000050 152063 161640 170337 161441 150044 162637 000361 165400
000060 170137 161441 160040 162637 170040 162637 177776 165377
000070 160004 161116 057777 164455 160024 162637 170024 162637
000080 117777 164375 000000 030020 040104 030000 040154 030000
000090 044054 030000 040200 030000 043440 030000 140015 160640
0000a0 154000 164455 130004 161114 022123 161640 030000 161640
 楼主| 发表于 2009-9-4 18:11:23 | 显示全部楼层
这个od命令,平时没怎么用过,确实不知道有什么实用的地方。
发表于 2009-9-5 17:37:52 | 显示全部楼层
期待今天的更新。
 楼主| 发表于 2009-9-5 21:06:26 | 显示全部楼层
嘿嘿。今 天周末。。本来想给大家放天假。。。

恰 今天有个文档要编辑整理下。。。

不过,还是继续的好。。说好一天一个的。。。呆会更新。。。谢谢支持。
 楼主| 发表于 2009-9-7 08:24:39 | 显示全部楼层
周末停了两天。  宿舍里不是很方便。。。。
 楼主| 发表于 2009-9-7 08:27:40 | 显示全部楼层
前面我们学习了几个查看文件内容的命令。会用这几个命令,查看一般的文件内容也就够用了。。。
那么,接下来学习一个命令,用于文件内容的统计。。。
 楼主| 发表于 2009-9-7 08:36:00 | 显示全部楼层
这个命令就是 wc  我们先来help一下。
[changyongid@localhost ~]$ wc --help
用法:wc [选项]... [文件]...
  或:wc [选项]... --files0-from=F
Print newline, word, and byte counts for each FILE, and a total line if
more than one FILE is specified.  With no FILE, or when FILE is -,打印文件的行、字、字节数
read standard input. 没有指定文件时,则从标准输入读取
  -c, --bytes            print the byte counts字节数
  -m, --chars            print the character counts 这个好像也是字节数
  -l, --lines            print the newline counts行数
      --files0-from=F    read input from the files specified by
                           NUL-terminated names in file F;
                           If F is - then read names from standard input
  -L, --max-line-length  print the length of the longest line 最长行的长度
  -w, --words            print the word counts字数
      --help     显示此帮助信息并退出
      --version  输出版本信息并退出
 楼主| 发表于 2009-9-7 08:48:07 | 显示全部楼层
现在来试一下这个命令。。。有名为 tt 的一个文件。。我们来对其操作一下。。

[changyongid@localhost ~]$ cat tt                        //这里是tt的内容
ok let is abc def g
abc efg
asdfghjkldafsdfa
[changyongid@localhost ~]$ wc -c tt              //字节数
45 tt
[changyongid@localhost ~]$ wc -m tt             //这个跟字节数相同,不敢确定
45 tt
[changyongid@localhost ~]$ wc -l tt              //行数
3 tt
[changyongid@localhost ~]$ wc -L tt               //最长行的字符数
19 tt
[changyongid@localhost ~]$ wc -w tt            //字数,以空格分开的
9 tt
 楼主| 发表于 2009-9-8 19:06:40 | 显示全部楼层
前面所学的命令都是针对文件的。。。现在开始来学习针对目录的命令吧。。。
cd   这个命令很简单,也很基本。。也最常用。
 楼主| 发表于 2009-9-8 19:07:29 | 显示全部楼层
首先,我们来help一下。。
[changyongid@localhost vivi]$ cd --help
bash: cd: --: invalid option
cd: usage: cd [-L|-P] [dir]

可以看到,这个命令的参数非常的简单。
 楼主| 发表于 2009-9-8 21:45:59 | 显示全部楼层
继续来看。 help得到的信息很少,那么就man一下。。 截取一些有用的信息。
Change  the  current directory to dir.  The variable HOME is the
              default dir.  
The  -P  option  says  to use the physical directory structure instead of
              following symbolic links (see also the  -P  option  to  the  set
              builtin command); the -L option forces symbolic links to be fol-
              lowed.  An argument of - is equivalent to $OLDPWD.   

英语不好,大意是 改变当前目录到参数dir这个目录里。HOME是进入终端时的默认目录。
至于-P 和-L命令我也没搞大清楚。大概跟链接link有关

还有一个比较有用的就是  - 参数。。它代表上一个进入的目录。。
比如:
[changyongid@Fedora ~]$ pwd
/home/changyongid
可以看到,当前目录是这个用户的主目录。。。
[changyongid@Fedora ~]$ cd /
[changyongid@Fedora /]$ pwd
/
这样之后,又到了根目录里。。。
那么:
[changyongid@Fedora /]$ cd -
/home/changyongid
[changyongid@Fedora ~]$ pwd
/home/changyongid
这样,看到,又回到上一次进入的目录。。。。

这个参数感觉非常的有用。。用起来很方便。。。当然,这里具的例子可能不恰当,因为路径很少,当路径很长时它的作用就明显了。

直接cd 不带参数,则会进入当前用户主目录。
 楼主| 发表于 2009-9-8 21:48:53 | 显示全部楼层
另外还有两个小技巧。
cd !$          #把上个命令的参数作为输入。
cd ~         #同样也是回到主目录

其实,这都是跟环境变量很有关系。
先了解这么多,今天有些累。。。散会。
 楼主| 发表于 2009-9-8 21:50:05 | 显示全部楼层
另外还有两个小技巧。
cd !$          #把上个命令的参数作为输入。
cd ~         #同样也是回到主目录

其实,这都是跟环境变量很有关系。
先了解这么多,今天有些累。。。散会。
 楼主| 发表于 2009-9-9 08:29:45 | 显示全部楼层
又是一天的开始,我们继续努力。
 楼主| 发表于 2009-9-9 08:32:54 | 显示全部楼层
本帖最后由 changyongid 于 2009-9-9 08:36 编辑

学习cd命令的时候,看到我打的pwd命令了吧。。。。那么这个命令是干什么的呢?相信你肯定已经知道了。没错。我们来man一下
PWD(1)                           User Commands                          PWD(1)

NAME
       pwd - print name of current/working directory  

SYNOPSIS
       pwd [OPTION]...

DESCRIPTION
       Print the full filename of the current working directory.
打印当前工作目录的绝对路径

       -L, --logical
              use PWD from environment, even if it contains symlinks

       -P, --physical
              avoid all symlinks

       --help display this help and exit

       --version
              output version information and exit

至于-P -L的选项,我还不知道是什么意思。。

 楼主| 发表于 2009-9-9 08:46:03 | 显示全部楼层
今天这个命令挺简单的。好像偷懒了。。
那么来规划一下未来几天要学习的命令吧。。。
mkdir  创建目录
rmdir   删除目录
ls   列出一个目录中的文件
cp  复制
mv 移动
rm 删除
一看就知道这些命令在我们的日常使用中的频率有多么高。所以好好的掌握是非常有必要的。
 楼主| 发表于 2009-9-10 15:45:12 | 显示全部楼层
有时候就是这样,脑子一下子僵在那里……突然想不动事情。

于是,再来学习一个命令。。。。

话又说回来。这些命令,如果不经常的去敲打的话,学到后面,很容易就忘了前面,特别是那些参数,忘起来就更快了。所以,还是有必要定时回过头去翻翻前面的贴子。

这样的话,就定个定时器,中断触发,专门的处理函数去响应。。。。

学习就是这个道理,给自己定个定时器,采用中断触发,定时回过头来复习已学过的内容。这样我们的大脑这台cpu才能跑的更好。。。
如查采取循环的模式,一个循环回来响应一次这个“复习”处理函数,那可就时间长了。说不定我们的cpu一直跑下去了,再也不回头了。。。这就是人的特殊性,因为这个程序往往是不循环的……
 楼主| 发表于 2009-9-10 15:50:06 | 显示全部楼层
ok 。。。mkdir。

[changyongid@localhost ~]$ mkdir --help
用法:mkdir [选项]... 目录...
若目录不是已经存在则创建目录。

长选项必须用的参数在使用短选项时也是必需的。
  -m, --mode=MODE   set file mode (as in chmod), not a=rwx - umask 对新建目录设置存取权限
  -p, --parents     no error if existing, make parent directories as needed 如果路径中有个目录不存在,则创建它
  -v, --verbose     print a message for each created directory 会显示出提示信息。这个选项许多命令里都会有。大至是一个提示的作用,让我们用户可以看到操作的结果。
  -Z, --context=CTX  set the SELinux security context of each created
                      directory to CTX
      --help     显示此帮助信息并退出
      --version  输出版本信息并退出
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关于我们  -  服务条款  -  使用指南  -  站点地图  -  友情链接  -  联系我们
电子工程网 © 版权所有   京ICP备16069177号 | 京公网安备11010502021702
快速回复 返回顶部 返回列表