SHELL的简介
来源:互联网 发布:freebsd mysql 编辑:程序博客网 时间:2024/09/21 06:33
1、什么是shell?
命令解释器也是一种程序设计语言
2、查看当前系统中支持哪些shell?
[root@shell ~]# cat /etc/shells /bin/sh/bin/bash/sbin/nologin/bin/dash/bin/tcsh/bin/csh
3、查看当前shell
[root@shell ~]# echo $SHELL/bin/bash
一般情况下: linux系统默认使用的是/bin/bash unix系统默认使用的是/bin/ksh
4、如何改变shell?
1)临时切换 直接在命令行敲命令
[root@shell ~]# yum install ksh -y[root@shell ~]# ksh //切换的ksh# lsanaconda-ks.cfg Downloads Music TemplatesDesktop install.log Pictures VideosDocuments install.log.syslog Public# exit //退出
2)永久切换 a、root可以直接修改/etc/passwd文件的最后一个字段,重启生效 b、使用命令修改 chsh --- change shell <1>对于root用户,可以修改任何人的shell,并且不需要密码
[root@shell ~]# grep root /etc/passwdroot:x:0:0:root:/root:/bin/bashoperator:x:11:0:operator:/root:/sbin/nologin[root@shell ~]# chsh -s /bin/kshChanging shell for root.Shell changed.[root@shell ~]# grep root /etc/passwdroot:x:0:0:root:/root:/bin/kshoperator:x:11:0:operator:/root:/sbin/nologin[root@shell ~]# useradd uplooking[root@shell ~]# tail -1 /etc/passwduplooking:x:504:504::/home/uplooking:/bin/bash[root@shell ~]# chsh -s /bin/ksh uplookingChanging shell for uplooking.Shell changed.[root@shell ~]# tail -1 /etc/passwduplooking:x:504:504::/home/uplooking:/bin/ksh[root@shell ~]# su - uplooking$ exit
3)对于普通用户,只能修改自己的,并且需要当前密码
[root@shell ~]# echo up | passwd --stdin uplookingChanging password for user uplooking.passwd: all authentication tokens updated successfully.[root@shell ~]# su - uplooking$ chsh -s /bin/bashChanging shell for uplooking.Password: up //需要当前密码Shell changed. $ grep up /etc/passwduplooking:x:504:504::/home/uplooking:/bin/bash
5、什么是环境?
对于计算机或者进程来说,环境就是指你使用的变量、打开的文件、使用的函数、当前路径、资源限制等等
6、用户如何营造自己的环境?
与用户登录相关的文件决定了用户的环境。 1)/etc/profile 2)/etc/bashrc 3)~username/.bashrc 4)~username/.bash_profile 5)/etc/profile.d/*.sh重点:PATH变量 查看PATH变量:
[root@shell ~]# echo $PATH/usr/lib64/qt3.3/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/root/bin
功能:命令的搜索路径,决定了不同用户能够直接执行的命令不同
7、登录shell和非登录shell
登录shell:能够登录系统的 /bin/*sh
[root@shell ~]# ls /bin/*sh/bin/bash /bin/csh /bin/dash /bin/ksh /bin/sh /bin/tcsh
非登录shell:不能够登录系统的 /sbin/nologin
8、完全登录shell和非完全登录shell
完全登录shell:用户拥有自己的环境,也就是读取了所有的环境变量配置文件 1)su - username 2)在登录界面输入账号和密码的登录非完全登录shell:用户没有读取全部的环境变量配置文件,使用了一部分别人的环境 su username
9、shell命令的分类
-- 查看文件类型 [root@shell ~]# file /etc/passwd /etc/passwd: ASCII text-- 查看命令的类型 type 1)内部命令 —— shell自带的 如何查看系统中有多少内部命令? [root@shell ~]# help | wc -l 46 [root@shell ~]# type unalias unalias is a shell builtin 2)外部命令 —— 一般是软件安装的 [root@shell ~]# type whoami whoami is /usr/bin/whoami [root@shell ~]# type hostname hostname is /bin/hostname 3)别名 [root@shell ~]# type ls ls is aliased to `ls --color=auto' 设置别名:alias 取消别名:unalias 4)函数 function(功能、函数) 很少在命令行使用,一般在脚本中使用 [root@shell ~]# hello() { echo douniwan;echo douwowan; } 定义函数: 函数名(参数) { 函数体; } 注意:参数可有可无;函数体为该函数具体功能实现的代码可以有多条 [root@shell ~]# type hello hello is a function hello () { echo douniwan; echo douwowan } [root@shell ~]# hello //调用函数,通过函数名 douniwan douwowan [root@shell ~]# unset hello //取消函数 [root@shell ~]# type hello bash: type: hello: not found 5)shell的关键字 [root@shell ~]# type if if is a shell keyword 6)hash的命令 在内存中的,执行速度快 [root@shell ~]# type ifconfig ifconfig is /sbin/ifconfig [root@shell ~]# ifconfig [root@shell ~]# type ifconfig ifconfig is hashed (/sbin/ifconfig) 查看已经缓存的命令及命中次数 [root@shell ~]# hash 如何清除命令的缓存? 清除某一条的缓存 [root@shell ~]# hash -d chsh [root@shell ~]# hash | grep chsh 清除全部缓存 [root@shell ~]# hash -r [root@shell ~]# hash hash: hash table empty
本节初步对于shell有个介绍,后续将会对shell使用作进一步详细说明。
1 0
- shell的简介
- Shell的简介
- shell的简介
- SHELL的简介
- shell简介
- shell简介
- shell简介
- shell简介
- shell简介
- Shell简介
- shell简介
- Shell简介
- Shell简介
- Shell 简介
- shell简介
- Shell简介
- shell简介
- Shell简介
- CodeForces
- php获取二维数组value的最小值key为指定非整型值
- 关于linux下alsa的一些知识
- feedly导入OPML文件(批量订阅博客)
- LICEcap方便快捷制作gif图片的工具
- SHELL的简介
- progress.fractionCompleted
- protobuf二:第一个c++示例
- Orcale(一)之:表2
- js判断对象属性,并追加
- js笔记(三)--正则表达式
- robot framework封装自定义关键字方法
- Linux Shell编程笔记
- 初探es6(react铺垫)