设为首页 收藏本站
查看: 1160|回复: 0

[经验分享] linux学习命令总结①

[复制链接]

尚未签到

发表于 2018-5-24 08:47:26 | 显示全部楼层 |阅读模式
  知识梳理,回顾之前所学习的一些命令语法。
  # tty命令:显示当前终端对应终端设备文件
[root@VM_168_102_centos ~]# tty
/dev/pts/0
  如何识别哪种终端:
  /dev/ttyS#:串行终端
  /dev/centsole:物理终端
  /dev/tty#:虚拟终端
  /dev/pts/#:伪终端
  #who命令:查看当前系统上登录的所有用户及其信息

[root@VM_168_102_centos ~]# who
root     pts/0        Aug  3 11:26 (222.36.73.57)
wanghan  pts/1        Aug  3 11:54 (222.36.73.57)
  用who命令也可以查看当前终端对应终端设备文件
  
  # basename命令和dirname命令区别:
  basenmae:取路径基名

[root@VM_168_102_centos ~]# basename /etc/passwd/wanghan/ceshi
ceshi
[root@VM_168_102_centos ~]# basename /etc/passwd/wanghan/
wanghan
[root@VM_168_102_centos ~]# basename /etc/passwd        
passwd
[root@VM_168_102_centos ~]# basename /etc      
etc
  dirname:取路径目录名

[root@VM_168_102_centos ~]# dirname /etc/passwd/wanghan/ceshi
/etc/passwd/wanghan
[root@VM_168_102_centos ~]# dirname /etc/passwd/wanghan/     
/etc/passwd
[root@VM_168_102_centos ~]# dirname /etc/passwd/        
/etc
  #type命令:查看当前命令是哪种类型(内建命令或外部命令)

[root@VM_168_102_centos ~]# type cd
cd is a shell builtin
  builtin:在shell程序中实现的命令即为内建命令

[root@VM_168_102_centos ~]# type cat
cat is /bin/cat
  外部命令:在文件系统上的某位置有一个与命令名称对应的可执行文件
  #hash命令:查看hash查找表中执行过的与命令名称相对应的可执行文件

[root@VM_168_102_centos ~]# hash
hitscommand
2/usr/bin/tty
7/bin/basename
5/usr/bin/tail
3/usr/bin/dirname
2/usr/sbin/useradd
4/usr/bin/who
1/usr/bin/man
1/usr/bin/passwd
1/usr/bin/id
3/bin/ls
9/usr/sbin/usermod
3/bin/su
3/usr/bin/clear
  hash –r 清空表

[root@VM_168_102_centos ~]# hash -r
[root@VM_168_102_centos ~]# hash
hash: hash table empty
  #which命令:which命令的作用是,在PATH变量指定的路径中,搜索某个系统命令的位置,并且返回第一个搜索结果。也就是说,使用which命令,就可以看到某个系统命令是否存在,以及执行的到底是哪一个位置的命令。

[root@VM_168_102_centos ~]# which cat
/bin/cat
[root@VM_168_102_centos ~]# which passwd
/usr/bin/passwd
  注意:

[root@VM_168_102_centos ~]# which cd
/usr/bin/which: no cd in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
[root@VM_168_102_centos ~]# type cd
cd is a shell builtin
  cd是内建命令,所以which通过PATH变量中指定的路径是搜索不到的。
  
  
  #如何获取命令帮助:
  内建命令帮助获取:hlep命令
  首先确定命令类型

[root@VM_168_102_centos ~]# 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:
-Lforce symbolic links to be followed
-Puse the physical directory structure without following symbolic
links
The default is to follow symbolic links, as if `-L' were specified.
Exit Status:
Returns 0 if the directory is changed; non-zero otherwise.
  注意:如果输入外部命令

[root@VM_168_102_centos ~]# help cat
-bash: help: no help topics match `cat'.  Try `help help' or `man -k cat' or `info cat'.
找不到相关帮助,并提示你去man中查找
  外部命令帮助获取:--hlep(使用的是manual)

[root@VM_168_102_centos ~]# cat --help     
Usage: cat [OPTION]... [FILE]...
Concatenate FILE(s), or standard input, to standard output.
-A, --show-all           equivalent to -vET
-b, --number-nonblank    number nonempty output lines
-e                       equivalent to -vE
-E, --show-ends          display $ at end of each line
-n, --number             number all output lines
-s, --squeeze-blank      suppress repeated empty output lines
-t                       equivalent to -vT
-T, --show-tabs          display TAB characters as ^I
-u                       (ignored)
-v, --show-nonprinting   use ^ and M- notation, except for LFD and TAB
--help     display this help and exit
--version  output version information and exit
With no FILE, or when FILE is -, read standard input.
Examples:
cat f - g  Output f's contents, then standard input, then g's contents.
cat        Copy standard input to standard output.
Report cat bugs to bug-coreutils@gnu.org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
Report cat translation bugs to <http://translationproject.org/team/>
For complete documentation, run: info coreutils 'cat invocation'
  注意:如果输入内部命令

[root@VM_168_102_centos ~]# cd --help
-bash: cd: --: invalid option
cd: usage: cd [-L|-P] [dir]
[root@VM_168_102_centos ~]# type --help
-bash: type: --: invalid option
type: usage: type [-afptP] name [name ...]
  会提示当前输入命令(cd/type)后面跟着的选项(--help)不存在,并提示你当前输入的命令(cd/type)的用法。
  通过man手册获取命令帮助:man命令
  #man 命令
  可以通过 man builtin(man 任意内建命令均可) 查看所有内建命令相关帮助

BASH_BUILTINS(1)                                              BASH_BUILTINS(1)
NAME
bash,  :,  .,  [,  alias,  bg, bind, break, builtin, caller, cd, command, compgen, complete, compopt, continue, declare, dirs, disown,
echo, enable, eval, exec, exit, export, false, fc, fg, getopts, hash, help, history, jobs, kill, let, local,  logout,  mapfile,  popd,
printf, pushd, pwd, read, readonly, return, set, shift, shopt, source, suspend, test, times, trap, true, type, typeset, ulimit, umask,
unalias, unset, wait - bash built-in commands, see bash(1)
  可以结合man手册中检索命令进行具体相关命令查询
  man手册中操作:
  空格键:向尾部翻一屏
  B键:向首部翻一屏
  回车键:向尾部翻一行
  K键:向首部翻一行
  CTRL+D:向尾部翻半屏
  CTRL+U:向首部翻半屏
  /keyword:像尾部搜索当前输入关键词
  ?keyword:像首部搜索当前输入关键词
  搜索出相关关键词后可以通过“n/N”键进行关键词之间上下跳转

DSC0000.png   q键:退出
  如何在命令帮助中查找关键字相关信息:
  #whatis命令:可以通过在命令帮助中搜索出当前输入命令的相关信息(精确查找),告知命令主要用途。

DSC0001.jpg   
  #man –k命令:可以通过在命令帮助中搜索出当前输入命令的相关信息(模糊查找)
  

DSC0002.jpg

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-480488-1-1.html 上篇帖子: Linux之bash的特性 下篇帖子: linux学习命令总结②
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表