环境:redhat7
Linux是真正的多用户多任务。
一、登录的用户:
1 root: 超级用户 最高权限 不要随意使用 工作中 sudoers
[root@server0 Desktop]# #当前在root用户下
2 普通用户:
[root@server0 Desktop]# su - student # su - 切换用户 #root用户切其他用户无需密码
3 切换图形和命令行:
[root@server0 Desktop]# systemctl isolate multi-user.target # 将当前的切换到命令行模式
[root@server0 Desktop]# systemctl isolate graphical.target #将当前的切换到图形化
Linux命令格式:
命令 选项(可选) 参数(可选)
[root@server0 Desktop]# rpm -qa # 短选项 - 单个字母 rpm -q -a 长选项:
[root@server0 tmp]# useradd --uid 2001 zhangsan # 长选项 --单词 --uid # useradd -u 2001 zhangsan
命令 选项(可选) 参数(可选)
[root@server0 Desktop]# cd /tmp # cd :change directory 改变当前目录
[root@server0 tmp]# ls # ls : list:列出当前目录中文件 #默认参数: 当前目录
ssh-CZbvYqz65m5V systemd-private-SKbAa5
systemd-private-9WZVqX yum_save_tx.2019-06-15.09-36._KhzO6.yumtx
systemd-private-Norukl
特殊格式:
[root@server0 tmp]# date +%T
10:19:52
[root@server0 tmp]# date +%D
06/15/19
[root@server0 tmp]# date +%y
19
[root@server0 tmp]# date +%Y
2019
[root@server0 tmp]#
交互命令:
[root@server0 tmp]# passwd student
Changing password for user student.
New password:
[root@server0 tmp]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): ^C
[root@server0 tmp]#
二、命令历史记录:history 默认 保存 1000条历史记录
[root@server0 tmp]# history
1 cd /etc/sysconfig/network-scripts/
2 ifconfig
3 vim ifcfg-eth0
4 init 6
5 ifconfig
6 ping content.example.com
7 lsblk
8 init 0
查看目前history可以保存历史记录的个数:
[root@server0 tmp]# set |grep HIST
HISTFILE=/root/.bash_history
HISTFILESIZE=500
HISTSIZE=500 # 当前记录 500
修改环境HISTSIZE的值,修改保存记录的条数:
[root@server0 Desktop]# cd
[root@server0 ~]# cat .bashrc
\# .bashrc
\# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
\# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
HISTSIZE=1000#在这里修改想要保存历史记录个数
[root@server0 ~]#
历史记录保存的文件:
[root@server0 Desktop]# cd
[root@server0 ~]# cd
[root@server0 ~]# ls -al
total 64
dr-xr-x---. 14 root root 4096 Jun 15 10:02 .
drwxr-xr-x. 17 root root 4096 Jun 15 2019 ..
-rw-------. 1 root root 8619 May 7 2014 anaconda-ks.cfg
-rw-------. 1 root root 515 Jun 15 10:25 .bash_history # 历史记录保存在文件中
-rw-r--r--. 1 root root 18 Dec 29 2013 .bash_logout
-rw-r--r--. 1 root root 176 Dec 29 2013 .bash_profile
-rw-r--r--. 1 root root 176 Dec 29 2013 .bashrc
drwx------. 10 root root 4096 Jun 15 09:35 .cache
drwxr-xr-x. 15 root root 4096 Jun 15 09:36 .config
-rw-r--r--. 1 root root 100 Dec 29 2013 .cshrc
drwxr-xr-x. 2 root root 6 Dec 30 2014 Desktop
drwxr-xr-x. 2 root root 6 Dec 30 2014 Documents
drwxr-xr-x. 2 root root 6 Dec 30 2014 Downloads
命令行正常exit退出才会保存 历史记录:
[root@server0 ~]# exit
清楚当前的历史记录:
[root@server0 ~]# history -c
[root@server0 ~]# exit
通过 !编号 运行命令,其会从历史记录中找出对应编号的命令,然后执行
[root@server0 ~]# history
1 history
2 ifconfig
3 history
[root@server0 ~]# !2
ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.25.0.11 netmask 255.255.255.0 broadcast 172.25.0.255
inet6 fe80::5054:ff:fe00:b prefixlen 64 scopeid 0x2
三、命令行的快捷键:
ctrl +a ,ctrl +e
ctrl + r : 搜索之前命令