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

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

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

Broadcast message from root@localhost.localdomain
(/dev/pts/0) at 19:05 …

The system is going down for halt NOW!
[root@localhost ~]#
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)
命令操作如下所示:
[root@localhost ~]# 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来查看,命令操作如下所示:
[root@localhost ~]# manpath //有多个路径,冒号为分隔符
/usr/local/share/man:/usr/share/man/zh_CN:/usr/share/man/overrides:/usr/share/man
步骤三:用man命令查看一下命令(uname、ifconfig、cat、shutdown)
man命令显示结果一般较多,我们简单了解即可。重点是man命令的使用。命令操作如下所示:
[root@localhost ~]# man uname //按q键退出
……
[root@localhost ~]# man ifconfig
……

[root@localhost ~]# man cat
……

[root@localhost ~]# man shutdown
……

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

董筱杰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值