先关注后白嫖,谢谢啦

目录

1Linux系统安装

一、Linux系统介绍

1、Linux系统简介

2、Linux系统的组成

3、Linux发行版本

二、Linux系统安装

2、将安装镜像放入光驱、开机

3、系统安装阶段

1)菜单选择

2)选择系统安装语言

3)设置系统时区、时间

4)软件选择

6)硬盘分区

7)设置root用户密码

8)创建普通用户

9)创建虚拟机快照!!!!!!

三、查看系统版本

1、查看内核版本

2、查看发行版本

四、Linux目录结构

2文件目录管理

一、切换、查看目录

命令格式

二、查看目录下的文件

命令格式:

1、查看当前目录下的文件

2、查看指定目录下的文件

3、常用选项

1)-l 查看文件的详细信息

2)-h 显示大小单位K,M,G,T

3)-d 显示目录的详细信息

4)-S 按文件大小排序

5)-t 按文件修改时间排序

6)-a 查看所有文件(隐藏文件)

三、创建目录

四、创建空白文件

五、查看文件内容

1、cat 查看文件全部内容

查看Linux发行版本

查看CPU的型号

查看CPU的数量

2、more/less 分页查看

3、head/tail

六、查看文件类型

七、统计文件的行数

八、管道符 |

九、删除文件、目录

1、-f 强制删除

2、-r 删除目录(三思而后行哦)

十、复制文件目录

1、复制文件

2、复制同时改名

3、复制目录 -选项

十一、移动文件目录

1、移动文件

2、移动目录

3、重命名

3文件目目录管理(修改查找压缩)

一、vim编辑器

1、介绍

2、模式间的切换

3、末行模式

4、命令模式

二、命令别名

1、配置vim编辑器显示行号

2、命令别名

三、文件压缩、解压缩/归档文件

1、文件压缩、解压缩

2、归档文件管理

四、查找文件 find

1、查找条件

2、按多条件查找

3、-exec 命令 \;

4、-maxdepth 数字

4文件目录管理(过滤、排序)

一、过滤/查看文件内容 grep

1、命令使用格式

2、正则表达式

3、常用选项

二、排序、去重

1、去重

2、排序

三、统计文件、目录大小 du

1、统计文件大小

2、统计目录大小

3、统计所有文件大小


1Linux系统安装

一、Linux系统介绍

1、Linux系统简介

  • 一类操作系统的统称
  • 部署在服务器
  • 服务器
    • 专业硬件设备

      • pc server, 刀片服务器、小型机
      • 提供服务的机器
    • 优势
      • 开源            开放源代码 (open source)
      • 最大化发挥硬件性能

2、Linux系统的组成

  • 内核(kernel)
  • The Linux Kernel Archiveshttps://www.kernel.org/
    • 作用:驱动硬件(硬盘、网卡)正常工作
    • 版本  x.y.z
      • x:主版本号

        • 2,3,4
      • y:次版本号
        • 偶数        稳定
        • 奇数        开发测试(不稳定)
      • 应用程序

3、Linux发行版本

  • 红帽(Redhat)

    • rhel(红帽企业版)收费
    • centeos(社区版)免费
  • 麒麟(国产)
    • 银河麒麟服务器操作系统
    • 银河麒麟桌面版操作系统
  • 华为
    • EulerOS
  • 统信
    • 通信OS

二、Linux系统安装

1、创建空虚拟机

2、将安装镜像放入光驱、开机

3、系统安装阶段

1)菜单选择

  • 直接安装系统
  • 检测安装介质,安装系统
  • 排错

2)选择系统安装语言

3)设置系统时区、时间

4)软件选择

  • 最小安装
  • GNOME桌面(全包安装)

5)网络设置

6)硬盘分区

  • /boot 启动分区 800M

    • 内核、系统启动相关配置文件
  • swap 交换分区/虚拟内存 2G
    • 当物理内存不足时,会使用swap区分充当内存
  • / 根分区 (必须有)

7)设置root用户密码

8)创建普通用户

9)创建虚拟机快照!!!!!!

三、查看系统版本

CTRL shift + 调大字体

CTRL - 调小字体

1、查看内核版本

@localhost ~]# uname -r
3.10.0-1160.el7.x86_64
  • x84_64

    • 操作系统的架构

      • 32位

        • 最大只能识别4G内存
      • 64位

2、查看发行版本

[root@localhost ~]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

四、Linux目录结构

  • 一切皆文件!!!!!!
  • /root:管理员root用户的家目录/宿主目录
  • /home:普通用户的家目录/宿主目录
    • 用户CK /home/CK
    • 用户hmq /home/hmq
  • /dev:存放设备文件(磁盘、U盘、光盘、打印机)
  • /etc:存放配置文件
  • /tmp:存放临时文件
  • /opt:个人文档、数据
  • /boot:启动分区
    • 内核、启动配置分区
  • /proc  ,  /sys:动态数据文件
  • /lib64:库文件(保证某应用程序、功能可正常运行)

五、命令提示符格式

[root@localhost ~]# 
  • root 挡墙登录系统的用户名
  • # 管理员
    • $ 普通用户
  • localhost 主机名
  • ~ 当前用户的家目录/宿主目录

2文件目录管理

一、切换、查看目录

  • 支持tab补全功能
  • 路径的表示方法
    • 绝对路径(从根目录开始向下写)
    • 相对路径(相对于当前目录)

命令格式

# cd [目录名称] 
[root@localhost ~]# cd /home
[root@localhost home]# pwd
/home[root@localhost home]# cd /etc
[root@localhost etc]# pwd
/etc[root@localhost etc]# cd /etc/sysconfig/
[root@localhost sysconfig]# pwd
/etc/sysconfig[root@localhost sysconfig]# cd /
[root@localhost /]# pwd
/
[root@localhost ~]# cd /etc/sysconfig/
[root@localhost sysconfig]# pwd
/etc/sysconfig
[root@localhost sysconfig]# cd ..
[root@localhost etc]# pwd
/etc
[root@localhost etc]# cd ..
[root@localhost /]# pwd
/
  • ..上一层目录
[root@localhost /]# pwd
/
[root@localhost /]# cd
[root@localhost ~]# pwd
/root
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# pwd
/etc/sysconfig/network-scripts
[root@localhost network-scripts]# cd
[root@localhost ~]# pwd
/root
[root@localhost ~]# cd /etc/sysconfig/
[root@localhost sysconfig]# pwd
/etc/sysconfig
[root@localhost sysconfig]#
[root@localhost sysconfig]# cd /
[root@localhost /]# cd etc/
[root@localhost etc]# pwd
/etc
[root@localhost etc]# cd sysconfig/
[root@localhost sysconfig]#
[root@localhost sysconfig]# pwd
/etc/sysconfig
  • 绝对路径、相对路径

二、查看目录下的文件

命令格式:

 ls [选项] [目录名称]

1、查看当前目录下的文件

[root@localhost ~]# pwd
/root
[root@localhost ~]# ls
anaconda-ks.cfg  initial-setup-ks.cfg  公共  模板  视频  图片  文档  下载  音乐  桌面[root@localhost ~]# cd /boot
[root@localhost boot]# ls
config-3.10.0-1160.el7.x86_64                            initramfs-3.10.0-1160.el7.x86_64.img
efi                                                      symvers-3.10.0-1160.el7.x86_64.gz
grub                                                     System.map-3.10.0-1160.el7.x86_64
grub2                                                    vmlinuz-0-rescue-d54fe4be6b674b079972696d39457a41
initramfs-0-rescue-d54fe4be6b674b079972696d39457a41.img  vmlinuz-3.10.0-1160.el7.x86_64[root@localhost boot]# cd /
[root@localhost /]# ls
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

2、查看指定目录下的文件

[root@localhost ~]# ls /root/
anaconda-ks.cfg  initial-setup-ks.cfg  公共  模板  视频  图片  文档  下载  音乐  桌面[root@localhost ~]# ls /
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var[root@localhost ~]# ls /etc/

3、常用选项

1)-l 查看文件的详细信息

[root@localhost ~]# ls -l
总用量 8
-rw-------. 1 root root 1842 7月   6 09:44 anaconda-ks.cfg
[root@localhost ~]# ls -l /etc/hosts
-rw-r--r--. 1 root root 158 6月   7 2013 /etc/hosts[root@localhost ~]# ls -l /etc/sysconfig/network-scripts/ifcfg-ens33
-rw-r--r--. 1 root root 310 7月   5 14:02 /etc/sysconfig/network-scripts/ifcfg-ens33
  • anaconda-ks.cfg 文件名
  • 7月 6 09:44 最后一次的修改时间
  • 1842 文件大小,默认单位B
  • rw-------. 1 root root 权限
  • 文件类型
    • - 普通文件
    • d 目录
    • l 软链接文件(快捷方式)
    • b 块设备文件(硬盘、分区、U盘)
    • c 字符设备文件(键盘、鼠标、显示器)

2)-h 显示大小单位K,M,G,T

[root@localhost ~]# ls -lh /etc/sysconfig/selinux
lrwxrwxrwx. 1 root root 17 7月   5 13:54 /etc/sysconfig/selinux -> ../selinux/config

3)-d 显示目录的详细信息

[root@localhost ~]# ls -ldh /dev/
drwxr-xr-x. 20 root root 3.3K 7月   6 08:58 /dev/[root@localhost ~]# ls -ldh /etc/sysconfig/
drwxr-xr-x. 6 root root 4.0K 7月   5 14:03 /etc/sysconfig/

4)-S 按文件大小排序

[root@localhost ~]# ls -lSh /boot/
总用量 124M
-rw-------. 1 root root  77M 7月   5 14:00 initramfs-0-rescue-d54fe4be6b674b079972696d39457a41.img
-rw-------. 1 root root  31M 7月   5 14:03 initramfs-3.10.0-1160.el7.x86_64.img
-rwxr-xr-x. 1 root root 6.5M 7月   5 14:00 vmlinuz-0-rescue-d54fe4be6b674b079972696d39457a41

5)-t 按文件修改时间排序

[root@localhost ~]# ls -lt /boot/
总用量 126324
drwx------. 5 root root       97 7月   5 14:03 grub2
-rw-------. 1 root root 31985984 7月   5 14:03 initramfs-3.10.0-1160.el7.x86_64.img

6)-a 查看所有文件(隐藏文件)

[root@localhost ~]# ls -a
  • .开头的文件为隐藏文件

三、创建目录

# mkdir 目录名称

[root@localhost ~]# mkdir /opt/work

[root@localhost ~]# mkdir -p /opt/linux/python [root@localhost ~]# ls /opt/ linux rh work [root@localhost ~]# ls /opt/linux/ python [root@localhost ~]# mkdir -pv /opt/A/B/C mkdir: 已创建目录 "/opt/A" mkdir: 已创建目录 "/opt/A/B" mkdir: 已创建目录 "/opt/A/B/C"

  • -p 递归创建目录

四、创建空白文件

# touch 文件名称

[root@localhost ~]# touch /opt/file01.mp3
[root@localhost ~]# ls /opt/
A  file01.mp3  linux  rh  work
[root@localhost ~]# ls -l /opt/
总用量 0
drwxr-xr-x. 3 root root 15 7月   6 11:12 A
-rw-r--r--. 1 root root  0 7月   6 11:15 file01.mp3
drwxr-xr-x. 3 root root 20 7月   6 11:11 linux
drwxr-xr-x. 2 root root  6 10月 31 2018 rh
drwxr-xr-x. 2 root root  6 7月   6 11:09 work
[root@localhost ~]# 

大括号展开:

[root@localhost ~]# touch /opt/work/{1..100}.txt [root@localhost ~]# touch /opt/work/{2,4,6,8}.jpg [root@localhost ~]# touch /opt/work/{zhangsan,lisi,wangwu}

命令引用:

  • 调用命令的结果作为文件名称使用
  • $(命令)
[root@localhost ~]# mkdir /opt/linux/$(date +%F_%T)
[root@localhost ~]# ls /opt/linux/
2022-07-06_11:39:16  python
[root@localhost ~]# touch /opt/linux/$(openssl rand -hex 10)
[root@localhost ~]# ls /opt/linux/
02e5128ef1ce05fb7417 

查看时间

[root@localhost ~]# date
2022年 07月 06日 星期三 11:34:49 CST
[root@localhost ~]#
[root@localhost ~]# date +%Y
2022
[root@localhost ~]# date +%m
07
[root@localhost ~]# date +%d
06
[root@localhost ~]# date +%H
11
[root@localhost ~]# date +%M
36
[root@localhost ~]# date +%S
26
[root@localhost ~]# date +%F
2022-07-06
[root@localhost ~]# date +%T
11:36:58
[root@localhost ~]# date +%F_%T
2022-07-06_11:37:28

五、查看文件内容

cat/more/less/head/tail  文件名称 

1、cat 查看文件全部内容

[root@localhost ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
[root@localhost ~]# cat -n /etc/hosts1  127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain42 ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

查看Linux发行版本

[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

查看CPU的型号

[root@localhost ~]# cat /proc/cpuinfo
processor   : 0
vendor_id   : GenuineIntel
cpu family  : 6
model       : 78
model name  : Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz
stepping    : 3
microcode   : 0xcc
cpu MHz     : 2400.002
cache size  : 3072 KB
physical id : 0
siblings    : 1
core id     : 0
cpu cores   : 1
apicid      : 0
initial apicid  : 0
fpu     : yes
fpu_exception   : yes
cpuid level : 22
wp      : yes

查看CPU的数量

[root@localhost ~]# nproc
1

2、more/less 分页查看

[root@localhost ~]# more /usr/share/dict/words 
[root@localhost ~]# less /usr/share/dict/words 
  • 回车 按行查看
  • 空格 按页查看
  • q 退出

3、head/tail

  • 查看文件的前n行内容
  • 默认查看前10行
[root@localhost ~]# head -n 2 /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin[root@localhost ~]# head -n 1 /etc/passwd
root:x:0:0:root:/root:/bin/bash
[root@localhost ~]# head /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
  • tail

    • 查看文件后n行
    • 默认是10行
[root@localhost ~]# tail -n 3 /etc/passwd
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
martin:x:1000:1000:martin:/home/martin:/bin/bash
[root@localhost ~]# tail /etc/passwd
ntp:x:38:38::/etc/ntp:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
gnome-initial-setup:x:988:982::/run/gnome-initial-setup/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
martin:x:1000:1000:martin:/home/martin:/bin/bash

六、查看文件类型

[root@localhost ~]# file /etc/hosts
/etc/hosts: ASCII text
[root@localhost ~]# file /boot/vmlinuz-3.10.0-1160.el7.x86_64
/boot/vmlinuz-3.10.0-1160.el7.x86_64: Linux kernel x86 boot executable bzImage, version 3.10.0-1160.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) #1 , RO-rootFS, swap_dev 0x6, Normal VGA

七、统计文件的行数

[root@localhost ~]# wc -l /etc/hosts
2 /etc/hosts[root@localhost ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

八、管道符 |

  • 将前一条命令的结果,交给一条命令进行处理
[root@localhost ~]# head -n 3 /etc/passwd | tail -n 1
daemon:x:2:2:daemon:/sbin:/sbin/nologin
[root@localhost ~]# ls -lSh /boot/ | head -n 3
总用量 124M
-rw-------. 1 root root  77M 7月   5 14:00 initramfs-0-rescue-d54fe4be6b674b079972696d39457a41.img
-rw-------. 1 root root  31M 7月   5 14:03 initramfs-3.10.0-1160.el7.x86_64.img[root@localhost ~]# ls -lSh /boot/ | head -n 3 | tail -n 2
-rw-------. 1 root root  77M 7月   5 14:00 initramfs-0-rescue-d54fe4be6b674b079972696d39457a41.img
-rw-------. 1 root root  31M 7月   5 14:03 initramfs-3.10.0-1160.el7.x86_64.img
[root@localhost ~]# ifconfig ens33 | head -n 2 | tail -n 1inet 192.168.140.161  netmask 255.255.255.0  broadcast 192.168.140.255[root@localhost ~]# ifconfig ens33 | head -n 2 | tail -n 1 | awk '{print $2}'
192.168.140.161
  • awk

    • 按空白将某行内容分为多段,第1段使用$1表示,第2段使用$2表示,依次类推
[root@localhost ~]# ls -l /boot/ | sed '1d' | wc -l
  • sed'1d':删除第一行内容

九、删除文件、目录

# rm [选项] 文件或目录名称
[root@localhost ~]# rm /opt/work/8.jpg
rm:是否删除普通空文件 "/opt/work/8.jpg"?y  
[root@localhost ~]# rm /opt/work/*.txt 

1、-f 强制删除

[root@localhost ~]# rm -f /opt/work/*.txt 

2、-r 删除目录(三思而后行哦)

[root@localhost ~]# rm -rf /opt/linux/

十、复制文件目录

# cp 源文件 目的文件

1、复制文件

[root@localhost ~]# cp /etc/fstab  /tmp/

2、复制同时改名

[root@localhost ~]# cp /etc/hosts /tmp/hosts_16

3、复制目录 -选项

[root@localhost ~]# cp -r /opt/0629/ /tmp/

十一、移动文件目录

# mv  源文件   目的文件 

1、移动文件

[root@localhost ~]# mv /opt/file01.mp3  /root/ 

2、移动目录

[root@localhost ~]# mv /opt/work/  /tmp/

3、重命名

  • 同目录下移动文件,就是重命名
[root@localhost ~]# mv /root/file01.mp3  /root/file02.html
[root@localhost ~]# ls /root/
anaconda-ks.cfg  file02.html  initial-setup-ks.cfg 

3文件目目录管理(修改查找压缩)

一、vim编辑器

1、介绍

  • 修改文件内容
  • 特性
    • 模式化编辑器

      • 命令模式、插入模式、末行模式
  • 使用格式:

# vim 文件名称

[root@localhost ~]# cp /etc/passwd /tmp/

2、模式间的切换

  • 命令模式——>插入模式

    • a,i,o,O
  • 插入模式——>命令模式
    • ESC
  • 命令模式——>末行模式
    • 冒号:

3、末行模式

  • 保存退出

    • wq
  • 不保存
    • q!
  • 显示行号
    • set nu

4、命令模式

1)快速移动光标

  • h左 j下 k 上 l 右
  • $ 移动到行尾
  • ^ 移动到行首
  • 68gg 跳转到68行
  • shift + g 跳转到最后一行
  • gg 跳转到第一行

2)删除字符

  • x 删除单个字符
  • dw 删除词
  • dd 删除整行
    • 67dd
  • d$ 删除到行尾
  • d^ 删除到行首
  • dG 删除到文件最后一行

3)复制,粘贴

  • yy 复制整行
  • p 粘贴

4)剪切、粘贴

  • dd
  • p

5)撤销

  • u

6)搜索

  • /内容

    • n 向下查找
    • N 向上查找

二、命令别名

1、配置vim编辑器显示行号

# vim /etc/vimrcset nu 

2、命令别名

# alias  别名='命令'

临时生效

[root@localhost ~]# alias ips='ifconfig ens33 | head -n 2 | tail -n 1'

永久生效 /etc/bashrc

[root@localhost ~]# vim /etc/bashrc
alias ips='ifconfig ens33 | head -n 2 | tail -n 1'
alias guanji='init 0'//让系统重新读取bashrc文件内容
[root@localhost ~]# source /etc/bashrc

查看命令别名

[root@localhost ~]# alias
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias guanji='init 0'
alias ips='ifconfig ens33 | head -n 2 | tail -n 1'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

删除别名

# unalias 别名

三、文件压缩、解压缩/归档文件

1、文件压缩、解压缩

1)gzip         *.gz

压缩:

[root@localhost ~]# gzip /opt/a.txt
[root@localhost ~]# ls /opt/
0629  A  a.txt.gz  rh[root@localhost ~]# file /opt/a.txt.gz
/opt/a.txt.gz: gzip compressed data, was "a.txt", from Unix, last modified: Thu Jul  7 13:39:53 2022

解压缩:

[root@localhost ~]# gzip -d /opt/a.txt.gz 

2)bzip2         *.bz2

压缩:

[root@localhost ~]# bzip2 /opt/b.txt
[root@localhost ~]# ls /opt/
0629  A  a.txt  b.txt.bz2  rh
[root@localhost ~]#
[root@localhost ~]# file /opt/b.txt.bz2
/opt/b.txt.bz2: bzip2 compressed data, block size = 900k

解压缩:

[root@localhost ~]# bzip2 -d /opt/b.txt.bz2 

3)xz         *xz

压缩:

[root@localhost ~]# xz /opt/c.txt
[root@localhost ~]# ls /opt/
0629  A  a.txt  b.txt  c.txt.xz  rh
[root@localhost ~]#
[root@localhost ~]# file /opt/c.txt.xz
/opt/c.txt.xz: XZ compressed data

解压缩:

[root@localhost ~]# xz -d /opt/c.txt.xz 

2、归档文件管理

1)创建归档文件        *.tar

# tar cf 归档文件名称  源文件 
  • c 创建
  • f 指定归档文件名称

将/etc目录所有文件打包到/backup/data.tar

[root@localhost ~]# tar cf /backup/data.tar   /etc/

2)创建归档文件,同时调用gzip压缩         *****.tar.gz

# tar czf 归档文件名称  源文件 
  • z 调用gzip压缩
  • 将/etc目录下所有文件打包压缩到/backup/etc01.tar.gz
[root@localhost ~]# tar czf /backup/etc01.tar.gz  /etc/

3)创建归档文件,同时调用bzip2压缩         *****.tar.bz2

[root@localhost ~]# tar cjf /backup/etc02.tar.bz2 /etc/

4)创建归档文件,同时调用xz压缩         *****.tar.xz

# tar cJf  归档文件名称   源文件 

将/etc目录下所有文件打包压缩到/backup/etc03.tar.xz

[root@localhost ~]# tar cJf /backup/etc03.tar.xz   /etc/

3、解压缩

# tar xf 归档文件名称 [-C 目录名称]

  • x 解压缩
  • -C 目录名称
    • 指定解压位置
[root@localhost ~]# tar xf /backup/etc01.tar.gz 
[root@localhost ~]# tar xf /backup/etc03.tar.xz -C /tmp/

四、查找文件 find

# find 目录名称 查找条件 [-exec 命令 \;]

  • 默认是在所有子目录下查找

1、查找条件

  • 按文件名称查找

    • -name
    • -iname  忽略大小写
[root@localhost ~]# find /opt/test/ -name "*.txt"
[root@localhost ~]# find /opt/test/ -name "*.txt" | wc -l
[root@localhost ~]# find /opt/test/ -iname "*.txt"
  • 按文件大小查找

    • -size
[root@localhost ~]# find /etc/ -size +2M
[root@localhost ~]# find /etc/ -size -2M
  • 按文件类型查找

    • -type(f,d,l)
[root@localhost ~]# find /etc/ -type l 
  • 按文件的创建时间

    • -ctime

[root@localhost ~]# find /etc/ -ctime +3    //3天前

[root@localhost ~]# find /etc/ -ctime -3   //最近3天

  • 按文件的修改时间

    • -mtime
[root@localhost ~]# find /etc/ -mtime -2 
[root@localhost ~]# find /etc/ -mtime +2 

2、按多条件查找

  • 并且 -a
[root@localhost ~]# find /etc/ -name "*.conf" -a -size +20k[root@localhost ~]# find /etc/ -mtime -3 -a -size +10k -a -name "*.conf" 
  • 或者 -o
[root@localhost ~]# find /etc/ -name "*.conf" -o -size +1M

3、-exec 命令 \;

  • 对查找的文件执行xxxxx操作
[root@localhost ~]# find /opt/test/ -name "*.mp3" -exec rm -rf {} \;
[root@localhost ~]# find /opt/test/ -name "*.jpg" -exec cp {} /tmp \;
[root@localhost ~]# find /etc/ -name "*.conf" -a -size +30k -exec ls -lh {} \;

4、-maxdepth 数字

  • 指定目录的层次
[root@localhost ~]# find /etc/ -maxdepth 2 -name "*.conf"

4文件目录管理(过滤、排序)

一、过滤/查看文件内容 grep

1、命令使用格式

# grep [选项] "pattern" 文件名称

  • pattern 条件、模式

    • 由普通文件、正则表达式组成的条件
[root@localhost ~]# grep "root" /etc/passwd [root@localhost ~]# grep "boot" /etc/fstab
UUID=d672e477-4028-4d42-9917-f6c45c631a46 /boot                   xfs     defaults        0 0[root@localhost ~]# ifconfig ens33 | grep "netmask"inet 192.168.140.161  netmask 255.255.255.0  broadcast 192.168.140.255[root@localhost ~]# grep "model name" /proc/cpuinfo 

2、正则表达式

  • 由一类特殊字符(元字符)组成的表达式
  • 匹配一类具有相同特征的文本

1)匹配单个字符

.        任意单个字符

[root@localhost ~]# grep "r..t" /etc/passwd
[root@localhost ~]# grep "F." /etc/passwd 

[ack]         任选其中一个,或者

[root@localhost ~]# grep "b[skt]" /etc/passwd
[root@localhost ~]# grep "[kPO]" /etc/passwd 

[a-z]         任意单个小写字母

[A-Z]         任意单个大写字母

[a-zA-Z]         任意单个字母

[0-9]         任意单个数字

[a-zA-Z0-9]         任意单个字母、或数字

[root@localhost ~]# grep "[A-Z]" /etc/passwd
[root@localhost ~]# grep "[A-Z][0-9]" /usr/share/dict/words 

[^a-z]         取反

[root@localhost ~]# grep "[^a-z]" /etc/fstab 

[[:space:]] 任意单个字符

[root@localhost ~]# grep "[[:space:]]" /etc/passwd

2)匹配字符出现的次数

* 匹配前一个字符出现任意次

.*

[root@localhost ~]# grep "a[0-9]*" /opt/file01 

\+ 匹配前一个字符至少出现1次

[root@localhost ~]# grep "a[0-9]\+" /opt/file01

\? 匹配前一个字符最多出现1次 可有可无

[root@localhost ~]# grep "a[0-9]\?" /opt/file01

\{3\} 匹配前一个字符精确出现3次 ab{3}

[root@localhost ~]# grep "a[0-9]\{2\}" /opt/file01

  • \{2,4\} 至少2次,最多4次

[root@localhost ~]# grep "a[0-9]\{2,5\}" /opt/file01

  • \{2, \} 至少2次

[root@localhost ~]# grep "a[0-9]\{2,\}" /opt/file01

3)分组 \(\)

  • 将多个字符作为一个整体来看

[root@localhost ~]# grep "\(ab\)\{2,\}" /usr/share/dict/words

4)匹配字符出现的位置

  • ^string

    • 以string开头
[root@localhost ~]# grep "^[rmk]" /etc/passwd     [root@localhost ~]# grep "^#" /etc/fstab
  • string$

    • 以string结尾
[root@localhost ~]# grep "bash$" /etc/passwd
  • ^$

    • 空行
[root@localhost ~]# grep "^$" /opt/file01 | wc -l

匹配IP:

[root@localhost ~]# grep "[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}" /opt/file02 

匹配邮箱:

[root@localhost ~]# grep "[a-zA-Z0-9_]\+@[a-z0-9]\+\.[a-z]\+" /opt/file02

匹配MAC地址:

[root@localhost ~]# ifconfig ens33 | grep "[0-9a-f]\{2\}:[0-9a-f]\{2\}:[0-9a-f]\{2\}:[0-9a-f]\{2\}:[0-9a-f]\{2\}:[0-9a-f]\{2\}"
[root@localhost ~]# ifconfig ens33 | grep "\([0-9a-f]\{2\}:\)\{5\}[0-9a-f]\{2\}"

3、常用选项

  • -o

    • 只显示符合条件的内容
[root@localhost ~]# grep -o "r..t" /etc/passwd
[root@localhost ~]# ifconfig ens33 | grep -o "\([0-9a-f]\{2\}:\)\{5\}[0-9a-f]\{2\}"
  • -i :忽略大小写
[root@localhost ~]# grep -i "^a" /opt/file01
  • -v :反向过滤,取反
[root@localhost ~]# grep -v "^#" /etc/fstab
  • -e :支持多条件过滤
[root@localhost ~]# grep -e "^#" -e "^UUID" /etc/fstab

-E:支持扩展正则表达式

[root@localhost ~]# grep -E "(ab){2,}" /usr/share/dict/words   

二、排序、去重

1、去重

# uniq 文件名称

[root@localhost ~]# uniq /opt/file03[root@localhost ~]# sort /opt/file03 | uniq

2、排序

[root@localhost ~]# sort -t: -k2 -n -r /opt/file04
  • 默认是按照ASCLL码表进行排序
  • -r :倒序,默认是升序
  • -n:按生活数字大小排序
  • -k:按每行的第几行进行排序(默认按照空白进行区分列)
  • -t:指定行分割符

三、统计文件、目录大小 du

1、统计文件大小

[root@localhost ~]# du -h /etc/passwd
4.0K    /etc/passwd[root@localhost ~]# du -h /boot/vmlinuz-3.10.0-1160.el7.x86_64
6.5M    /boot/vmlinuz-3.10.0-1160.el7.x86_64

2、统计目录大小

[root@localhost ~]# du -sh /boot/
140M    /boot/

3、统计所有文件大小

[root@localhost ~]# du -ah /boot/

查找/etc目录下最大的3个文件

[root@localhost ~]# du -a /etc/* | sort -k1 -n -r | head -n 3
23220   /etc/selinux
23212   /etc/selinux/targeted
17464   /etc/selinux/targeted/active
[root@localhost ~]# du -ah /etc/* | sort -k1 -h -r | head -n 3
23M /etc/selinux/targeted
23M /etc/selinux
18M /etc/selinux/targeted/active

云计算Linux运维——Linux系统管理——文件目录管理相关推荐

  1. 新开班全栈Linux运维-Linux云计算运维与高级架构班课程 全新自动化运维必学课程

    新开班全栈Linux运维-Linux云计算运维与高级架构班课程 全新自动化运维必学课程 全栈Linux运维的课程意义,在于让同学们从Liunx基础课程开始,一路直通Liunx运维高级架构师的级别.全新 ...

  2. 全栈Linux运维-Linux云计算运维与高级架构班课程 全新自动化运维必学课程

    全栈Linux运维-Linux云计算运维与高级架构班课程 全新自动化运维必学课程 全栈Linux运维的课程意义,在于让同学们从Liunx基础课程开始,一路直通Liunx运维高级架构师的级别.全新的Li ...

  3. Linux运维——文件系统管理

    文章目录 Linux运维--文件系统管理 一.硬盘结构 1.硬盘的逻辑结构 2.硬盘接口 二.文件系统 1.Linux文件系统的特性 2.Linux常见文件系统 三.常用的硬盘管理命令 1.df命令 ...

  4. Linux运维 Linux简介

    Linux运维 工作方向: • 产品经理 • 设计类方向(UI.UE) • 开发方向(PHP.Python.Java.C) • 运维方向(Linux.云计算) • 网络方向(思科.华为.华三) 运维方 ...

  5. 0基础linux运维,Linux运维基础

    字符匹配: . 匹配任意单个字符 [] 匹配指定范围内的任意单个字符 [^] 匹配指定范围外的任意单个字符 [:alnum:] 字母和数字 [:alpha:] 代表任何英文大小写字符,亦即 A-Z, ...

  6. 什么公司需要Linux运维,为什么企业会需要Linux运维?Linux入门!

    提及Linux,很多人或许都会疑惑Linux是什么?为什么企业需要Linux运维岗位?关于大家的疑问小编一一为大家解答. 什么是Linux? 在我们的日常生活当中,接触到最多的就是Windows操作系 ...

  7. alpine linux图形界面_跟光磊学Linux运维-Linux入门与基本使用

    认识Linux用户 在安装CentOS8.2时,设置过root用户的密码,同时也创建了用户guanglei. 其中root用户是系统自带的管理员账户,也被称为超级用户,root用户接近系统完整的控制能 ...

  8. 云计算Linux运维——Linux系统——软件管理

    点关注不迷路 目录 点关注不迷路 1RPM软件管理 1.软件安装包类型 2.RPM软件安装包的组成 二.RPM软件管理操作 rpm命令 1.安装软件 2.查看软件 3.卸载软件 2yum工具介绍 一. ...

  9. Linux运维篇之进程管理②

    一.HUP信号 当用户注销(logout)或者网络断开或者关闭终端时(一定是终端整体关闭,而不是单纯的exit)时,终端会收到Linux HUP信号,然后终端在结束前会关闭所有子进程. 如果我们想让进 ...

最新文章

  1. 浅谈边缘计算对企业安全建设的影响及趋势
  2. 极客新闻——17、给决定长久做程序员的你三个建议
  3. 仿苹果的导航,有点凹陷的感觉
  4. 知识产权创业的比赛结果
  5. 改变服务器控件的显示属性,2.6.1 设置Style特性和其他属性
  6. 【Virtual DOM】虚拟 DOM 和 Snabbdom 库
  7. 怎么样使用Badboy工具录制JMeter脚本
  8. ios h5 出现的问题
  9. Oracle 10G R2 让表常驻内存
  10. 【信号与系统|吴大正】1:信号与系统概述
  11. revit插件有哪些常用的?介绍几个常用的revit插件操作简单
  12. linux yast命令,Linux_SUSE Linux系统上双网卡绑定方法,1、使用yast工具配置第一块网 - phpStudy...
  13. 谷歌地图高清卫星地图
  14. http请求报400错误原因
  15. Browserslist: caniuse-lite is outdated. Please run: npx browserslist@latest --update-db
  16. html地图周边搜索,高德地图API实现定位、地点搜索和周边搜索(H5/Vue/微信小程序)...
  17. Linux服务器开发,手把手设计实现epoll
  18. python 比较运算符列表_python基础-列表,文件,运算符
  19. ATM纷纷办学来招生,为何互联网巨头都爱开大学?
  20. 百度地图JavaScript API获取用户当前经纬度和详细地理位置,反之通过详细地理位置获取当前经纬度...

热门文章

  1. 虹膜识别论文3:DeepIrisNet:IEEE 2016 学习心得
  2. 2023年场内基金怎么开户?开户流程?
  3. 基于Labview的环境噪声测量系统
  4. 开发学校一键打卡app(待完成)
  5. 中值滤波与高斯滤波的原理和应用场合
  6. 在x86_64平台搭建飞腾ARM交叉编译环境
  7. PPDE第二季度迎新 | 欢迎22位AI开发者加入飞桨开发者技术专家计划!
  8. 阿里云OS和android的关系
  9. 如何使用Python轻松解决TSP问题(PSO算法)
  10. 教大家使用大名鼎鼎的Ad Block Plus,屏蔽讨厌的广告