1、怎么查看全部命令?
要想在Linux下方便迅速地工作,熟悉Linux命令是一个必须的过程。从我们常见的命令ls出发怎么才能知道全部的命令呢?
首先,用which命令获得ls命令的路径:
which ls
此命令输出如下:/usr/bin/ls
然后查看/usr/bin/ls这个文件是由哪个软件包提供的,用下面这个命令:dpkg -S /usr/bin/ls
此命令输出如下:coreutils: /usr/bin/split
最后,查看coreutils这个软件包的全部内容:dpkg -L coreutils
此命令输出如下:/.
/bin
/bin/cat
/bin/chgrp
/bin/chmod
/bin/chown
/bin/cp
/bin/date
/bin/dd
/bin/df
/bin/dir
/bin/echo
/bin/false
/bin/ln
/bin/ls
/bin/mkdir
/bin/mknod
/bin/mv
/bin/pwd
/bin/readlink
/bin/rm
/bin/rmdir
/bin/vdir
/bin/sleep
/bin/stty
/bin/sync
/bin/touch
/bin/true
/bin/uname
/sbin
/usr
/usr/share
/usr/share/doc
/usr/share/doc/coreutils
/usr/share/doc/coreutils/AUTHORS
/usr/share/doc/coreutils/THANKS.gz
/usr/share/doc/coreutils/TODO.gz
/usr/share/doc/coreutils/THANKS-to-translators
/usr/share/doc/coreutils/buildinfo.gz
/usr/share/doc/coreutils/NEWS.Debian.gz
/usr/share/doc/coreutils/changelog.gz
/usr/share/doc/coreutils/README.Debian
/usr/share/doc/coreutils/copyright
/usr/share/doc/coreutils/NEWS.gz
/usr/share/doc/coreutils/README.gz
/usr/share/doc/coreutils/changelog.Debian.gz
/usr/share/info
/usr/share/info/coreutils.info.gz
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/cat.1.gz
/usr/share/man/man1/chgrp.1.gz
/usr/share/man/man1/chown.1.gz
/usr/share/man/man1/cksum.1.gz
/usr/share/man/man1/comm.1.gz
/usr/share/man/man1/cp.1.gz
/usr/share/man/man1/cut.1.gz
/usr/share/man/man1/date.1.gz
/usr/share/man/man1/dd.1.gz
/usr/share/man/man1/df.1.gz
/usr/share/man/man1/dir.1.gz
/usr/share/man/man1/dirname.1.gz
/usr/share/man/man1/du.1.gz
/usr/share/man/man1/echo.1.gz
/usr/share/man/man1/env.1.gz
/usr/share/man/man1/expand.1.gz
/usr/share/man/man1/expr.1.gz
/usr/share/man/man1/factor.1.gz
/usr/share/man/man1/fmt.1.gz
/usr/share/man/man1/fold.1.gz
/usr/share/man/man1/groups.1.gz
/usr/share/man/man1/head.1.gz
/usr/share/man/man1/hostid.1.gz
/usr/share/man/man1/id.1.gz
/usr/share/man/man1/chmod.1.gz
/usr/share/man/man1/join.1.gz
/usr/share/man/man1/link.1.gz
/usr/share/man/man1/ln.1.gz
/usr/share/man/man1/logname.1.gz
/usr/share/man/man1/ls.1.gz
/usr/share/man/man1/md5sum.1.gz
/usr/share/man/man1/mkdir.1.gz
/usr/share/man/man1/mkfifo.1.gz
/usr/share/man/man1/mknod.1.gz
/usr/share/man/man1/mv.1.gz
/usr/share/man/man1/nl.1.gz
/usr/share/man/man1/nohup.1.gz
/usr/share/man/man1/od.1.gz
/usr/share/man/man1/pathchk.1.gz
/usr/share/man/man1/pinky.1.gz
/usr/share/man/man1/pr.1.gz
/usr/share/man/man1/printenv.1.gz
/usr/share/man/man1/printf.1.gz
/usr/share/man/man1/ptx.1.gz
/usr/share/man/man1/pwd.1.gz
/usr/share/man/man1/rm.1.gz
/usr/share/man/man1/rmdir.1.gz
/usr/share/man/man1/seq.1.gz
/usr/share/man/man1/sha1sum.1.gz
/usr/share/man/man1/shred.1.gz
/usr/share/man/man1/sleep.1.gz
/usr/share/man/man1/sort.1.gz
/usr/share/man/man1/stat.1.gz
/usr/share/man/man1/stty.1.gz
/usr/share/man/man1/sum.1.gz
/usr/share/man/man1/sync.1.gz
/usr/share/man/man1/tac.1.gz
/usr/share/man/man1/tail.1.gz
/usr/share/man/man1/tee.1.gz
/usr/share/man/man1/test.1.gz
/usr/share/man/man1/touch.1.gz
/usr/share/man/man1/tr.1.gz
/usr/share/man/man1/tsort.1.gz
/usr/share/man/man1/tty.1.gz
/usr/share/man/man1/uname.1.gz
/usr/share/man/man1/unexpand.1.gz
/usr/share/man/man1/uniq.1.gz
/usr/share/man/man1/users.1.gz
/usr/share/man/man1/vdir.1.gz
/usr/share/man/man1/wc.1.gz
/usr/share/man/man1/who.1.gz
/usr/share/man/man1/whoami.1.gz
/usr/share/man/man1/yes.1.gz
/usr/share/man/man1/chcon.1.gz
/usr/share/man/man1/runcon.1.gz
/usr/share/man/man1/basename.1.gz
/usr/share/man/man1/csplit.1.gz
/usr/share/man/man1/dircolors.1.gz
/usr/share/man/man1/false.1.gz
/usr/share/man/man1/install.1.gz
/usr/share/man/man1/nice.1.gz
/usr/share/man/man1/paste.1.gz
/usr/share/man/man1/readlink.1.gz
/usr/share/man/man1/split.1.gz
/usr/share/man/man1/true.1.gz
/usr/share/man/man1/unlink.1.gz
/usr/share/man/man8
/usr/share/man/man8/chroot.8.gz
/usr/share/locale
/usr/share/locale/af
/usr/share/locale/af/LC_TIME
/usr/share/locale/be
/usr/share/locale/be/LC_TIME
/usr/share/locale/bg
/usr/share/locale/bg/LC_TIME
/usr/share/locale/ca
/usr/share/locale/ca/LC_TIME
/usr/share/locale/cs
/usr/share/locale/cs/LC_TIME
/usr/share/locale/da
/usr/share/locale/da/LC_TIME
/usr/share/locale/de
/usr/share/locale/de/LC_TIME
/usr/share/locale/el
/usr/share/locale/el/LC_TIME
/usr/share/locale/es
/usr/share/locale/es/LC_TIME
/usr/share/locale/et
/usr/share/locale/et/LC_TIME
/usr/share/locale/eu
/usr/share/locale/eu/LC_TIME
/usr/share/locale/fi
/usr/share/locale/fi/LC_TIME
/usr/share/locale/fr
/usr/share/locale/fr/LC_TIME
/usr/share/locale/ga
/usr/share/locale/ga/LC_TIME
/usr/share/locale/gl
/usr/share/locale/gl/LC_TIME
/usr/share/locale/hr
/usr/share/locale/hr/LC_TIME
/usr/share/locale/hu
/usr/share/locale/hu/LC_TIME
/usr/share/locale/it
/usr/share/locale/it/LC_TIME
/usr/share/locale/ja
/usr/share/locale/ja/LC_TIME
/usr/share/locale/ko
/usr/share/locale/ko/LC_TIME
/usr/share/locale/lg
/usr/share/locale/lg/LC_TIME
/usr/share/locale/ms
/usr/share/locale/ms/LC_TIME
/usr/share/locale/nb
/usr/share/locale/nb/LC_TIME
/usr/share/locale/nl
/usr/share/locale/nl/LC_TIME
/usr/share/locale/no
/usr/share/locale/no/LC_TIME
/usr/share/locale/pl
/usr/share/locale/pl/LC_TIME
/usr/share/locale/pt
/usr/share/locale/pt/LC_TIME
/usr/share/locale/pt_BR
/usr/share/locale/pt_BR/LC_TIME
/usr/share/locale/ru
/usr/share/locale/ru/LC_TIME
/usr/share/locale/rw
/usr/share/locale/rw/LC_TIME
/usr/share/locale/sk
/usr/share/locale/sk/LC_TIME
/usr/share/locale/sl
/usr/share/locale/sl/LC_TIME
/usr/share/locale/sv
/usr/share/locale/sv/LC_TIME
/usr/share/locale/tr
/usr/share/locale/tr/LC_TIME
/usr/share/locale/vi
/usr/share/locale/vi/LC_TIME
/usr/share/locale/zh_CN
/usr/share/locale/zh_CN/LC_TIME
/usr/share/locale/zh_TW
/usr/share/locale/zh_TW/LC_TIME
/usr/bin
/usr/bin/[
/usr/bin/dircolors
/usr/bin/du
/usr/bin/install
/usr/bin/link
/usr/bin/mkfifo
/usr/bin/nohup
/usr/bin/shred
/usr/bin/stat
/usr/bin/unlink
/usr/bin/cksum
/usr/bin/comm
/usr/bin/csplit
/usr/bin/cut
/usr/bin/expand
/usr/bin/fmt
/usr/bin/fold
/usr/bin/head
/usr/bin/join
/usr/bin/md5sum
/usr/bin/nl
/usr/bin/od
/usr/bin/paste
/usr/bin/pr
/usr/bin/ptx
/usr/bin/sha1sum
/usr/bin/sort
/usr/bin/split
/usr/bin/sum
/usr/bin/tac
/usr/bin/tail
/usr/bin/tr
/usr/bin/tsort
/usr/bin/unexpand
/usr/bin/uniq
/usr/bin/wc
/usr/bin/basename
/usr/bin/dirname
/usr/bin/env
/usr/bin/expr
/usr/bin/factor
/usr/bin/id
/usr/bin/logname
/usr/bin/pathchk
/usr/bin/printenv
/usr/bin/printf
/usr/bin/seq
/usr/bin/tee
/usr/bin/test
/usr/bin/tty
/usr/bin/whoami
/usr/bin/yes
/usr/bin/chcon
/usr/bin/runcon
/usr/bin/hostid
/usr/bin/nice
/usr/bin/pinky
/usr/bin/users
/usr/bin/who
/usr/bin/groups
/usr/sbin
/usr/sbin/chroot
/usr/share/man/man1/[.1.gz
/usr/share/man/man1/md5sum.textutils.1.gz
/usr/share/locale/af/LC_TIME/coreutils.mo
/usr/share/locale/be/LC_TIME/coreutils.mo
/usr/share/locale/bg/LC_TIME/coreutils.mo
/usr/share/locale/ca/LC_TIME/coreutils.mo
/usr/share/locale/cs/LC_TIME/coreutils.mo
/usr/share/locale/da/LC_TIME/coreutils.mo
/usr/share/locale/de/LC_TIME/coreutils.mo
/usr/share/locale/el/LC_TIME/coreutils.mo
/usr/share/locale/es/LC_TIME/coreutils.mo
/usr/share/locale/et/LC_TIME/coreutils.mo
/usr/share/locale/eu/LC_TIME/coreutils.mo
/usr/share/locale/fi/LC_TIME/coreutils.mo
/usr/share/locale/fr/LC_TIME/coreutils.mo
/usr/share/locale/ga/LC_TIME/coreutils.mo
/usr/share/locale/gl/LC_TIME/coreutils.mo
/usr/share/locale/hr/LC_TIME/coreutils.mo
/usr/share/locale/hu/LC_TIME/coreutils.mo
/usr/share/locale/it/LC_TIME/coreutils.mo
/usr/share/locale/ja/LC_TIME/coreutils.mo
/usr/share/locale/ko/LC_TIME/coreutils.mo
/usr/share/locale/lg/LC_TIME/coreutils.mo
/usr/share/locale/ms/LC_TIME/coreutils.mo
/usr/share/locale/nb/LC_TIME/coreutils.mo
/usr/share/locale/nl/LC_TIME/coreutils.mo
/usr/share/locale/no/LC_TIME/coreutils.mo
/usr/share/locale/pl/LC_TIME/coreutils.mo
/usr/share/locale/pt/LC_TIME/coreutils.mo
/usr/share/locale/pt_BR/LC_TIME/coreutils.mo
/usr/share/locale/ru/LC_TIME/coreutils.mo
/usr/share/locale/rw/LC_TIME/coreutils.mo
/usr/share/locale/sk/LC_TIME/coreutils.mo
/usr/share/locale/sl/LC_TIME/coreutils.mo
/usr/share/locale/sv/LC_TIME/coreutils.mo
/usr/share/locale/tr/LC_TIME/coreutils.mo
/usr/share/locale/vi/LC_TIME/coreutils.mo
/usr/share/locale/zh_CN/LC_TIME/coreutils.mo
/usr/share/locale/zh_TW/LC_TIME/coreutils.mo
/usr/bin/md5sum.textutils
/usr/bin/touch
从这里可以看出,Linux系统有八十几个核心命令,即/bin和/usr/bin目录下的那些命令文件。同时,每个命令都有帮助文件在系统中存在了,即那些/usr/share/man目录下的后缀名为gz的文件。
比如在上面的输出中我们看到一个文件/bin/cp,即我们有一个cp命令可以用,哪这个命令是做什么用的呢?我们可以打开/usr/share/man/man1/cp.1.gz文件来看,但不用想怎么打开这个文件,直接输入下列命令就可以了:
man 1 cp
2、man命令的使用
Linux系统有个很大的好处就是有在线帮助,基本上每个东西都有一份文档,这些文档类的东西都保存在/usr/share目录下。
最基本的一个就是man手册。全部在/usr/share/man目录下,这个目录下又分成man1,man2,man3...等一个个目录。即man手册的章,man1目录下是man手册第1章的内容,man2目录下是man手册第2章的内容...
man1 -9这些目录下又有一些以gz结尾的文件,这些文件就是我们的手册了,每个文件就是一个命令的名称、一个软件工具的名称或某个函数的名称。如果用命令 man 1 cp就是打开/usr/share/man/man1/cp.1.gz文档的内容来查看。即man命令的基本用法是man section-number pager
这里section-number是数字1-9表示第几章,而pager就是我们看到的文件名,即某个命令的名称或某个函数的名称等。
当然这里的section-number是可以省略的,省略后man命令会按照某个顺序找到第一个适合的手册来显示。section-number也可以是 -a 表示查看所有章节里的某个名字的内容。
现在就man man试试看。你会看到说明:1 Executable programs or shell commands即第一章是些可执行程序或shell命令
2 System calls (functions provided by the kernel)即内核提供的系统调用
3 Library calls (functions within program libraries)即库函数,这对我们写程序的来说相当有用
4 Special files (usually found in /dev)即设备文件
5 File formats and conventions eg /etc/passwd即文件格式和转换方法等一些说明
6 Games 即游戏
7 Miscellaneous (including macro packages and conven-\r
tions), e.g. man(7), groff(7) 即其它一些工具
8 System administration commands (usually only for root)即系统管理的一些命令
9 Kernel routines [Non standard] 即内核函数
3、命令的归类
上面八十几个命令一个个看下来要花不少时间,按照GNU手册info的说明,这些命令分成下面这些类:
* 输出整个文件内容的命令:: cat tac nl od
* 文件内容格式化的命令:: fmt pr fold
* 输出文件一部分内容的命令:: head tail split csplit
* 统计文件信息的命令:: wc sum cksum md5sum
* 对排序的文件进行操作的命令:: sort uniq comm ptx tsort
* 操作每一行内容的各部分的命令:: cut paste join
* 字符操作的命令:: tr expand unexpand
* 目录内容显示的命令:: ls dir vdir dircolors
* 基本操作的命令:: cp dd install mv rm shred
* 特殊文件类型操作的命令:: ln mkdir rmdir mkfifo mknod
* 改变文件属性的命令:: chgrp chmod chown touch
* 磁盘使用情况分析的的命令:: df du stat sync
* 打印文字内容的命令:: echo printf yes
* 条件命令:: false true test expr
* 重定向命令:: tee
* 文件名操作命令:: dirname basename pathchk
* 当前工作环境相关的命令:: pwd stty printenv tty
* 用户信息相关的命令:: id logname whoami groups users who
* 系统命令相关的命令:: date uname hostname
* 修改命令行为的命令:: chroot env nice nohup su
* 进程控制的命令:: kill
* 延时命令:: sleep
* 数值操作命令:: factor seq
4、自我学习每个命令
如果你安装的是一个比较好的桌面版,比如Ubuntu,按照下面这个顺序点击即可以查看到所有命令的信息。
不管是否有空读完所有的命令的帮助信息。左边“Common options”栏里的几篇短小的文字一定要读完。这是绝大多数Linux命令共有的东西,比如任意一个命令加上--help会查看该命令的帮助信息。
比如命令的长选项格式和短选项格式问题,又比如命令选项结束符的问题。
如果你要操作一个文件,其文件名是“-h”,试试看能删除文件名为“-h”的文件吗?看完这个“Common options”你就知道了。
syzgemini 于 2007-11-12 23:23:43发表:
对于我这个菜鸟来讲,有点糊涂:)
carlote 于 2007-11-12 23:19:10发表:
支持