命令行编辑方法及Linux的命令帮助

1.命令行编辑方法
问题
1)检查命令echo、cd、cat、hostname的类型
2)利用自动补齐查看文件 /etc/sysconfig/network-scripts/ifcfg-eth0
3)列出以if、fd开头的命令程序
4)利用 \ 强制换行,拆分“命令字 选项 参数”
方案
查看命令类型的命令为type,Tab键的作用能够补全命令、补全路径、判断命令与路径是否有错。命令行的格式一般有三部分,分为“命令字 选项 参数”。在使用“\”强制换行时,需注意的是命令字、选项、参数之间至少要有一个空格。
步骤
实现此案例需要按照如下步骤进行。
步骤一:打开gnome-terminal窗口程序
只需右击桌面(或资源管理器)空白处,选择“打开终端”,如图-1所示。
命令行编辑方法及Linux的命令帮助
图-1
步骤二:检查命令echo、cd、cat、hostname的类型
利用type命令可以查询命令的类型,命令操作如下所示:
[[email protected] ~]# type echo
echo is a shell builtin //builtin表示内部命令
[[email protected] ~]# type cd
cd is a shell builtin
[[email protected] ~]# type cat
cat is /bin/cat //出现路径表示该命令为外部命令
[[email protected] ~]# type hostname
hostname is /bin/hostname
[[email protected] ~]#
步骤三:利用自动补齐查看文件 /etc/sysconfig/network-scripts/ifcfg-eth0
按Tab键不仅可以补全命令,也可以补全路径。要学好Linux必须学会使用Tab键所有要勤加练习。命令操作如下所示:
[[email protected] ~]# ls /et //输入路径到此处按Tab键
[[email protected] ~]# ls /etc/sysco //输入路径到此处按Tab键
[[email protected] ~]# ls /etc/sysconfig/netw //输入路径到此处按Tab键
[[email protected] ~]# ls /etc/sysconfig/network- //输入路径到此处按Tab键
[[email protected] ~]# ls /etc/sysconfig/network-scripts/ifc
//输入路径到此处按Tab键
[[email protected] ~]# ls /etc/sysconfig/network-scripts/ifcfg-e
//输入路径到此处按Tab键
[[email protected] ~]# ls /etc/sysconfig/network-scripts/ifcfg-eth0 //实现补全
步骤四:列出以if、fd开头的命令程序
Tab键特可以让我们变得更加轻松,记忆较长命令时可以只记住前半部分,可以利用Tab键显示出来。命令操作如下所示:
[[email protected] ~]# if //输入if都连续按两下Tab键
if ifcfg ifconfig ifdown ifenslave ifrename ifup
[[email protected] ~]# fd //输入fd都连续按两下Tab键
fdformat fdisk
步骤五:利用 \ 强制换行,拆分“命令字 选项 参数”
命令操作如下所示:
[[email protected] ~]# shutdown \ //输入“\”换行

-k \ //输入“\”换行
now

Broadcast message from [email protected]
(/dev/pts/0) at 19:05 …

The system is going down for halt NOW!
[[email protected] ~]#
2.Linux的命令帮助
问题
1)help查看内部命令的帮助(cd、pwd)
2)查看各种man手册页的存放路径
3)查阅以下命令的man手册页:uname、ifconfig、cat、shutdown
4)用man查看文件/etc/passwd的帮助信息
方案
当利用help命令,查看命令的帮助信息时候。注意两种格式:
help 内部命令
外部命令 --help
man命令可以查看命令的帮助信息,而且帮助信息的类型有很多种,也可以说man帮助手册有很多的入口:1 用户指令、2 系统、3 程序库、4 设备、5 文件系统、6 游戏、7 杂项、8 系统指令、9 内核指令。
其中1、5、8常用需要重点记忆。
步骤
实现此案例需要按照如下步骤进行。
步骤一:help查看内部命令的帮助(cd、pwd)
命令操作如下所示:
[[email protected] ~]# help cd
cd: cd [-L|-P] [dir]
Change the shell working directory.

Change the current directory to DIR.  The default DIR is the value of the
HOME shell variable.

The variable CDPATH defines the search path for the directory containing
DIR.  Alternative directory names in CDPATH are separated by a colon (:).
A null directory name is the same as the current directory.  If DIR begins
with a slash (/), then CDPATH is not used.

If the directory is not found, and the shell option `cdable_vars' is set,
the word is assumed to be  a variable name.  If that variable has a value,
its value is used for DIR.

Options:
    -L	force symbolic links to be followed
    -P	use the physical directory structure w

……
步骤二:查看各种man手册页的存放路径
其实man命令显示的帮助信息,其原理是把事先写好的帮助文档显示出来而已。那么这些帮助文档在哪里呢?,可以通过命令manpath来查看,命令操作如下所示:
[[email protected] ~]# manpath //有多个路径,冒号为分隔符
/usr/local/share/man:/usr/share/man/zh_CN:/usr/share/man/overrides:/usr/share/man
步骤三:用man命令查看一下命令(uname、ifconfig、cat、shutdown)
man命令显示结果一般较多,我们简单了解即可。重点是man命令的使用。命令操作如下所示:
[[email protected] ~]# man uname //按q键退出
……
[[email protected] ~]# man ifconfig
……

[[email protected] ~]# man cat
……

[[email protected] ~]# man shutdown
……

步骤四:用man查看文件/etc/passwd帮助信息
需要大家记住的几个man入口:1(用户指令)、5(文件系统)、8(系统指令)。而/etc/passwd为文件,属于文件系统5的范畴,所以命令操作如下所示:
[[email protected] ~]# man 5 /etc/passwd
……