liunx入门

Xshell的使用

先打开虚拟机----->打开Xshell创立连接(ssh +ip地址----->回车 输入用户名密码)
普通用户创建:
[[email protected] ~]# useradd test
[[email protected] ~]# passwd test
默认root:#
默认普通用户:$

[[email protected] ~]$
anliu:当前登录的用户。
backup:主机名

~ 的位置表示当前目录
~:用户的家目录

root用户的家目录是/root
普通用户anliu的家目录在 /home/anliu

[[email protected] ~]# pwd 查看当前目录
[[email protected] ~]$ echo $PS1 #输出变量PS1的值
[\[email protected]\h \W]$

[[email protected] ~]$ PS1="[\[email protected]\h]*" #修改变量 (临时,只对当前终端生效)

如何永久生效:将PS1="[\[email protected]\h \d \t \W]$"写入到家目录(~)下的.bashrc文件中。

环境变量文件加载顺序:
PS1 ==>/etc/bashrc
$PATH ==>/etc/profile
/etc/profile → /etc/profile.d/*.sh → ~/.bash_profile → ~/.bashrc → [/etc/bashrc]
/home/anliu/.bashrc
/root/.bashrc
PS1=123 .sh: PS1=456 PS1=789 PS1=101

[[email protected] ~]$ PS1="";

Linux系统上,以.开通的文件是隐藏文件,查看隐藏文件:ls -a
[[email protected] ~]$ ls -a
用root登录:
[[email protected] ~]# yum install vim #安装vim软件:文本编辑器,vi—> vim
[[email protected] ~]$ vim .bashrc
i
PS1="[\[email protected]\h \d \t \W]$"
ESC
:
wq
[[email protected] ~]$ source .bashrc

bash的个性化设置:

3.颜色设置
PS1中常用的颜色格式为:[\e[F;Bm],其中“F“为字体颜色,编号为30-37,“B”为背景颜色,编号为40-47
颜色如下:
0 重新设置属性到缺省设置
1 设置粗体
2 设置一半亮度(模拟彩色显示器的颜色)
4 设置下划线(模拟彩色显示器的颜色)
5 设置闪烁
7 设置反向图象
22 设置一般密度
24 关闭下划线
25 关闭闪烁
27 关闭反向图象
30 设置黑色前景
31 设置红色前景
32 设置绿色前景
33 设置黄色前景
34 设置蓝色前景
35 设置紫色前景
36 设置青色前景
37 设置白色前景
38 在缺省的前景颜色上设置下划线
39 在缺省的前景颜色上关闭下划线
40 设置黑色背景
41 设置红色背景
42 设置绿色背景
43 设置黄色背景
44 设置蓝色背景
45 设置紫色背景
46 设置青色背景
47 设置白色背景
49 设置缺省黑色背景

下面为了区分root用户和普通用户,我在/etc/bashrc下设置
if [ $USER == “root” ]; then
export PS1=’[[\e[33;49m]\[email protected]\H \w]$’
else
export PS1=’[[\e[32;49m]\[email protected]\H \w]$’
fi
也可起设置多个颜色
判断root ,显示为红色,普通用户为绿色,并记录path
if [ $USER == “root” ];then
PS1=’[[\e[31m]\u[\e[m]@[\e[33m]\H [\e[m]\w]$’
else
PS1=’[[\e[32m]\u[\e[m]@[\e[33m]\H [\e[m]\w]$’
fi
还可以记录命令条数
if [ $USER == “root” ];then
PS1=’[\e[35m]|#|[\e[m][[\e[31m]\u[\e[m]@[\e[33m]\H [\e[m]\w]$’
else
PS1=’[\e[35m]|#|[\e[m][[\e[32m]\u[\e[m]@[\e[33m]\H [\e[m]\w]$’
fi

操作上述代码结果如下

liunx入门liunx入门
liunx入门
liunx入门
liunx入门
liunx入门
liunx入门
liunx入门
liunx入门