首页 > 系统相关 >简单的linux系统学习笔记——07

简单的linux系统学习笔记——07

时间:2024-08-16 17:24:26浏览次数:11  
标签:07 -- root 笔记 linux 100 txt c7 find

一、虚拟机克隆

本体删了,克隆机也会消失

1.先关闭虚拟机

2.右键虚拟机点管理,点击克隆

3.克隆源选择“虚拟机中的当前状态”

4.克隆类型选择“创建链接克隆”

5.编辑虚拟机名字,设置存放路径

6.点击完成

7.修改主机名

8.更改ip,修改网卡

9.重启,保存快照

二、文件

文件属性:

1)权限

2)类型

3)大小

4)时间

5)文件所属

文件相关命令:
file  //查看文件信息
find  //找文件
which //命令(文件)
tar   //压缩与解压缩

三、查看文件的详细信息

属性解释
[root@c7-100 ~]# ll -i 11.txt
67168144 -rw-r--r--. 1 root root 567 7月  18 19:06 11.txt

67168144   //inode号,系统中文件存储在磁盘中的唯一标识,类似座位号
-          //代表是普通文件(d:目录  -:普通文件)
rw-r--r--  //【rw-】:属主的权限【r--】:属组的权限【r--】:其他用户
1          //文件的硬链接数量
root       //属主
root       //属组
567        //字节大小 8bit=1字节  1024字节=1kb  1024kb=1m  1024m=1g 1024g=1t 1024t=1p                                                                              1024p=1e
7月  18 19:06  //时间
11.txt     //文件名称



查看文件更更更详细的信息
[root@c7-100 ~]# stat 11.txt
  文件:"11.txt"
  大小:567       	块:8          IO 块:4096   普通文件
设备:803h/2051d	Inode:67168144    硬链接:1
权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)
最近访问:2024-07-18 19:06:06.639381353 +0800     //最近查看
最近更改:2024-07-18 19:06:00.394988485 +0800     //最近一次内容被修改的时间
最近改动:2024-07-18 21:57:51.998889054 +0800     //属性信息发生变化的时间
创建时间:-

四、文件类型分类

linux的拓展名,只是标识作用,没有实际意义
.config  //配置文件
.rpm     //安装包格式
.tar  .gz  .zip  //压缩包格式
.log     //日志文件


使用【file】命令查看一个文件的类型
[root@c7-100 ~]# file jb.sh
jb.sh: Bourne-Again shell script, UTF-8 Unicode text executable


以符号区分
-  //普通文件
d  //目录
l  //连接文件
****拓展****
c  //字符设备文件(无法查看全是乱码)
b  //block,块设备文件
s  //socket,进程与进程之间本机内通信使用的文件

五、文件相关的命令

1.file命令

查看文件类型

#普通文件
[root@c7-100 ~]# file 1.txt 
1.txt: ASCII text

#图片
[root@c7-100 ~]# file banner.jpg 
banner.jpg: JPEG image data, EXIF standard

#链接文件
[root@c7-100 ~]# file /etc/rc.local
/etc/rc.local: symbolic link to `rc.d/rc.local'

#目录
[root@c7-100 ~]# file /etc
/etc: directory

#块设备
[root@c7-100 ~]# file /dev/sda1
/dev/sda1: block special

#压缩文件
[root@c7-100 ~]# file html.zip 
html.zip: Zip archive data, at least v1.0 to extract

2.which查看命令文件路径

[root@c7-100 ~]# which vim
/usr/bin/vim

3.find查找文件位置

【【【  find + 要查找的位置路径 + 参数 + 搜索的值(内容)  】】】

通过文件名查找【-name】
[root@c7-100 ~]# find / -name "ifcfg-eth0"
/etc/sysconfig/network-scripts/ifcfg-eth0

忽略大小写查找【-iname】
[root@c7-100 ~]# find ./ -name a.txt
./a.txt
[root@c7-100 ~]# find ./ -iname a.txt
./A.txt
./a.txt

[root@c7-100 ~]# cat `find / -name "ifcfg-eth0"`  //【``】先执行反引号中的内容
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
NAME=eth0
UUID=6083d416-be6b-4efb-9459-1021d85c8a6f
DEVICE=eth0
ONBOOT=yes
IPADDR=10.0.0.100
PREFIX=24
GATEWAY=10.0.0.2
DNS1=223.5.5.5


通过文件时间查找【-mtime】以天为单位
[root@c7-100 ~]# find / -mtime +2  //两天之前所创建的文件
[root@c7-100 ~]# find / -mtime -2  //两天之内创建的文件

通过文件时间查找【-mmin】以分钟为单位
[root@c7-100 ~]# find / -mmin +2   //两分钟之前创建
[root@c7-100 ~]# find / -mmin -2   //两分钟之内创建


通过文件类型查找【-type】
-  //find:f
d  //d
l  //l

[root@c7-100 ~]# find /etc/ -type l
[root@c7-100 ~]# find /etc/ -type d
[root@c7-100 ~]# find /etc/ -type f

组合使用
[root@c7-100 ~]# find / -type f -name *-eth0
/etc/sysconfig/network-scripts/ifcfg-eth0

取反
[root@c7-100 ~]# find / ! -type f -name *-eth0


通过文件大小查找【-size】
查找家目录下,大于5m文件
[root@c7-100 ~]# find ~ -size +5M
/root/2.txt
/root/3.txt
/root/1.txt


查找家目录下,小于15m的文件
[root@c7-100 ~]# find ~ -size -15M


总结
[root@c7-100 ~]# find ~ -size -15M   //小于15m
                              -15    //小于15字节  默认【15c】
                              -15G   //小于15G
                              -15k   //小于15kb
                              
                              
*** 拓展 ***
通过权限查找【-perm】
[root@c7-100 ~]# find ~ -perm 755
/root/a
/root/b
/root/b/qwe
/root/c
/root/hi

4.tar压缩与解压

压缩作用:

1.节省空间

2.增加传输效率

原理:

1.创建一个空的压缩文件

2.将被压缩为放进去文件

【【【  tar + zcvf + 压缩文件名称 + 要压缩的文件  】】】
[root@c7-100 test]# ll
总用量 4
-rw-r--r--. 1 root root   0 7月  18 15:23 1.txt
-rw-r--r--. 1 root root 312 7月  18 21:59 33.txt
drwxr-xr-x. 2 root root   6 7月  18 15:11 a
drwxr-xr-x. 3 root root  28 7月  18 15:21 b
[root@c7-100 test]# tar zcvf yasuo.tar.gz ./*
./1.txt
./33.txt
./a/
./b/
./b/qwe/
./b/ihi
[root@c7-100 test]# ll
总用量 8
-rw-r--r--. 1 root root   0 7月  18 15:23 1.txt
-rw-r--r--. 1 root root 312 7月  18 21:59 33.txt
drwxr-xr-x. 2 root root   6 7月  18 15:11 a
drwxr-xr-x. 3 root root  28 7月  18 15:21 b
-rw-r--r--  1 root root 378 7月  25 11:21 yasuo.tar.gz

参数解释
z  //压缩数据的方式:zzip
c  //创建压缩包
v  //显示压缩过程
f  //识别压缩包生成的路径
h  //跟随软连接,将源文件进行压缩

解压前查看文件内容

【tf】解压文件前查看,不能查看压缩包里文件夹的内容
[root@c7-100 test]# tar tf yasuo.tar.gz
./1.txt
./33.txt
./a/
./b/
./b/qwe/
./b/ihi

解压压缩包

【xvf】(x解压)
[root@c7-100 test]# tar xvf yasuo.tar.gz -C /t1

-C  //指定路径

5.命令结合使用

find与tar

创建测试数据
[root@c7-100 old]# touch old{1..3}
[root@c7-100 old]# touch old{1..3}.txt
[root@c7-100 old]# ll /old
总用量 0
-rw-r--r-- 1 root root 0 7月  25 15:07 old1
-rw-r--r-- 1 root root 0 7月  25 15:07 old1.txt
-rw-r--r-- 1 root root 0 7月  25 15:07 old2
-rw-r--r-- 1 root root 0 7月  25 15:07 old2.txt
-rw-r--r-- 1 root root 0 7月  25 15:07 old3
-rw-r--r-- 1 root root 0 7月  25 15:07 old3.txt

找到以.txt结尾的文件,并压缩以【``】方式
[root@c7-100 old]# tar zcvf ha.tar.gz `find /old -name "*.txt"`
tar: 从成员名中删除开头的“/”
/old/old1.txt
/old/old2.txt
/old/old3.txt
[root@c7-100 old]# ll /old
总用量 4
-rw-r--r-- 1 root root 139 7月  25 15:13 ha.tar.gz
-rw-r--r-- 1 root root   0 7月  25 15:07 old1
-rw-r--r-- 1 root root   0 7月  25 15:07 old1.txt
-rw-r--r-- 1 root root   0 7月  25 15:07 old2
-rw-r--r-- 1 root root   0 7月  25 15:07 old2.txt
-rw-r--r-- 1 root root   0 7月  25 15:07 old3
-rw-r--r-- 1 root root   0 7月  25 15:07 old3.txt
[root@c7-100 old]# tar tf ha.tar.gz 
old/old1.txt
old/old2.txt
old/old3.txt


以【|】的方式
[root@c7-100 old]# find ./ -name "*.txt" |xargs tar zcvf wa.tar.gz  //xargs是分组
./old1.txt
./old2.txt
./old3.txt
[root@c7-100 old]# tar tf wa.tar.gz 
./old1.txt
./old2.txt
./old3.txt


- 【了解即可】【exec】方式结合使用(逐条执行)
[root@c7-100 old]# find ./ -name "*.txt" -exec tar zcvf  wahh.tar.gz {} \; 
./old1.txt
./old2.txt
./old3.txt
[root@c7-100 old]# tar tf wahh.tar.gz 
./old3.txt

六、xargs分组显示

[root@c7-100 old]# find ./ -name "*.txt" | xargs
./old1.txt ./old2.txt ./old3.txt

[root@c7-100 old]# find ./ -name "*.txt" | xargs -n2
./old1.txt ./old2.txt
./old3.txt

[root@c7-100 old]# find ./ -name "*.txt" | xargs -n3
./old1.txt ./old2.txt ./old3.txt

[root@c7-100 old]# find ./ -name "*.txt" | xargs -n1
./old1.txt
./old2.txt
./old3.txt

07-完

标签:07,--,root,笔记,linux,100,txt,c7,find
From: https://blog.csdn.net/weixin_44550167/article/details/141264603

相关文章

  • Leetcode刷题笔记8.12-8.16
    Leetcode刷题笔记8.12-8.1619.删除倒数第n个链表结点(8.12)一个巧妙删除倒数第n个结点的trick该方法避免了对链表的一次全面扫描来获得总长度//返回链表的倒数第k个节点ListNodefindFromEnd(ListNodehead,intk){ListNodep1=head;//p1先走k步......
  • Linux安装Nginx详细教程
    1.安装nginx依赖yum-yinstallgccgcc-c++pcrepcre-develzlibzlib-developensslopenssl-devel2.安装wgetyum-yinstallwget我这里是已经安装好的,运行代码会是下面的结果,不确定自己有没有安装,可以执行试下 3.创建nginx安装目录    /usr/local/目录下......
  • 韩顺平linux——centos安装
    centos安装选redhat红帽,centos是红帽的分支。 开发工具包含gccjdkmysql。 软件选择,默认最小安装,很多功能如gcc不带,学习过程需要一个桌面。磁盘分区boot分区1G设备类型:标准分区 文件类型ext4swap分区1G 设备类型:标准分区 文件类型swaproot分区17G 设备类......
  • 【linux学习指南】Linux管理文件与处理数据二(重定向与管道)
    文章目录......
  • 题解:P10781 【MX-J1-T1】『FLA - III』Spectral
    P10781【MX-J1-T1】『FLA-III』Spectral题解(非正解,正解应该是数学题。)这道题很简单,分析题意就可以得出核心代码:for(inti=1;i<=n;i++){ans=k+ans/i;}那么恭喜你获得$40$pts。为什么呢?因为题目需要的是最高温度,而烧碳获得的温度可能小于烧炭时减低的温度。简单说......
  • [笔记]关于在linux中通过yum安装mysql错误--因为Centos 7官方镜像不可用的解决方法
     因为Centos7在2024年6月30号停止维护   在执行命令时找不到镜像源, 在下载时出现的错误为,还有一种错误由于没有截图,但是问题一样先通过yumremovemariadb*-y去删除自带的sql包通过命令编辑这个文本文件 vim/etc/yum.repos.d/CentOS-Base.repo这里举......
  • 【Linux操作系统】——Linux基本命令3
    1、vi与vim的简介  在Linux下,绝大部分的配置文件都是以ASCII码的纯文本形式存在的,可以利用一些简单的编辑软件修改配置。  在Linux命令行界面下的文本编辑器有很多,比如nano,Emacs,vim等。但是所有的UNIXLike系统都会内置vi文本编辑器,而其他的文本编辑器则不一定存在......
  • Linux中yum、vim、gcc/g++的使用
    目录一、Linux软件包管理器yum什么是软件包关于rzsz查看软件包★如何安装软件★如何卸载软件★Linux开发工具二、Linux编译器-vim使用vim的基本概念vim的基本操作vim正常模式命令集vim末行模式命令集vim操作总结如果在vim界面不小心按了Ctrl+Z怎么处理批......
  • 方法精讲-言语1笔记
    前:1、听思路、听方法,举一反三是目的。2、挖坑在哪是重点。3、跟上笔记言语理解与表达考情:联考-省一、三大类:1、片段阅读2、语句表达3、逻辑填空二、1、题量40~25不等2、考场上速度,标准题量-5分钟如:40-5=35分3、开始学不要求速度4、文科80%以上的准确率合格5、理......
  • Linux shell脚本实战案例
    文章目录1.基础案例:显示系统信息2.文件备份案例3.自动安装软件案例4.批量重命名文件案例5.监控磁盘空间案例6.定时任务案例:定期清理日志文件7.错误处理和日志记录案例:安全地运行命令8.备份数据库案例:定期备份MySQL数据库9.系统监控案例:CPU和内存使用率10.用户......