awk ‘BEGIN{print "开始"}{print $1}END{print "结束"}’
BEGIN: awk 在读取文件之前执行的动作
{ } 读取文件
END: awk在读取完文件之后执行的动作
# awk 中动作可以和文件内容没关系
[root@db01 ~]# cat 2.txt
root: 0:test
oldboy /bin/bash
[root@db01 ~]# awk '{print "hehe"}' 2.txt #内容有几行打印结果就有几行
hehe
hehe
[root@db01 ~]# cat 2.txt
root: 0:test
oldboy /bin/bash
[root@db01 ~]# awk 'BEGIN{print "开始"}{print $1}END{print "结束"}' 2.txt
开始
root:
oldboy
结束
[root@db01 ~]# echo 10 20|awk '{print $1+$2}'
30
面试题:
开机bios自检,检测硬件的问题
主板
CPU
内存
硬盘
电源
在企业中出问题最多的硬件: 硬件服务器 IDC机房 自建机房
1.磁盘 出了怎么办? 磁盘的详细属性
互联网公司: 表现的有经验
1).是否在保质期内 3年
如果保质期3年内,联系售后直接换新的
2).过了保质期,有库存吗 直接采购
问领导: 更换硬盘的流程
3).在质保期内更好流程
a.联系售后
b.联系IDC机房
定时间 身份证
2.内存 (内存不会坏)
a .兼容性问题 关机重启 或者刚开机无法启动服务器
重新插拔内存,擦拭金手指
全部拔下一根根插 插一根启动一下
一根一根往下拔 拔一根启动一下
3.电源 坏了直接换 服务器支持两块电源
4.主板 坏了换
5.CPU 风扇
让一个服务器开机自动运行的方法: centos7.X
方法1.被systemctl所管理的服务 直接可以使用enable
systemctl stop NetworkManager --------# 关闭
systemctl enable NetworkManager -------# 开机自动运行
方法2.不被systemctl所管理的服务 写入/etc/rc.local
方法3.写入/etc/profile 环境变量 不建议
centos6.X 管理服务的是 chkconfig (了解)
[root@db01 ~]# chkconfig network on|off
[root@db01 ~]# /etc/inittab/network start
[root@db01 ~]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
第一列: 用户名称 管理员普通用户和虚拟用户体现的位置
第二列: x 用户的密码
第三列: 0 用户的UID号
第四列: 0 用户的GID号 小组的号码
第五列: root 描述信息 可写可不要
第六列: /root 用户的家目录 管理员/root 普通该用户oldboy家目录--->/home/oldboy/
第七列: 命令解释器
/bin/bash 普通用户包括root,允许登录操作系统
/sbin/nologin 虚拟用户 不允许登录操作系统
1.创建用户(useradd oldboy)
2.系统会将/etc/skel/隐藏的环境变量文件 复制到/home/oldboy/家目录中隐藏文件
3.系统将隐藏文件属主属组修改为普通用户
-bash-4.2#
-bash-4.2#
-bash-4.2#
# 解决方法 复制模版文件到家目录
-bash-4.2# cp /etc/skel/.* .
查看是否复制成功 .bash_profile和.bashrc
-bash-4.2# ll .bash*
-rw------- 1 root root 22021 Mar 20 12:02 .bash_history
-rw-r--r-- 1 root root 18 Mar 20 12:02 .bash_logout
-rw-r--r-- 1 root root 193 Mar 20 12:02 .bash_profile
-rw-r--r-- 1 root root 231 Mar 20 12:02 .bashrc
# 退出重新连接操作系统
exit
如果不退出可以让profile直接运行一次
使用. 或者source
-bash-4.2# . .bash_profile
[root@db01 ~]#
[root@db01 ~]#
[root@db01 /etc/sysconfig/network-scripts]#PS1='[\u \t@\h \w]\$'
[root 11:56:17@db01 /etc/sysconfig/network-scripts]#
[root 11:56:18@db01 /etc/sysconfig/network-scripts]#
[root 11:56:18@db01 /etc/sysconfig/network-scripts]#
[root 11:56:18@db01 /etc/sysconfig/network-scripts]#
[root 11:56:18@db01 /etc/sysconfig/network-scripts]#
[root 11:56:19@db01 /etc/sysconfig/network-scripts]#
永久修改写入/etc/profile
答: 出现以上问题是由于误删除了家目录下的隐藏文件.bash_profile .bashrc
解决方法 复制/etc/skel/目录下的隐藏文件 到家目录
然后重新连接即可
1.useradd 添加用户
语法格式:
useradd [参数选项] 用户名称
参数选项:
-s 指定解释器 /bin/bash /sbin/nologin
-u 指定UID 身份证 如果不指定默认往后排
-g 指定GID 组号
-M 不创建家目录,如果不使用-M 创建家目录
-G 附加组 (了解)
案例1.创建一个普通用户oldboy,默认可以不加任何参数
[root@db01 ~]# useradd oldboy
查看普通用户的信息
[root@db01 ~]# id oldboy
uid=1001(oldboy) gid=1002(oldboy) groups=1002(oldboy)
[root@db01 ~]# grep 'oldboy' /etc/passwd
oldboy:x:1001:1002::/home/oldboy:/bin/bash
案例2.创建一个虚拟用户 oldboy 指定UID 666 不创建家目录 不允许登录
[root@db01 ~]# userdel -r oldboy
[root@db01 ~]#
[root@db01 ~]# useradd -u666 -M -s /sbin/nologin oldboy
[root@db01 ~]# id oldboy
uid=666(oldboy) gid=1002(oldboy) groups=1002(oldboy)
案例3.创建一个虚拟用户 uid888 gid888 不创建家目录 不允许登录系统 test01
[root@db01 ~]# useradd -u888 -g888 -M -s /sbin/nologin test01
useradd: group '888' does not exist
组888 不存在
第一步: 创建组
[root@db01 ~]# groupadd -g888 test01
第二步: 创建组
[root@db01 ~]# useradd -u888 -g888 -M -s /sbin/nologin test01
[root@db01 ~]# id test01
uid=888(test01) gid=888(test01) groups=888(test01)
userdel -r 删除用户相关的所有文件
修改用户密码
方法一:
案例.修改root的密码
[root@db01 ~]# passwd
Changing password for user root.
New password: # 输入新的密码 比如123
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: # 再次输入新的密码 比如 123
passwd: all authentication tokens updated successfully.
案例2.给test03设置一个密码
[root@db01 ~]# passwd test03
Changing password for user test03.
New password: # 密码1
BAD PASSWORD: The password is a palindrome
Retype new password: # 密码1
passwd: all authentication tokens updated successfully.
使用xshell通过test03进行远程连接Linux系统
方法二:免交互配置密码
[root@db01 ~]# echo 1|passwd --stdin test03
Changing password for user test03.
passwd: all authentication tokens updated successfully.
[root@db01 ~]# echo 1|passwd --stdin root
Changing password for user root.
passwd: all authentication tokens updated successfully.
chown 修改文件的属主和属组
[root@db01 tmp]# ll 1.txt
-rw-r--r-- 1 root root 0 Mar 14 10:30 1.txt
[root@db01 tmp]# chown test03.test03 1.txt
[root@db01 tmp]# ll 1.txt
-rw-r--r-- 1 test03 test03 0 Mar 14 10:30 1.txt
递归修改目录及目录以下所有文件的属主属组: (需要加 -R)
[root@db01 ~]# mkdir oldboy
[root@db01 ~]# touch oldboy/{1..3}.txt
[root@db01 ~]# ll
total 0
-rw-r--r-- 1 root root 0 Mar 20 15:22 1.txt
drwxr-xr-x 2 root root 45 Mar 20 15:29 oldboy
[root@db01 ~]# ll oldboy/
total 0
-rw-r--r-- 1 root root 0 Mar 20 15:29 1.txt
-rw-r--r-- 1 root root 0 Mar 20 15:29 2.txt
-rw-r--r-- 1 root root 0 Mar 20 15:29 3.txt
默认只修改目录的属主和属组
[root@db01 ~]# chown test03.test03 oldboy
[root@db01 ~]# ll
total 0
-rw-r--r-- 1 root root 0 Mar 20 15:22 1.txt
drwxr-xr-x 2 test03 test03 45 Mar 20 15:29 oldboy
[root@db01 ~]# ll oldboy/
total 0
-rw-r--r-- 1 root root 0 Mar 20 15:29 1.txt
-rw-r--r-- 1 root root 0 Mar 20 15:29 2.txt
-rw-r--r-- 1 root root 0 Mar 20 15:29 3.txt
[root@db01 ~]# chown -R test03.test03 oldboy #需要加 -R 递归修改
[root@db01 ~]# ll
total 0
-rw-r--r-- 1 root root 0 Mar 20 15:22 1.txt
drwxr-xr-x 2 test03 test03 45 Mar 20 15:29 oldboy
[root@db01 ~]# ll oldboy/
total 0
-rw-r--r-- 1 test03 test03 0 Mar 20 15:29 1.txt
-rw-r--r-- 1 test03 test03 0 Mar 20 15:29 2.txt
-rw-r--r-- 1 test03 test03 0 Mar 20 15:29 3.txt
su - 切换用户
1.root切换到普通用户 不需要密码
2.普通用户切换到root 需要root的密码
3.普通用户切换到普通用户 需要密码
案例1.root用户切换到test03用户
[root@db01 ~]# su - test03
Last login: Wed Mar 20 15:26:30 CST 2024 on pts/1
[test03@db01 ~]$
案例2.普通用户切换到普通用户 test02
[test03@db01 ~]$ su - test02
Password: # 密码1
[test02@db01 ~]$ su - root
Password: # 密码1
[root@db01 ~]#