linux运维基础命令参考

设置ip地址为 192.168.8.16
Ifconfig ens33 192.168.8.16
设置DNS地址为 202.106.0.20
Echo “nameserver  202.106.0.20” >> /etc/resolv.conf
设置 网关地址为:192.168.8.2
Route add  default gw 192.168.8.2
进入/etc/sysconfig/network-scripts/(使用tab 键)
Cd /etc/sysconfig/network-scripts
查看 ifcfg-ens33内容
Cat ifcfg-ens33
查看 /etc/resolv.conf 的内容
Cat /etc/resolv.conf
使用ping命令测试 www.baidu.com
Ping www.baidu.com
备份yum配置文件并下载阿里源配置文件

清除源码缓存并创建阿里源的缓存
Yum clean all
Yum makecache
关闭禁用selinux
Seten 0
关闭并禁用防火墙
Systemctl stop firewalld
Systemctl disable firewalld
查看防火墙当前的状态
Systemctl status firewalld
查看sshd服务当前的状态
Systemctl status sshd
设置开机自启
Systemctl enable sshd
同时创建目录 /data、/backup
Mkdir /data   /backup
创建多层目录 /data/dir1/dir2/dir3
Mkdir -p  /data/dir1/dir2/dir3
在/data/dir1/dir2/dir3目录中创建100个文件分别为 file1-file100
Touch /data/dir1/dir2/dir3/file{1..100}
切换目录回到宿主目录
cd
同时创建目录 test001 – test100
Mkdir test{1..100}
快速回到上一次访问的目录 /data/dir1/dir2/dir3
Cd -
通过yum查询tree命令的包名并安装tree
Yum install tree
使用tree命令查看 /data目录的树形结构
Tree /data
删除空目录/root/test100
Rm -rf /root/test100
查看 /root/test01目录的权限
Ls -ld /root/test01
创建空文件 /root/test01/file1
Touch /root/test01/file1
使用echo 追加写入“hello linux ”
Echo    ”hello linux” >> /test01/file1
使用cat 命令结合>> << 编辑如下内容并以EOF结束
内容如下:
123
456
789
Cat >> /test01/file1 <<  EOF
123
456
789
EOF
拷贝 /etc/passwd  到/opt/ 改名为password
Cp -rp  /etc/passwd  /opt/password
使用分页显示/opt/password 的内容
More /opt/password
查看/opt/password文件的前5行
Head  /opt/password
查看 /var/log/message文件的后 4行
Tail  -4  /var/log/message
拷贝目录/data目录到 /backup目录中并保持原有权限
Cp -rp  /data  /backup
移动/data/backup/dir1/dir2/dir3 到/opt/ 改名为 dir11
Mv /data/backup/dir1/dir2/dir3  /opt/dir11
使用vi 创建文件 /opt/pass1
Vim  /opt/pass1
从/opt/password文件中读取内容
:r /opt/password
一下使用组合键完成:
查找systemd 关键词 跳转到第2个位置 将其改名为 initd
/systemd    n   x    initd
查找sync关键词,跳转到第3个位置 将其改名为:test
/sync   n n    x  test
查找mail关键字,跳转到第3个位置,将其改名为:cmd
/mail       n n  x  cmd
保存并退出
wq
查看行号
Set nu
直接定位到最后一行、复制当前行插入到22行下面
G    yy   22G p
直接定位到第一行复制3行并插入到18行下面
1 G  3yy    18G p
直接定位到12行删除5行
12 G    5dd
替换第10-15行中的所有sbin 为SBIN
10,15 s/sbin/SBIN/g
替换全文中所有的nologin 为 bash
%s/nologin/bash/g
替换全文中所有的sbin 为 test
%s/sbin/test/g
使用dd命令创建文件大小为 2G 名字为file.txt
Dd if  /dev/repo  of=file.txt  bs=1000M count=2
压缩file.txt 为file.txt.gz 
Tar zcf file.txt.gz   file.txt
使用两种方法查看file.txt.gz 大小
Ls -lh file.txt.gz
解压file.txt.gz
 Tar  zxf  file.txt.gz  
查看file.txt的大小
Ls -lh file.txt
将file.txt 压缩为file.txt.bz2
Bzip2  file.txt
查看file.txt.bz2大小
Ls -lh file.txt.bz2
归档压缩 /boot 文件夹为 boot-2022-08-03.tar.gz(时间需要通过命令生成)
Tar zcf  boot-$(date +%F).tar.gz
创建文件夹 /backup
Mkdir /backup
归档压缩 /boot /etc 文件夹为 /backup/2022-08-03.tar.bz2 
Tar zcf /backup/$(date +%F).tar.bz2
解压/backup/2022-08-03.tar.bz2
Tar xf  /backup/2022-08-03.tar.bz2  
查看解压目录的权限
Ls -ld
创建别名 c 代表 “clear” 清屏
Alias  c=clear
修改配置文件使别名重启生效
搜索名字以 ifcfg 开头的所有文件
Find  -name  “ifcfg.*”
搜索名字以 .conf 结尾的所有文件
Find  -name  “*.conf”
搜索名字以 net开头的目录
Find  -type  d   -name “*.net”
搜索3天内被访问过的所有文件
Find  -type f -atime 3
查找/目录下,用户可写 and 组可写 and 其他人可写的文件
Find  /  -perm  -222  -type f 
查找/目录下,用户可写 or 组可写 or 其他人可写的文件
Find /   perm /222  -type f
搜索不属于root的文件
Find  /!  -user root -type f
搜索属于daemon用户的文件
Find / -user daemon -type f
查找目录下,文件大小小于200K大小的文件
Find  -type f -  size -200K
查找 .conf 后缀的文件并进行拷贝到 /opt/文件夹下面
Find   -type  f -name “*.conf” -exec cp {} /opt\;
查找/目录下所有的空文件,并删除

Find /  -type f  -size 0 -exec rm -rf {} \;
 

猜你喜欢

转载自blog.csdn.net/weixin_63294004/article/details/130304323