linux学习笔记

Linux基础命令文件管理

基本命令

ls

cd


•服务器的类型尺寸(Unit)
1u=1.75英寸=44.45毫米=4.445 厘米
2u则是1u的2倍为8.89cm

•典型服务模式:C/S,Client/Server架构
–由服务器提供资源或某种功能
–客户机使用资源或功能

•TCP/IP是最广泛支持的通信协议集合
–包括大量Internet应用中的标准协议
–支持跨网络架构、跨操作系统平台的通信

•主机与主机之间通信的三个要素
–IP地址(IP address)
–子网掩码(subnet mask)
–IP路由(IP router)

•IPv4地址(IP address)
作用:用来标识一个节点的网络地址
地址组成(点分十进制):
–一共32个二进制位
–表示为4个十进制数,以 . 隔开
–二进制的 11111111 = 十进制的 255

人的标识:身份证号
北京朝阳区: 110105 19901001 1000
乌鲁木齐天山区:650102 19910906 5000

北京朝阳区:
110105 19901001 1000=来自北京朝阳区,编号为199010011000的人

网络位与主机位
网络位:身份证前六位,表示区域
主机位:在区域中的编号

•用于一般计算机网络
–A类:1 ~ 127         网+主+主+主
–B类:128 ~ 191       网+网+主+主
–C类:192 ~ 223       网+网+网+主

网络名:网络位不变,主机位全为0
相同网络(区域)通信
192.168.1.1=来自192.168.1.0网络,在区域中编号1的主机
192.168.1.2=来自192.168.1.0网络,在区域中编号2的主机

192.168.3.38----》C类----》三个网络位一个主机位----》网络位不变,主机位全为0---》192.168.3.0

子网掩码:标识IP地址网络位与主机位,二进制1表示网络位,二级制0表示主机位(利用255表示网络位,利用0表示主机位)

192.168.1.1=11000000.10101000.00000001.00000001
子网掩码=111111111.11111111.11111111.00000000

192.168.1.1           192.168.1.1/24
255.255.255.0


测试网络连通:ping
格式:ping   对方IP地址

ipconfig:查看Windows的IP地址

设置IP地址:
1.手动方式    
2.自动获取IP地址(DHCP服务器)

网关地址:解决不同网络之间通信,路由器地址

DNS服务器:将名字解析成对应IP地址
www.qq.com--DNS服务器--腾讯服务器(IP地址)


云计算学院24年新课程全阶段软件:
链接:https://pan.baidu.com/s/1mvtR__vwcE8U-MC4lVQCiA?pwd=1234 

安装VMware软件


Unix 1970-1-1诞生

内核:软件,调配计算机硬件
用户----》内核----》硬件

内核官网:kernel.org

Linux:KVM软件
 
 
 
 
 
 
 


Windows:VMware软件


步骤一:Linux命令行界面字体调节
字体变大:ctrl  shift  +
字体变小:ctrl   -

[root@localhost ~]# pwd         #显示当前所在的位置
[root@localhost ~]# cd    /       #切换到根目录下
[root@localhost /]# pwd  
[root@localhost /]#  ls           #显示当前目录下内容
[root@localhost /]# cd    /boot
[root@localhost boot]# ls     
[root@localhost boot]# cd   /
[root@localhost /]# ls
[root@localhost /]# cd  /home
[root@localhost home]# ls
[root@localhost home]# cd   /root  
[root@localhost ~]# ls       

[root@localhost etc]# ls   /       #查看根目录内容
[root@localhost etc]# ls   /home
[root@localhost etc]# ls   /opt
[root@localhost etc]# ls   /boot
[root@localhost etc]# ls   /var
[root@localhost etc]# ls   /bin
[root@localhost etc]# ls   /proc
[root@localhost etc]# ls   /usr
[root@localhost etc]# ls   /tmp
[root@localhost etc]# ls   /mnt

cat查看文本文件内容,适合查看内容较少文件
[root@localhost /]# ls    /root/                       
[root@localhost /]# ls    /root/anaconda-ks.cfg 
[root@localhost /]# cat     /root/anaconda-ks.cfg
[root@localhost /]# cat    /etc/passwd
[root@localhost /]# cat    /etc/fstab     
[root@localhost /]# cat    /etc/group

[root@localhost /]# cat    /etc/redhat-release  #查看系统版本

less查看文本文件内容,适合查看内容较多文件
[root@localhost /]# less  /etc/passwd
按上、下键进行滚动
按q键进行退出


绝对路径:以根目录开始的完整路径   /usr/games
   地球----》亚洲---》中国---》北京---》海淀区---》学院路---》XXX大厦----》达内----》5教室

相对路径:以当前位置位参照的路径
海淀区---》学院路---》XXX大厦----》达内----》5教室
[root@localhost ~]# cd    /usr/
[root@localhost usr]# ls
[root@localhost usr]# cd    games         #相对路径
[root@localhost games]# pwd

[root@localhost games]# cd   /
[root@localhost /]# cd    /usr/games     #绝对路径
[root@localhost games]# pwd

..  表示上一层目录(父目录)
[root@localhost /]# cd   /etc/pki/rpm-gpg/
[root@localhost rpm-gpg]# pwd
/etc/pki/rpm-gpg
[root@localhost rpm-gpg]# cd   ..
[root@localhost pki]# pwd
/etc/pki
[root@localhost pki]# cd   ..
[root@localhost etc]# pwd
/etc
[root@localhost etc]# cd  ..
[root@localhost /]# pwd
/
[root@localhost /]#


hostname查看主机名与临时设置主机名
[root@localhost /]# hostname
[root@localhost /]# hostname   abc.haha.xixi
[root@localhost /]# hostname

新开一个全新的命令行终端,查看提示符变化
[root@abc ~]# hostname   nb.haha.com

新开一个全新的命令行终端,查看提示符变化
[root@nb ~]# hostname

hostnamectl永久设置主机名
[root@nb ~]# hostnamectl  set-hostname  nb.haha.com
[root@nb ~]# hostname   #查看主机名
nb.haha.com
[root@nb ~]# reboot     #重启系统

哲学理念:一切皆文件
/dev:存放设备(键盘、鼠标、硬盘、光驱…..)相关数据

查看识别的硬盘:lsblk
第三块SCSI接口的硬盘:/dev/sdc

虚拟机接口:vd开头


]# ifconfig   #查看网卡信息
lo: 本机回环接口(此接口专门用于测试)   
   IP永远为127.0.0.1
   127.0.0.1:永远代表本机

]# ifconfig   ens1   192.168.4.1  #临时设置IP
]# ifconfig    ens1

]# ping   192.168.4.1
Ctrl  c:结束正在运行命令

列出CPU处理器信息  
[root@A ~]# lscpu
……
CPU(s):            1     #核心数
……
型号名称:Intel(R) Core(TM) i5-4430 CPU @ 3.00GHz
……

列出内存信息
[root@A ~]# cat   /proc/meminfo
MemTotal:         997956 kB   #一共内存总和
……

mkdir创建目录         
[root@A ~]# mkdir   /opt/test
[root@A ~]# ls   /opt
[root@A ~]# mkdir  /root/nsd01
[root@A ~]# ls  /root

touch创建文本文件
[root@A ~]# touch    /opt/1.txt
[root@A ~]# ls  /opt
[root@A ~]# touch    /opt/2.txt
[root@A ~]# ls  /opt

head、tail 命令(查看部分文件内容)

head -n 数字 文件名
tail -n 数字 文件名

[root@A /]# head   -1    /etc/passwd
[root@A /]# head   -2    /etc/passwd
[root@A /]# head   -3    /etc/passwd

[root@A /]# tail   -1   /etc/passwd
[root@A /]# tail   -2   /etc/passwd
[root@A /]# tail   -3   /etc/passwd

过滤文件内容:输出包含指定字符串的行
[root@A /]# grep  root    /etc/passwd
[root@A /]# grep  bash    /etc/passwd
[root@A /]# grep  lisi    /etc/passwd
[root@A /]# grep  zhangsan   /etc/passwd
[root@A /]# grep  haha   /etc/passwd


vim  文本编辑器(编辑文件内容)
vim有新建文件功能,但是不能新建目录

三模式:命令模式   插入模式(编辑模式)  末行模式

[root@A /]# vim    /opt/haxi.txt   
命--- i键 或者 o键 --->插入模式(Esc回到命令模式)


式--- 英文的冒号:--->末行模式(Esc回到命令模式)
末行模式 :wq      #保存并退出 
末行模式 :q!      #强制不保存并退出

补充:命令模式  u   #可以实现撤销


关机poweroff与重启操作系统reboot
[root@A /]# poweroff

在Linux中执行大多数命令时,都要找到命令所对应的程序
]#  hostname
]#  which  hostname     #查询命令对应的程序
]#  ls  /usr/bin/hostname
]#  which ifconfig     #查询命令对应的程序
]#  firefox
]#  which  firefox   #查询命令对应的程序

命令的执行依赖于解释器  默认解释器/bin/bash

用户----》解释器(shell)----》内核----》计算机硬件

shell:壳

绿色:可以执行的程序

命令完整的格式:
  命令     [选项]       [参数1]    [参数2] ……….

打     武器    凯哥 ………
[root@localhost /]#  cat    --help      #查看命令帮助信息
[root@localhost /]#  cat    -n    /etc/shells   #显示行号
[root@localhost /]#  cat    -n    /etc/passwd
[root@localhost /]#  cat    -n    /etc/redhat-release
[root@localhost /]#  cat    -n    /etc/fstab  
[root@localhost /]#  cat    -n    /etc/shadow
[root@localhost /]#  cat    -n    /etc/hosts
[root@localhost /]#  cat    -n    /etc/group

]#  ls   -l    /etc/passwd    #长格式显示
]#  ls   -l    /etc/fstab      #显示详细属性
]#  ls   -l    /etc/shells
]#  ls   -l    /etc/shadow   #长格式显示
]#  ls   -l    /etc/hosts    #长格式显示
]#  ls   -l    /etc/group    #长格式显示
]#  ls   -l    /etc/gshadow  #长格式显示
]#  ls   -l    /root    #默认显示目录内容的详细属性

Tab键自动补全
可补齐命令字、选项、参数、文件路径、软件名、服务名

[root@localhost /]# if(tab) (tab)     #列出以if开头的命令  
[root@localhost /]# ifco(tab)
[root@localhost /]# cat   /etc/re(tab) (tab)
[root@localhost /]# cat   /etc/red(tab)
[root@localhost /]# ls  /etc/sysconfig/network-scripts/
[root@localhost /]# ls  /et(tab)/sysco(tab)/netw(tab)- (tab)

快捷键
Ctrl + c:结束正在运行的命令
Esc + .或Alt + .:粘贴上一个命令的参数
[root@localhost ~]# ls    /etc/hosts
[root@localhost ~]# ls  -l    Alt + . 
[root@localhost ~]# cat     Alt + . 
[root@localhost ~]# cat   -n    Alt + .
Ctrl + l:清空整个屏幕

Ctrl + u:从光标处清空至行首
Ctrl + k:从光标处清空至行尾
Home键:从光标处快速到行首
end键:从光标处快速到行尾
Ctrl + w:往回删除一个单词(以空格界定)

mount挂载
Linux系统光盘镜像文件中,具备众多的软件包
显示光盘镜像文件的内容

光盘镜像文件----》虚拟机光驱设备----》访问点(目录)

Linux系统必须通过目录作为访问点才可以访问设备内容

1.通过图形操作
 

 
 

2.虚拟机的光驱设备
[root@nb ~]# ls   /dev/sr0
/dev/sr0
[root@nb ~]# ls   /dev/cdrom
/dev/cdrom
[root@nb ~]# ls -l  /dev/cdrom
lrwxrwxrwx. 1 root root 3 4月  29 09:06 /dev/cdrom -> sr0
[root@nb ~]#

3.mount挂载:将目录成为设备的访问点
[root@nb ~]# mkdir   /dvd

[root@nb ~]# mount  /dev/cdrom    /dvd/  
mount: /dvd: WARNING: device write-protected, mounted read-only.
[root@nb ~]# ls   /dvd
AppStream  EFI     isolinux  media.repo
BaseOS     images  LICENSE   TRANS.TBL
[root@nb ~]#

4.卸载操作
[root@localhost /]# umount     /dvd
[root@localhost /]# ls   /dvd/           #显示内容为空

[root@localhost /]# mkdir    /mydvd
[root@localhost /]# mount    /dev/cdrom     /mydvd
mount: /mydvd: WARNING: device write-protected, mounted read-only.
[root@localhost /]# ls    /mydvd

家目录:专门记录用户个性化信息的目录
/root:管理员root的家目录
/home:存放所有普通用户家目录
~:用户家目录
[root@localhost /]# cd  ~root    #去往root用户的家目录
[root@localhost /]# pwd          
[root@localhost /]# useradd  dc   #创建用户dc
[root@localhost /]# cd  ~dc       #去往dc用户的家目录
[root@localhost /]# pwd
[root@localhost /]# useradd  tom   #创建用户tom
[root@localhost /]# cd  ~tom       #去往tom用户的家目录
[root@localhost /]# pwd


ls — List
格式:ls [选项]... [目录或文件名]
常用命令选项:
-l:以长格式显示,显示详细信息
-h:提供易读的容量单位(K、M等)
-d:显示目录本身(而不是内容)的属性
[root@localhost /]# ls  -ld   /home
[root@localhost /]# ls  -ld   /root
[root@localhost /]# ls  -ld    /

[root@localhost /]# ls  -l     /etc/passwd
[root@localhost /]# ls  -lh   /etc/passwd

-A:显示所有内容,包含隐藏数据
-R:递归显示目录内容
[root@localhost /]# ls  -A     /root
[root@localhost /]# touch    /opt/.nsd.txt
[root@localhost /]# ls    /opt/
[root@localhost /]# ls   -A    /opt/
[root@localhost /]# ls  -R   /boot


通配符使用
*:任意多个任意字符
[root@localhost /]# ls    /root/a*
[root@localhost /]# ls    /boot/vm*
[root@localhost /]# ls    /etc/*tab
[root@localhost /]# ls    /etc/*.conf
[root@localhost /]# ls    /etc/re*.conf
[root@localhost /]# ls    /dev/tty*

[root@localhost /]# ls   -d   /etc/r*
[root@localhost /]# ls   -d   /etc/*as*

?:单个字符(必须要有一个)
[root@localhost /]# ls   /etc/??tab
[root@localhost /]# ls   /dev/tty?
[root@localhost /]# ls   /dev/tty??
[a-z]:多个字符或连续范围中的一个,若无则忽略
{a,min,xy}:多组不同的字符串,全匹配
[root@localhost /]#  ls    /dev/tty[3-9]    
[root@localhost /]#  ls    /dev/tty[1-7]             
[root@localhost /]#  ls    /dev/tty{1,17,20}            
[root@localhost /]#  ls    /dev/tty{10,18,22,33}
[root@localhost /]#  ls    /dev/tty{26,19,21,30,40}
[root@localhost /]#  ls    /etc/{rw,fs}tab

命令的别名:简化复杂的命令

查看已设置的别名
alias 

定义新的别名
alias 别名名称= '实际执行的命令行'

取消已设置的别名
unalias [别名名称]

[root@localhost /]#  hostname               
[root@localhost /]#  alias   hn='hostname' #临时定义别名
[root@localhost /]#  hn

[root@localhost /]#  alias           #查看系统中有哪些别名
[root@localhost /]#  unalias    hn    #删除hn别名
[root@localhost /]#  hn
bash: hn: 未找到命令... 

[root@localhost /]#  alias     myls='ls   -l'   
[root@localhost /]#  myls   /etc/passwd

mkdir — Make Directory
格式:mkdir [/路径/]目录名…
[-p]:连同父目录一并创建

]#  mkdir   -p    /opt/aa/bb/cc/dd
]#  ls   -R    /opt/aa       #递归显示目录内容

]#  mkdir    -p    /nsd04/test04
]#  ls   -R     /nsd04
]#  mkdir    -p    /cbd/abc01
]#  ls   -R     /cbd
]#  mkdir    -p    /xtt/stu01
]#  ls   -R     /xtt


rm 删除 Remove
格式:rm [选项]... 文件或目录…
常用命令选项
-r、-f:递归删除(含目录)、强制删除

[root@localhost /]#  ls     /opt
[root@localhost /]#  rm     -rf     /opt/1.txt
[root@localhost /]#  ls    /opt

[root@localhost /]#  rm     -rf     /opt/aa
[root@localhost /]#  ls     /opt


mv移动:源数据消失
[root@localhost /]#  rm  -rf  /opt/*
[root@localhost /]#  mkdir    /opt/nsd01
[root@localhost /]#  touch    /opt/1.txt
[root@localhost /]#  ls     /opt/

[root@localhost /]#  mv     /opt/1.txt      /opt/nsd01
[root@localhost /]#  ls    /opt/

[root@localhost /]#  ls   /opt/nsd01

重新命名:路径不变的移

[root@localhost /]#  ls   /opt/
[root@localhost /]#  mv   /opt/nsd01    /opt/abc
[root@localhost /]#  ls   /opt/
[root@localhost /]#  mv    /opt/abc       /opt/student
[root@localhost /]#  ls    /opt/

[root@localhost /]#  mv    /opt/student     /mnt/stu01
[root@localhost /]#  ls    /mnt/


cp:复制/拷贝
-r:复制目录
[root@localhost /]#  cp      /etc/passwd       /opt
[root@localhost /]#  ls     /opt

[root@localhost /]#  cp    -r     /boot       /opt  
[root@localhost /]#  ls     /opt

[root@localhost /]#  cp    -r     /home      /opt
[root@localhost /]#  ls     /opt

进行强制覆盖
]#  \cp  -r  /boot  /opt   #本次操作临时取消别名
]#  \cp  -r  /boot  /opt   #本次操作临时取消别名

复制可以重新命名,目标路径下数据的名称
]#  cp    -r    /home   /opt/myhome
]#  ls    /opt
]#  cp    /etc/shells     /opt/r.txt
]#  ls    /opt       
   
]#  ls     /opt
]#  cp    -r     /boot    /opt/myboot
]#  ls    /opt
]#  cp   -r     /boot     /opt/myboot  
]#  ls      /opt/myboot


复制可以支持两个以上的参数,永远把最后一个参数作为目标,其他的所有的参数都作为源数据
]# mkdir    /nsd05
]# ls   /nsd05

]# cp    -r    /home    /boot   /etc/passwd    /etc/shells      /nsd05

]# ls    /nsd05

复制与一个点进行连用,将数据复制到当前路径下
]#  cd    /etc/sysconfig/network-scripts/
]#  pwd
]#  cp   /etc/passwd     .  
]#  ls

]#  cd    /mnt        
]#  pwd
]#  cp   /etc/shells    .  
]#  ls


grep过滤文件内容,输入包含指定字符串的行

常用命令选项
-v,取反匹配(不包含)
-i,忽略大小写
[root@localhost /]#  grep   root     /etc/passwd
[root@localhost /]#  grep  -v   root    /etc/passwd
[root@localhost /]#  grep  ROOT    /etc/passwd
[root@localhost /]#  grep  -i  ROOT  /etc/passwd


高级使用
^word   以字符串word开头
word$   以字符串word结尾
[root@localhost /]#  grep   ^root   /etc/passwd
[root@localhost /]#  grep   ^bin     /etc/passwd
[root@localhost /]#  grep   root$    /etc/passwd
[root@localhost /]#  grep   bash$    /etc/passwd      

^$:表示空行

]#  cat   /etc/default/useradd
]#  grep  ^$  /etc/default/useradd  #过滤空行
]#  grep -v  ^$  /etc/default/useradd  #过滤不要空行的内容

]#  cat   /etc/login.defs
]#  grep  ^$  /etc/login.defs  #过滤空行
]#  grep -v  ^$  /etc/login.defs  #过滤不要空行的内容


 


案例:复制、删除、移动
1. 在目录/opt下创建一个子目录 nsd
2. 在目录/opt/nsd/创建文件readme.txt,利用vim写入内容 I Love Linux

3. 将/etc/passwd 和 /etc/fstab同时拷贝到/opt/nsd目录下
4. 将文件 /etc/shells复制到 /root/ 下,同时 改名为 version.txt

5. 将文件 /root/version.txt 移动到/opt/nsd/目录下
6. 将/home目录复制到/opt/nsd/目录下


常见的压缩格式:
 gzip------》.gz
 bzip2----》.bz2
 xz----》.xz

制作压缩包(打包)
格式:
tar   [选项]   /路径/压缩包名字    /路径/被归档压缩的数据………

-c:制作压缩包(制作tar包)   -f:指定压缩包名字(必须在所有选项的最后)
 -z  -j  -J:  gzip   bzip2     xz

]# tar  -zcf  /root/cbd.tar.gz  /etc/passwd  /home
]# ls  /root          
      
]# tar  -jcf  /root/haha.tar.bz2  /etc/passwd  /home
]# ls   /root

]# tar  -Jcf  /root/cctv.tar.xz  /etc/passwd   /home
]# ls   /root


释放压缩包(解包)
格式:
tar   [选项]    /路径/压缩包的名字   [选项]   /释放路径

  -x:解包操作    -f:指定tar包名字
  -C:指定路径
[root@nb ~]# mkdir   /nsd10
[root@nb ~]# ls   /nsd10
[root@nb ~]# tar  -xf  /root/cbd.tar.gz  -C   /nsd10
[root@nb ~]# ls  /nsd10
[root@nb ~]# ls  /nsd10/etc
[root@nb ~]# ls  /nsd10/home/

tar高级使用:归档压缩时不进行路径的归档
]# tar -zcf  /root/zz.tar.gz   -C   /etc/    passwd         -C  /usr/    games

]# tar  -tf   /root/zz.tar.gz    #查看tar包内容

]# tar  -zcf  /root/yy.tar.gz  -C  /etc/  shells    fstab  hosts 
]# tar  -tf  /root/yy.tar.gz     #查看tar包内容

[root@nb ~]# mkdir   /nsd11
[root@nb ~]# tar   -xf   /root/yy.tar.gz   -C  /nsd11
[root@nb ~]# ls   /nsd11


本例要求使用tar工具完成以下备份任务:
创建一个名为/root/backup.tar.bz2的归档文件
其中包含/usr/local目录中的内容
tar归档必须使用bzip2进行压缩

[root@nb ~]# tar  -jcf   /root/backup.tar.bz2  /usr/local
tar: 从成员名中删除开头的“/”
[root@nb ~]# ls  /root

[root@nb ~]# tar  -tf  /root/backup.tar.bz2

重定向操作:重新定向命令的输出
将前面命令的输出,作为内容,写入到后面的文件
>:覆盖重定向
>>:追加重定向

[root@A /]# head  -5  /etc/passwd  >  /opt/p.txt
[root@A /]# cat   /opt/p.txt

[root@A /]# head  -2  /etc/passwd  >  /opt/p.txt
[root@A /]# cat  /opt/p.txt

[root@A /]# hostname 
[root@A /]# hostname   >>   /opt/p.txt 
[root@A /]# cat   /opt/p.txt

echo命令的使用
]# echo     123456           
]# echo   123456    >    /opt/p.txt
]# cat     /opt/p.txt

]# echo     hello  world           
]# echo   hello  world    >>    /opt/p.txt
]# cat     /opt/p.txt

]# cat     /etc/hostname 
]# echo    nb.tedu.cn    >    /etc/hostname
]# cat    /etc/hostname


管道操作  |  
作用:将前面命令的输出,传递给后面命令,作为后面命令的参数

]# head  -4  /etc/passwd   |      tail  -1 
]# head  -8  /etc/passwd  |   tail  -1

]# cat -n  /etc/passwd  |  head  -8  |   tail  -1

]# ifconfig  |  head  -2

不支持管道:
1.命令没有参数也能执行
  2.所有双参数以上的命令  cp  mv  mount
  3.命令没有输出不能参与管道

显示8~12行内容
]# head  -12  /etc/passwd   |    tail  -5
]# cat -n  /etc/passwd   |  head -12
]# cat -n  /etc/passwd  |  head  -12  |  tail -5

]# cat -n  /etc/passwd  |  head -12  |   tail -5  > /opt/pa.txt

]# cat  /opt/pa.txt  

Linux中大多数配置文件内容,以#开头的行为注释行
显示配置文件有效信息(去除以#开头的注释行和去除空行)
]# grep -v  ^#  /etc/login.defs
]# grep -v  ^#  /etc/login.defs  |  grep -v  ^$

]# grep -v ^# /etc/login.defs   |  grep -v ^$  > /opt/log.txt

]# cat  /opt/log.txt

过滤命令的输出
[root@localhost /]# ifconfig  |    grep  inet
[root@localhost /]# ifconfig   |    grep  127
[root@localhost /]# ifconfig    |    less       #方便查看

find查找
递归式查找   
只能查找硬盘的数据

格式:  find   查找的路径     条件
-type  f(文件)   d(目录)   l(快捷方式)
[root@A /]# find    /boot     -type    d
[root@A /]# find    /opt     -type    d

[root@A /]# find    /etc     -type    l   
[root@A /]# find    /boot    -type    f
[root@A /]# find    /usr     -type    d
[root@A /]# find    /var     -type    d
[root@A /]# find    /sbin     -type    l   
[root@A /]# find    /bin     -type    f

-name   支持通配符 * 号
-iname  忽略大小写
]# find    /etc    -name    "passwd"
]# find    /etc    -name    "*tab"
]# find    /etc    -name    "*.conf"
]# find  /root  -name   ".*"          #查找隐藏数据
]# find   /etc    -name   "*tab"   |  wc  -l

]# find   /etc    -name  "*.conf"   |  wc  -l
]# find   /etc   -name  "*.conf"  |  cat  -n

两个条件联合使用
]# mkdir   /mnt/cbd01
]# mkdir   /mnt/cbd02
]# touch   /mnt/cbd03.txt

]# find   /mnt/   -name   "cbd*"
]# find   /mnt/   -name   "cbd*"  -type   d
]# find   /mnt/   -name   "cbd*"  -type   f

]# find   /mnt/   -name   "cbd*" -o  -type   f    #两个满足其中一个

-size  k   M   G

]# find   /boot   -size  +300k

]# find   /boot   -size  +10M
]# find   /boot   -size  +20M

]# find   /boot   -size  +10M    -size  -50M

-user  数据的所有者
[root@A /]# useradd  natasha  #创建用户
[root@A /]# find  /home   -user    natasha
[root@A /]# find    /      -user    natasha
/proc:内存的数据,不占用硬盘空间

[root@A /]# useradd  harry  #创建用户
[root@A /]# find  /home   -user    harry
[root@A /]# find    /      -user    harry

-mtime  数据修改时间

+90   #90天之前的数据,三个月之前
-10    #最近10天之内

三个月之前的数据:    
[root@A /]# find  /var  -mtime  +90


最近10天之内的数据:
[root@A /]# find  /root  -mtime  -10


补充:
-newermt    #在此时间之后
! -newermt  #不在此时间之后(在此时间之前)

在2024-4-30 10:00:00时间之后
]# find  /var/  -newermt  '2024-4-30 10:00:00'

在今天10:00:00时间之后,在今天14:00时间之前
]# find /var/ -newermt '10:00:00'  !  -newermt '14:00:00'

find高级使用:处理find查找的数据

处理find找到的数据,每查找的一个就传递一次
find [范围] [条件]  -exec  处理命令 {}   \;

-exec额外操作的开始
{} 永远表示前面find查找的结果
\; 额外操作的结束

]# find   /boot   -size     +10M
]# find  /boot  -size   +10M  -exec  cp  {}  /mnt  \;      
]# ls    /mnt

]# find  /boot  -size +10M  -exec  ls -lh  {}  \;

两个条件联合使用
]# mkdir   /root/mytab

]# find    /etc   -name   "*tab"    -type   f

]# find   /etc    -name  "*tab"    -type   f
 -exec   cp       {}    /root/mytab    \;


]# ls    /root/mytab


利用find查找,数据的所有者为 student,并且必须是文件,把它们拷贝到 /root/findfiles 文件夹中

]# useradd  student           #创建普通用户student     
]# mkdir  /root/findfiles   
                                           
]# find   /    -user  student   -type  f
]# find  /  -user student  -type  f  -exec cp  {}  /root/findfiles   \;

]# ls  -A  /root/findfiles/   #-A显示隐藏数据

[root@nb ~]# cp   /etc/passwd   /opt/pass.txt
[root@nb ~]# vim   /opt/pass.txt


读入另一个文件的内容

读取文件内容
[root@localhost /]# echo  123456  >  /opt/aa.txt
[root@localhost /]# echo  hahaxixi  >  /opt/cc.txt

[root@localhost /]# vim    /opt/cc.txt
末行模式下    :r  /opt/aa.txt
末行模式下    :r  /etc/passwd
末行模式下    :r  /etc/shells

[root@localhost /]# cp  /etc/passwd    /opt/s.txt
[root@localhost /]# vim  /opt/s.txt

字符串替换
:1,10s/root/new/g  替换第1-10行所有的“root”
:%s/bin/xixi/g     替换文件内所有的“bin”


开关参数的控制
:set  nu或nonu   显示/不显示行号
:set  ai或noai    启用/关闭自动缩进

永久的vim开关设置
配置文件路径: 在用户的家目录 .vimrc

[root@nb ~]# vim   /root/.vimrc
set  nu    #在插入模式下,写入内容


[root@nb ~]# vim   /opt/pass.txt     #测试是否有行号


vimdiff同时比对或修改多个文件
[root@a ~]# echo  hahaxixi  >  /opt/aa.txt
[root@a ~]# echo  hahaabc  >  /opt/bb.txt
[root@a ~]# vimdiff  /opt/aa.txt   /opt/bb.txt

命令模式下Ctrl与w同时按下,然后 左 右键移动光标
末行模式wqa保存全部文件并退出


 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值