Linux常用命令——压缩和解压、搜索、日期的操作

因为疫情原因工作出现了调整,后续可能常接触这些命令了,发现网上内容很难找到有一个能介绍所有命令的文章,所以这里整理了一些内容。

其他命令

用户以及用户组管理

压缩和解压、搜索、日期的操作

文件以及目录的操作

权限,线程、系统健康度、磁盘情况

命令汇总

作用命令示例
gzip压缩gzip 文件gzip mytest.txt
gunzip解压缩gunzip 文件.gzgunzip mytest.txt.gz
zip压缩zip [选项] XXX.zip 将要压缩的内容zip csdn1.zip csdn
unzip解压缩unzip [选项] XXX.zipunzip csdn1.zip -d /root/csdn
tar压缩tar [选项] XXX.tar.gztar -zcvf csdn.tar csdn
tar解压缩tar [选项] XXX.tar.gztar -zxvf csdn.tar
搜索文件find [搜索范围] [选项]find /usr/local/testing/confs -name *value2*
显示当前时间datedate
显示非当前时间date -d ‘1 days ago’date -d '1 days ago'
设置系统时间date -s 字符串时间date -s "2020-10-02 14:18:39"
查看日历cal [选项]cal 6 2021

压缩和解压

gzip/gunzip 压缩

只能压缩为gz类型的文件,也只能解压此类型的文件,操作之后不保存原文件

语法

gzip 文件		(功能描述:压缩文件,只能将文件压缩为*.gz文件)
gunzip 文件.gz	(功能描述:解压缩文件命令)

实际语句

# 压缩
gzip mytest.txt 
# 解压缩
gunzip mytest.txt.gz 

实际操作

创建一个mytest.txt文件然后进行压缩,然后对此文件进行解压缩

[root@iZbp1buyhgwtrw6hrp2ugjZ csdn]# touch mytest.txt
[root@iZbp1buyhgwtrw6hrp2ugjZ csdn]# ls
mytest.txt
[root@iZbp1buyhgwtrw6hrp2ugjZ csdn]# gzip mytest.txt 
[root@iZbp1buyhgwtrw6hrp2ugjZ csdn]# ls
mytest.txt.gz
[root@iZbp1buyhgwtrw6hrp2ugjZ csdn]# gunzip mytest.txt.gz 
[root@iZbp1buyhgwtrw6hrp2ugjZ csdn]# ls
mytest.txt

返回内容解释

zip/unzip 压缩

语法

zip  [选项] XXX.zip  将要压缩的内容 		(功能描述:压缩文件和目录的命令)
unzip [选项] XXX.zip						(功能描述:解压缩文件)

可选参数

选项功能
-r压缩目录
-d{目录}指定解压缩后存放目录

实际语句

# 压缩
zip csdn1.zip csdn
# 解压缩
unzip csdn1.zip -d /root/csdn

实际操作

将csdn目录压缩为csdn1.zip文件,并将文件解压多root/csdn的目录下

[root@iZbp1buyhgwtrw6hrp2ugjZ ~]# zip csdn1.zip csdn
  adding: csdn/ (stored 0%)
[root@iZbp1buyhgwtrw6hrp2ugjZ ~]# ls
a.out  csdn  csdn1.zip
[root@iZbp1buyhgwtrw6hrp2ugjZ ~]# unzip csdn1.zip -d /root/csdn
Archive:  csdn1.zip
   creating: /root/csdn/csdn/
[root@iZbp1buyhgwtrw6hrp2ugjZ ~]# cd csdn
[root@iZbp1buyhgwtrw6hrp2ugjZ csdn]# ls
csdn  mytest.txt
[root@iZbp1buyhgwtrw6hrp2ugjZ csdn]# 

tar 打包

语法

tar  [选项]  XXX.tar.gz  将要打包进去的内容		(功能描述:打包目录,压缩后的文件格式.tar.gz)

可选参数

选项功能
-ctar打包文件地址
-v压缩时详细信息
-f压缩后的文件名
-z打包同时压缩
-x解包.tar文件

实际语句

# 压缩
tar -zcvf csdn.tar csdn
houge.txt
# 解压到当前目录
tar -zxvf csdn.tar 

实际操作

首先压缩csdn文件,然后对其在当前目录进行解压

[root@iZbp1buyhgwtrw6hrp2ugjZ ~]# tar -zcvf csdn.tar csdn
csdn
[root@iZbp1buyhgwtrw6hrp2ugjZ ~]# ls
csdn  csdn.tar


# 当前目录解压
[root@iZbp1buyhgwtrw6hrp2ugjZ ~]# rm csdn
rm: remove regular file ‘csdn’? y
[root@iZbp1buyhgwtrw6hrp2ugjZ ~]# ls
csdn.tar
[root@iZbp1buyhgwtrw6hrp2ugjZ ~]# tar -zxvf csdn.tar 
csdn
[root@iZbp1buyhgwtrw6hrp2ugjZ ~]# ls
csdn  csdn.tar
[root@iZbp1buyhgwtrw6hrp2ugjZ ~]# 

搜索

查找文件或者目录

语法

find [搜索范围] [选项]

find的查询基于三种方式:根据指定的文件名称进行查询,查询用户的所有文件,根据文件大小进行查询。使用文件名称进行查询时比较常用的使用情况。

选项的查询

选项功能
-name<查询方式>按照指定的文件名进行文件查找
-user{用户名}查找属于指定用户名所有文件
-size{根据文件大小}根据大小查询文件

实际语句

# 寻找文件名中有value2的文件
[root@iZbp1buyhgwtrw6hrp2ugjZ testing]# find /usr/local/testing/confs -name *value2*
/usr/local/testing/confs/order_sale_sql_last_value2.yml


# 寻找root用户所属的文件
[root@iZbp1buyhgwtrw6hrp2ugjZ testing]# find /usr/local/testing/confs -user root
/usr/local/testing/confs
/usr/local/testing/confs/order_sale_sql_last_value.yml
/usr/local/testing/confs/order_sale_sql_last_value2.yml

日期处理

显示当前时间

语法

(1)date								(功能描述:显示当前时间)
(2)date +%Y							(功能描述:显示当前年份)
(3)date +%m							(功能描述:显示当前月份)
(4)date +%d							(功能描述:显示当前是哪一天)
(5)date "+%Y-%m-%d %H:%M:%S"		(功能描述:显示年月日时分秒)

实际语句

## 查询时间
[root@iZbp1buyhgwtrw6hrp2ugjZ confs]# date
Sat Oct  3 14:14:43 CST 2020
## 查询时间年份
[root@iZbp1buyhgwtrw6hrp2ugjZ confs]# date +%Y
2020
[root@iZbp1buyhgwtrw6hrp2ugjZ confs]# date "+%Y-%m-%d %H:%M:%S"
2020-10-03 14:14:56

显示非当前时间

语法

(1)date -d '1 days ago'			(功能描述:显示前一天时间)
(2)date -d '-1 days ago'			(功能描述:显示明天时间)

实际语句

## 查询前一天的时间,并且使用格式化显示
[root@iZbp1buyhgwtrw6hrp2ugjZ confs]# date -d '1 days ago'
Fri Oct  2 14:15:29 CST 2020
[root@iZbp1buyhgwtrw6hrp2ugjZ confs]# date -d '1 days ago' "+%Y-%m-%d %H:%M:%S"
2020-10-02 14:15:39

设置系统时间

语法

date -s 字符串时间

实际语句

date -s "2020-10-02 14:18:39" 

查看日历

语法

cal [选项]			(功能描述:不加选项,显示本月日历)

在选项中可以配置某一年来查看某一年的日历

实际语句

## 查看当前月份的日历
[root@iZbp1buyhgwtrw6hrp2ugjZ confs]# cal
    October 2020    
Su Mo Tu We Th Fr Sa
             1  2  3
 4  5  6  7  8  9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

## 查看2021年6月份的日历,去掉月份参数可以查看一整年的日历
[root@iZbp1buyhgwtrw6hrp2ugjZ confs]# cal 6 2021
      June 2021     
Su Mo Tu We Th Fr Sa
       1  2  3  4  5
 6  7  8  9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30


个人水平有限,上面的内容可能存在没有描述清楚或者错误的地方,假如开发同学发现了,请及时告知,我会第一时间修改相关内容。假如我的这篇内容对你有任何帮助的话,麻烦给我点一个赞。你的点赞就是我前进的动力。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Linux系统中,解压压缩文件有多种命令可以使用。对于压缩文件,常见的命令有: 1. ".zip"格式的压缩命令是使用"zip"命令,例如:zip 压缩文件名.zip 要压缩文件或目录。 2. ".gz"格式的压缩命令是使用"gzip"命令,例如:gzip 要压缩文件。 3. ".bz2"格式的压缩命令是使用"bzip2"命令,例如:bzip2 要压缩文件。 4. ".tar"格式的压缩命令是使用"tar"命令,例如:tar -cvf 压缩文件名.tar 要压缩文件或目录。 对于解压文件,常见的命令有: 1. ".zip"格式的解压缩命令是使用"unzip"命令,例如:unzip 压缩文件名.zip。 2. ".gz"格式的解压缩命令是使用"gunzip"命令,例如:gunzip 压缩文件。 3. ".bz2"格式的解压缩命令是使用"bunzip2"命令,例如:bunzip2 压缩文件。 4. ".tar"格式的解压缩命令是使用"tar"命令,例如:tar -xvf 压缩文件名.tar。 需要注意的是,压缩文件的扩展名对于Linux系统来说并不是必需的,但为了方便管理和操作,建议给压缩文件添加正确的扩展名。此外,Linux系统支持的压缩格式还有很多,如".7z"、".rar"等,具体的解压缩命令可以根据不同的格式进行调整。 #### 引用[.reference_title] - *1* *2* *3* [Linux常用命令——压缩解压缩命令](https://blog.csdn.net/m0_59868866/article/details/126237042)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大·风

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值