linux全方位掌握一个命令–思路比方法更重要

Linux命令众多,当不清楚一个命令的使用方法时,我们该怎样了解命令的属性和帮助?

1.  用type命令了解一个命令的属性

[root@zejin240 testdir]# type cd
cd is a shell builtin
[root@zejin240 testdir]# type rm
rm is aliased to `rm -i'
[root@zejin240 testdir]# type mysql
mysql is /opt/lamp/mysql/bin/mysql
cd属于linux的内置命令,可以用man type查看所有的内置命令,rm是我们设置的一个别名,mysql是一个外部命令

2. 用which命令查看命令的全路径在哪

[root@zejin240 testdir]# which mkdir
/bin/mkdir
[root@zejin240 testdir]# which mysql
/opt/lamp/mysql/bin/mysql
[root@zejin240 testdir]# which cp
alias cp='cp -i'
/bin/cp

3. 用whatis命令来查看命令的简要信息

[root@zejin240 testdir]# whatis rm
rm (1p) – remove directory entries
rm (1) – remove files or directories
[root@zejin240 testdir]# whatis passwd
passwd (1) – update user's authentication tokens
passwd (5) – password file
passwd [sslpasswd] (1ssl) – compute password hashes

4. 对于内置命令,我们可以用help command来获取命令帮助信息

[root@zejin240 testdir]# help exit
exit: exit [n]
Exit the shell.

Exits the shell with a status of N. If N is omitted, the exit status
is that of the last command executed.

内置命令有哪些,再强调一次,用man type命令可以查看得到

5. 对于非内置命令,一般可以用command –help来获取帮助信息

[root@zejin240 testdir]# mysql –help
mysql Ver 14.14 Distrib 5.7.12, for linux-glibc2.5 (x86_64) using EditLine wrapper
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
……
-e, –execute=name Execute command and quit. (Disables –force and history
file.)
-E, –vertical Print the output of a query (rows) vertically.
-f, –force Continue even if we get an SQL error.
……

6. 对于非内置命令,也可以用man command命令查看

[root@zejin240 tmp]# man pwd
   

linux全方位掌握一个命令--思路比方法更重要

在弹出的页面中,左上角为其章节,man总共有8个章节,还记得上面提到的whatis命令么,命令显示出来的括号里面的1、1p、5是man和页面中的章节对应的。
那么man命令里面的8个章节都有特定的描述规定,它们分别是
第一章节:描述用户命令的使用方法
第二章节:描述系统调用的使用方法
第三章节:描述C的库函数使用方法
第四章节:描述设备及特殊文件
第五章节:描述配置文件的格式及约定
第六章节:描述游戏信息
第七章节:描述其它杂项
第八章节:描述系统管理工具及后台进程

这八个章节的描述可以用man man查看得到。

如果用man command进去的话会显示第一个它搜索到的章节,那像上面提到的passwd命令,我们知道它有第五章节,那怎么进去呢?
用:man 5 passwd即可,类似的还有man 1p rm
我们知道passwd命令对应的是/etc/passwd,所以它对应的就是此文件的介绍,每个字段对应的是什么含义,如下,可以打开/etc/passwd文件和下面的描述对应看看
   

linux全方位掌握一个命令--思路比方法更重要

类似的,man 5 shadow,描述的是/etc/shadow文件的格式介绍。

7. 用info command查看

  主要是一些命令的历史介绍,平时很少用到

建议:

  多用help命令及man,英文不懂也要硬着看,甚至比去各种搜索都还强悍,而且这也是最官方,最权威的解读。

原创文章,作者:chenzejin,如若转载,请注明出处:http://www.178linux.com/56226

(0)
chenzejinchenzejin
上一篇 2016-10-30 19:53
下一篇 2016-10-30 20:00

相关推荐

  • M22 wireshark使用方法简介

    wireshark是一款著名的开源抓包软件,它可以抓取网卡的数据包,以供网络管理员分析。 一 安装方法 debain系安装方法: sudo add-apt-repository ppa:wireshark-dev/stable sudo apt update sudo apt install wireshark 启动wireshark: sudo wires…

    2017-03-20
  • 磁盘分区,raid,lvm,脚本编程_第七周练习

    Q1:创建一个10G分区,并格式为ext4文件系统; (1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl; [root@promote ~]# fdisk /dev/sdb        &n…

    Linux干货 2016-12-24
  • N22-第十三周作业

    1、建立samba共享,共享目录为/data,要求:(描述完整的过程)  1)共享名为shared,工作组为magedu;  2)添加组develop,添加用户gentoo,centos和ubuntu,其中gentoo和centos以develop为附加组,ubuntu不属于develop组;密码均为用户名;  3)添加samb…

    Linux干货 2016-11-14
  • gzip压缩输出

    一、gzip介绍          gzip是GNU zip的缩写,它是一个GNU自由软件的文件压缩程序,也经常用来表示gzip这种文件格式。软件的作者是Jean-loup Gailly和Mark Adler。1992年10月31日第一次公开发布,版本号是0.1,目前的稳定版本是…

    Linux干货 2015-07-29
  • 8.3-ACL权限详解(命令篇)

    前言         我们都知道Linux有三种身份(owner,group,other)搭配三种权限(r,w,x)以及三种特殊权限(SUID,SGID,SBIT), 但是某些时候这些组合不能满足复杂的权限需求。 例如      …

    Linux干货 2016-08-04
  • Linux系统基础(二)

    一、Linux文件管理命令及其常用方法 1、cd(切换目录)这个命令应该是Linux中用的最频繁的一个命令之一了,因为我们经常需要进行目录的切换。在详解这个命令之前,首先得补充一个重要的知识,就是我们常用的一些比较特殊的目录: .        代表当前目录 .. &n…

    Linux干货 2016-09-24

评论列表(1条)

  • 马哥教育
    马哥教育 2016-11-02 16:09

    内容格式把握得很好,不错,希望你能熟知基础命令知识,加油!