vim打开文件,替换文件中的内容
将IP地址114.114.114.114替换为114.114.114.200
\1为一个占位,等价于前面小括号中的内容
:%s/\(114.114.114.\)114/\1200/
:%s#\(114.114.114.\)#\1200#
将.c源文件批量重名为.cpp文件
#!/bin/bash
for file in `find ./ -name "*.c" -exec basename {} \;`
do
echo $file
mv $file $file"pp"
done
date 命令使用
# 显示系统的时间信息
date "+%y-%m-%d %T"
# 查看文件的最后一次的访问时间
date -r /etc/fstab
# 设置系统时间(需要root权限)
sudo date -s "2020-10-15 11:11:11"
给文件添加注释
:3,5s/^/#/
使用sed方式添加注释
sed -ri '1,5s/.*/#&/' passwd
sed -ri '1,5s/^/#/' passwd
sed 的基本操作
sed -r 'd' passwd # 删除所有行
sed -r '3d' passwd # 删除第3行
sed -r '1,3d' passwd # 删除1-3行
sed -r '/root/d' passwd #删除含有 root的行
sed -r '/root/,5d' passwd #删除包括 root的5行
sed -r '/root/,+5d' passwd #删除 root行以及后面的5行
sed -r 's/root/linuxccc/g' passwd # 替换
sed -r '/^syn/,3d' passwd # 以某一个特定单词开头的替换
sed -r '1~2d' passwd # 删除奇数行
sed -r '0~2d' passwd # 删除偶数行
sed -r '/root/!d/ passwd # 删除没有root的行,取反操作
type 命令
type命令用来显示指定命令的类型,判断给出的指令是内部指令还是外部指令。
alias:别名。
keyword:关键字,Shell保留字。
function:函数,Shell函数。
builtin:内建命令,Shell内建命令。
file:文件,磁盘文件,外部命令。
unfound:没有找到。
colrm 按列删除
colrm命令用于删除文件中的指定列。
起始列号:指定要删除的指定列;
结尾列号:指定要删除的结尾列。
csplit命令 文件过滤分割与合并
csplit命令用于将一个大文件分割成小的碎片,并且将分割后的每个碎片保存成一个文件。碎片文件的命名类似“xx00”,“xx01”。
tr 单个字符替换命令
实现将小写字母替换为大写字母
单个字符的一一替换
按照一行打印环境变量
paste 将多个文件按照列队列进行合并
cpio 文件备份和恢复
sudo find /bin -print | cpio -o > bin.bak
file bin.bak
compress 压缩和解压缩
sudo apt install ncompress -y
compress a b bin.bak
uncompress a.Z b.Z bin.bak.Z
zip 压缩与解压缩
zip demo.zip a bin.bak
unzip demo.zip
cp命令实现创建硬链接和符号链接
cp -l a h_a
cp -s a s_a
-l 创建硬链接
-s 创建符号链接
hostid - print the numeric identifier for the current host
dircolors
dircolors -b
echo $LS_COLORS
ps aux | grep gpm
whatis - display one-line manual page descriptions
whatis ls
whatis open
whatis fork
finger — user information lookup program
sudo apt install finger -y
finger root
finger ubuntu
halt
-p, --poweroff
Power-off the machine, regardless of which one of the three commands is invoked.
关机
halt -p