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



在彈出的頁面中,左上角為其章節(jié),man總共有8個章節(jié),還記得上面提到的whatis命令么,命令顯示出來的括號里面的1、1p、5是man和頁面中的章節(jié)對應的。
那么man命令里面的8個章節(jié)都有特定的描述規(guī)定,它們分別是
第一章節(jié):描述用戶命令的使用方法
第二章節(jié):描述系統(tǒng)調用的使用方法
第三章節(jié):描述C的庫函數(shù)使用方法
第四章節(jié):描述設備及特殊文件
第五章節(jié):描述配置文件的格式及約定
第六章節(jié):描述游戲信息
第七章節(jié):描述其它雜項
第八章節(jié):描述系統(tǒng)管理工具及后臺進程

這八個章節(jié)的描述可以用man man查看得到。

如果用man command進去的話會顯示第一個它搜索到的章節(jié),那像上面提到的passwd命令,我們知道它有第五章節(jié),那怎么進去呢?
用:man 5 passwd即可,類似的還有man 1p rm
我們知道passwd命令對應的是/etc/passwd,所以它對應的就是此文件的介紹,每個字段對應的是什么含義,如下,可以打開/etc/passwd文件和下面的描述對應看看



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

7. 用info command查看

主要是一些命令的歷史介紹,平時很少用到

建議:

多用help命令及man,英文不懂也要硬著看,甚至比去各種搜索都還強悍,而且這也是最官方,最權威的解讀。

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容