linun基本命令

介绍

巍哥的学习笔记

cat /etc/os-release
less命令
搜索:/bin
n:向下跳转
N:向上跳转
q:退出
查看主机名:hostname
临时修改主机名:hostname xxxxx
设置永久主机名:hostnamectl set-hostname 1_6
列出CPU信息:lscpu , cat /proc/cpuinfo
查看内存信息:cat /proc/meminfo
文件查看:
head -14 /etc/passwd
tail -14 /etc/passwd

grep 文本文件过滤内容
grep root /etc/passwd
关机命令:poweroff
绿色是程序的颜色
浅蓝色 表示快捷方式

命令的默认解释器 /bin/bash
cat -n /etc/passwd输出内容编号
ctrl + l 清屏
Esc + .或者 Alt+. 粘贴上一个命令的参数
ctrl+u 从光标处清空至行首
ctrl+w 往回删除一个单词

挂载 mount
ls /dev/sr0
/dev/sr0是光驱的设备名,/dev/cdrom代表光驱
/dev/sr0 =/dev/cdrom
mount /dev/cdrom/ /mnt
卸载挂载点:
umount /mnt 只卸载挂载点就可以了

cd ~root 特殊用法,去往root的家目录

[root@localhost ~]# cd ~root
[root@localhost ~]# useradd lisi
[root@localhost ~]# useradd dc
[root@localhost ~]# useradd tom
[root@localhost ~]# cd ~lisi
[root@localhost lisi]# pwd
/home/lisi
[root@localhost lisi]# cd ~dc
[root@localhost dc]# pwd
/home/dc
[root@localhost dc]# cd ~tom
[root@localhost tom]# pwd
/home/tom
ls命令
ls -ld 显示目录本身
ls -A 显示隐藏目录
ls -R 递归显示内容

别名定义:alias
alias hn=‘hostname’
删除别名:unalias
复制目录:cp -r /boot /opt
重命名强制覆盖: \cp -r /boot /opt
cp /etc/os-release /opt/op :会自动生成op文件
拷贝到当前目录可用 . 代替 cp /etc/shells .

grep命令
-v 取反匹配
-i 忽略大小写
grep root /etc/passwd
grep -v ROOT /etc/passwd
grep -i ROOT /etc/passwd

通配符
^word 以字符串word开头
word$ 以字符串word结尾
root@localhost opt]# grep ^root /etc/passwd
root​❌0:0:Super User:/root:/bin/bash
[root@localhost opt]# grep bash$ /etc/passwd
root❌0:0:Super User:/root:/bin/bash
lisi​❌1000:1000::/home/lisi:/bin/bash
dc❌1001:1001::/home/dc:/bin/bash
tom​❌1002:1002::/home/tom:/bin/bash

常见的压缩格式,命令工具
.gz------>gzip
.bz------>bzip2
.xz------->xz
tar工具的常用选项
tar 选项 /路径/压缩包名字/源数据

-c 创建归档
-x 释放归档
-f 制定归档文件名 必选项*,必须写在最后,因为顺序原因
-z、-j、-J:调用 .gz .bz2 .xz 格式的工具进行处理
-t 显示归档的文件清单
-C 制定释放路径
`

归档压缩
tar -zcf /root/123/tar.gz
tar -zcf /root/123/aa.tgz
tar -zcf /root/dc.tar.gz /home /etc/passwd
tar -Jcf /root/abc.tar.xz /home/ /etc/passwd
解压缩命令
tar -xf /root/xixi.tar.bz2 -C /asd05/
tar -xf /rooo///sfsfs -C /adaf

echo 123456 > /opt/a.txt
清空文件 > /opt/aaa.txt

统计文档行数
wc -l /var/log/messages

[root@1_6 ~]# wc -l /var/log/messages
19689 /var/log/messages

过滤空行
grep ^$ /etc/default/useradd
grep -v ^$ /etc/default/useradd
grep -v ^# /etc/login.defs |grep ^$ -v > /opt/1.txt

[root@1_6 ~]# grep -v ^# /etc/man_db.conf > /opt/man.txt
[root@1_6 ~]# cat /opt/man.txt
wc -l /opt/man.txt

find 精确查找

-type 文件类型
-name 文档名称
-size + - 文件 大小
-user 用户名
-mtime 修改时间

find /boot/ -type d
find /boot/ -type d | wc -l
find /boot/ -type d | cat -n
find /boot/ -type f

find /boot/ -type d
find /boot/ -type d | wc -l
find /boot/ -type f
find /boot -type d
find /opt/ -type d
find /etc -type l
fing /boot -type d
find /boot -type d
find /boot -type d | wc -l
find /opt -type d |wc -l
find /etc/ -type l |wc -l

find /etc/ -name “passwd” -name 要用“”双引号
find /etc/ -name “passwd”
find /etc/ -name “tab"
find /etc/ -name "
.conf”
find /etc/ -name “tab" | wc -l
find /etc/ -name “.conf” | wc -l
find /etc/ -name "
.conf” | wc -l
find /etc/ -name “*.conf” | cat -n

-size + - 文件大小(k、M、G)严格区分大小写
find /boot/ -size +300k
find /boot/ -size +30M
find /boot/ -size -1M 此命令是bug

find /boot/ -size +300k
find /boot/ -size +300K
find /boot/ -size +300k
find /boot/ -size +30M
find /boot/ -size -1M
find /boot/ -size -1024k
find /boot -size +300k
find /boot -size +10M
find /boot/ -size +1M
find /boot/ -size -2M

-user 用户名 按照数据的所有者查找

find /home -user lisi
useradd natasha
find / -user natasha

-mtime 修改时间
-mtime +90 #90天之前的数据
-mtime -90 #90天之后的数据

find /root/ -mtime +90
find /root/ -mtime -10 #查找最近10天修改过的文件

find 的高级使用

find {范围} 【条件】 -exec 处理命令 {}\ ; #用来专门处理所查找到的内容
find /boot -size +10M -exec ls -lh {} ; #这个大括号代表了前面find查询的结果 # \代表exec操作的结束
find /boot -size +10M -exec cp {} /1234 ;
find /root -name “xixi*” -exec rm -rf {} ;
find /boot/ -size +10M -exec tar -zcf /mnt/abc.tar.gz {} ;

vim
光标跳转
Home键 跳转到行首
End键 跳转到行尾
gg 跳转到行首
G 跳转到行尾
18G 跳转到指定行

复制粘贴删除
复制 yy 3yy 5yy

粘贴 命令
p 命令用于在当前行的下方粘贴已复制或删除的文本,
P 命令则用于在当前行的上方粘贴相同的文本。

删除
x或delete 删除光标的单个字符
dd 3dd 删除一行或多行
d^ 从光标处删除至行首
d$或大写D 从光标处删除至行尾
编辑撤销: u

查找、撤销、保存
文本查找:/bin
n、N 跳至后、前一个结果
编辑撤销: u
取消撤销:ctrl + r
保存并退出:ZZ

文件操作:
:w 保存当前文件
:q!强制退出
保存后退出::wq 或 :x
X:设置文档密码
:w /root/newfile 另存为其他文件
:r /etc/filesystems 读取其他文件内容
字符串替换:
行内替换: 指的是光标所在的这一行
:\s/old/new :s 代表替换指令 /老的字符/替换成新的字符
:s/aa/1234 只能替换当前的这一个字符
:s/aa/aaaa/g g 表示此行内 匹配到 aa的 全部替换为 aaaa
%/:s/aa/aaaa/g 表示全文 匹配到aa的 替换为aaaa
:1,8/s/aa/aaaa/g 表示1到8行 匹配到aa的 替换为aaaa

开关参数的控制:
:set nu 显示行号
:set no nu 取消行号
:set ai 自动缩进 以上一行的格式为基准
:set noai 关闭自动缩进

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值