码迷,mamicode.com
首页 > 系统相关 > 详细

Linux 相关小技巧

时间:2018-08-02 02:11:28      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:清除   algo   加密算法   text   附加   技术分享   session   9.png   dirname   

修改提示行

进入目录 技术分享图片

创建 yanse.sh nano yanse.sh技术分享图片

修改颜色命令:

PS1="[\e[1;36m][\u@\h \W ]\$[\e[0m]"

技术分享图片

保存 退出

exit

效果:

技术分享图片

------------------------------------------------------------

修改登录前提示 /etc/issue

cat /etc/issue 查看修改登录前提示 /etc/issue技术分享图片

寻找帮助

技术分享图片

技术分享图片

根据自己需要进行修改

技术分享图片

效果:

技术分享图片

技术分享图片

------------------------------------------------------------

修改motd 登录提示信息

删除系统motd文件

rm -f /etc/motd

技术分享图片

进入 /etc 目录

rz命令 从windows系统传入文件

技术分享图片

上传成功

exit

效果图:

技术分享图片

------------------------------------------------------------

CentOS7中 ls /misc/cd 不能挂载的解决方法

查看设置

systemctl status autofs

运行开启服务

systemctl start autofs

设置开机自启动

systemctl enable autofs

效果图:技术分享图片技术分享图片技术分享图片技术分享图片

------------------------------------------------------------

查看目录颜色 cat /etc/DIR_COLORS

技术分享图片技术分享图片

------------------------------------------------------------

实现录屏功能 script -t 2> time.log -a cmd.session

输入命令 录屏开始

技术分享图片

简单输入几个命令作为测试

结束 exit

回看记录: cat cmd.session scriptreply time.log cmd.session

技术分享图片

scriptreply time.log cmd.session技术分享图片

------------------------------------------------------------

挂载U盘 echo ‘- - -‘ > /sys/class/scsi_host/host2/scan

echo ‘- - -‘ > /sys/class/scsi_host/host2/scan

技术分享图片

------------------------------------------------------------

删除历史记录

找到 .bash_history文件

技术分享图片

清除内存中的历史 (注意顺序)

rm .bash_history

history -c

------------------------------------------------------------

screen 实现同屏

centos7 需要安装screen包

技术分享图片

创建screen

技术分享图片

查看screen screen -ls

技术分享图片

连接

技术分享图片

效果

技术分享图片

剥离 ctrl+A D

技术分享图片

重连 screen -r help

------------------------------------------------------------

mail 发送邮件

发邮件

技术分享图片

收邮件

技术分享图片

------------------------------------------------------------

误删除用户后恢复的方法

创建用户useradd test1

技术分享图片

删除用户rm -rf /home/test1

技术分享图片

mkdir /home/test1

技术分享图片

cp -r /etc/skel/. /home/test1

技术分享图片

如图

------------------------------------------------------------

更改账户加密算法

cat /etc/login.defs

技术分享图片

技术分享图片

authconfig --passalgo=sha256 --update

技术分享图片

查看shadow

技术分享图片

shadow里 root账户变为$5

技术分享图片

------------------------------------------------------------

附加组相关文件位置 以及添加组成员、删除组成员

/etc/group:附加组及其属性信息 组名 口令 组ID 组成员

技术分享图片

技术分享图片

/etc/gshadow:附加组组密码及其相关属性 组名 组口令 组成员

技术分享图片

技术分享图片

以上两个文件必须同步 可以查看一下man帮助说明

man gshadow

技术分享图片

一般不用手工改 用命令去改

添加用户到组中 usermod -G test root

技术分享图片

从test组中删除用户 groupmems -g test -d root技术分享图片

------------------------------------------------------------

获取IP

方法1 ifconfig ens33|head -n2 | tail -n1| tr -s " "|cut -d" " -f3

技术分享图片

方法2 ifconfig ens33|grep -o ‘[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}‘|head -n1

技术分享图片

方法3 ifconfig ens33|grep -w "inet" |grep -o "[0-9.]{7,15}" |head -n1

技术分享图片

方法4 ifconfig ens33|grep -o "inet [0-9.]+"|cut -d " " -f2

方法5 ifconfig eth0|grep -w inet |grep -o ‘([0-9]{1,3}.){3}[0-9]{1,3}‘|head -n1

方法6 ifconfig eth0|grep -w inet |grep -Eo ‘([0-9]{1,3}.){3}[0-9]{1,3}‘|head -n1

技术分享图片

方法7 ifconfig ens33|head -n2|tail -n1|tr -s " " |cut -d" " -f3

------------------------------------------------------------

取随机数10位

tr -dc ‘[:alnum:]‘ < /dev/urandom | head -c10技术分享图片

统计rpm 包数量

ls /misc/cd/Packages/|grep -o "[^.]+.rpm$"|cut -d. -f1|sort |uniq -c

ls /misc/cd/Packages/*.rpm |rev|cut -d. -f2|rev|sort |uniq -c

------------------------------------------------------------

grep 取 basename dirname

echo /etc/rc.d/init.d/functions|egrep -o ‘[^/]+/?$‘

echo /etc/rc.d/init.d/functions|egrep -o "^.*/"

------------------------------------------------------------

磁盘使用率

df |grep "^/dev/sd"|tr -s " " % |cut -d% -f5|sort -nr

df|grep "/dev/sd" |grep -Eo "[0-9]{1,3}%"|grep -Eo "[0-9]{1,3}" |sort -nr

Linux 相关小技巧

标签:清除   algo   加密算法   text   附加   技术分享   session   9.png   dirname   

原文地址:http://blog.51cto.com/13854765/2153393

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!