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
在彈出的頁面中,左上角為其章節,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文件和下面的描述對應看看
類似的,man 5 shadow,描述的是/etc/shadow文件的格式介紹。
7. 用info command查看
主要是一些命令的歷史介紹,平時很少用到
建議:
多用help命令及man,英文不懂也要硬著看,甚至比去各種搜索都還強悍,而且這也是最官方,最權威的解讀。
原創文章,作者:chenzejin,如若轉載,請注明出處:http://www.www58058.com/56226
內容格式把握得很好,不錯,希望你能熟知基礎命令知識,加油!