草庐IT

linux基础(3)--实用指令2(时间指令、搜索指令和压缩指令)

lyf-cnblogs 2023-03-28 原文

1 时间日期指令

1.1 date

date       显示当前时间

date +%Y    显示当前年份

date +%m    显示当前月份

date +%d     显示今天

date "+%Y -%m-%d %H:%M:%S"      显示年月日时分秒

date -s "2023-03-03 03:03:03"      设置时间为2023-03-03 03:03:03

[root@HSP01 ~]# date
2023年 03月 10日 星期五 09:15:33 CST
[root@HSP01 ~]# date +%m
03
[root@HSP01 ~]# date "+%Y -%m-%d %H:%M:%S" 
2023 -03-10 09:16:22

1.2 cal

显示日历

cal    显示当月日历

cal 年份    显示某一年日历

[root@HSP01 ~]# cal
      三月 2023     
日 一 二 三 四 五 六
          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

2 搜索查找指令

 2.1 find

从指定目录向下遍历所有目录查找指定文件。

find 指定目录 -name  指定文件      从指定目录向下遍历所有目录按名称查找指定文件

find 指定目录 -user  指定用户名          查找指定目录下指定用户的所有文件

find 指定目录 -size  文件大小            查找指定目录下符合大小所有文件(+n 大于n   -n 小于n  n 等于   单位:k,M或G)

[root@HSP01 ~]# find /home -name test      
/home/test
[root@HSP01 ~]# find /home -user sora
/home/sora
/home/sora/.bash_logout
/home/sora/.config
/home/sora/.config/abrt
/home/sora/.bash_history
/home/sora/.mozilla
/home/sora/.mozilla/plugins
/home/sora/.mozilla/extensions
/home/sora/.bashrc
/home/sora/.bash_profile
/home/sora/.cache
/home/sora/.cache/abrt
/home/sora/.cache/abrt/lastnotification
[root@HSP01 ~]# find /home -size +5M
/home/laffy/.cache/mozilla/firefox/ri8vp6vr.default-default/startupCache/scriptCache.bin

2.2 locate

locate可以实现快速定位文件路径,利用建立的路径系统可以在无需遍历整个系统的情况下快速查找文件。

locate  文件名

注:使用前先利用指令updatedb更新路径。

[root@HSP01 ~]# updatedb
[root@HSP01 ~]# locate Sora.PNG
/home/sora/Sora.PNG
/opt/tmp/home/sora/Sora.PNG

3 grep&|

grep :过滤查找。

管道符“|”:表示将前一个命令的处理结果输出传递给后面的命令处理。

grep -n 查找内容 文件    在文件中查找相关内容且显示行号

grep -i 查找内容 文件    在文件中查找相关内容且忽略大小写(无论大小写都会被查找出来)

[root@HSP01 test]# grep -n life /home/test/app.txt
4:With the quickening pace of urban life and ever-increasing pressure, people in growing numbers are suffering from either the physical or mental problems.
[root@HSP01 test]# grep -i it /home/test/app.txt 
It is a wonderful day!
wherever you are,it is no doubt that i will meet you.
With the quickening pace of urban life and ever-increasing pressure, people in growing numbers are suffering from either the physical or mental problems.
As the job market is getting gloomy and competition is becoming fierce, it is increasingly difficult for college undergraduates to find a decent job.

4 压缩解压指令

4.1 gzip&gunzip

gzip     压缩文件,不能用于文件夹

gunzip    解压文件,不能用于文件夹

4.2 zip&unzip

压缩或解压文件

zip  文件                  压缩文件

unzip 文件                 解压文件或文件夹

zip -r   压缩后文件名  文件夹              压缩文件夹

unzip -d  路径 文件                解压文件到指定路径

[root@HSP01 home]# ls
jack laffy murasame myroot sora test
[root@HSP01 home]# zip -r mytest.zip test
adding: test/ (stored 0%)
adding: test/A/ (stored 0%)
adding: test/A/hello.cpp (deflated 48%)
adding: test/A/B (deflated 26%)
adding: test/A/app.txt (deflated 26%)
adding: test/app.txt (deflated 38%)
[root@HSP01 home]# ls
jack laffy murasame myroot mytest.zip sora test


[root@HSP01 home]# unzip -d /home/sora/ /home/mytest.zip
Archive: /home/mytest.zip
creating: /home/sora/test/
creating: /home/sora/test/A/
inflating: /home/sora/test/A/hello.cpp
inflating: /home/sora/test/A/B
inflating: /home/sora/test/A/app.txt
inflating: /home/sora/test/app.txt
[root@HSP01 home]# ls sora
Sora.PNG test

有关linux基础(3)--实用指令2(时间指令、搜索指令和压缩指令)的更多相关文章

  1. ruby - 使用 RubyZip 生成 ZIP 文件时设置压缩级别 - 2

    我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看ruby​​zip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d

  2. ruby - 在 Ruby 中编写命令行实用程序 - 2

    我想用ruby​​编写一个小的命令行实用程序并将其作为gem分发。我知道安装后,Guard、Sass和Thor等某些gem可以从命令行自行运行。为了让gem像二进制文件一样可用,我需要在我的gemspec中指定什么。 最佳答案 Gem::Specification.newdo|s|...s.executable='name_of_executable'...endhttp://docs.rubygems.org/read/chapter/20 关于ruby-在Ruby中编写命令行实用程序

  3. ruby-on-rails - Ruby 检查日期时间是否为 iso8601 并保存 - 2

    我需要检查DateTime是否采用有效的ISO8601格式。喜欢:#iso8601?我检查了ruby​​是否有特定方法,但没有找到。目前我正在使用date.iso8601==date来检查这个。有什么好的方法吗?编辑解释我的环境,并改变问题的范围。因此,我的项目将使用jsapiFullCalendar,这就是我需要iso8601字符串格式的原因。我想知道更好或正确的方法是什么,以正确的格式将日期保存在数据库中,或者让ActiveRecord完成它们的工作并在我需要时间信息时对其进行操作。 最佳答案 我不太明白你的问题。我假设您想检查

  4. ruby-on-rails - 将 Ruby 中的日期/时间格式化为 YYYY-MM-DD HH :MM:SS - 2

    这个问题在这里已经有了答案:Railsformattingdate(4个答案)关闭4年前。我想格式化Time.Now函数以显示YYYY-MM-DDHH:MM:SS而不是:“2018-03-0909:47:19+0000”该函数需要放在时间中.现在功能。require‘roo’require‘roo-xls’require‘byebug’file_name=ARGV.first||“Template.xlsx”excel_file=Roo::Spreadsheet.open(“./#{file_name}“,extension::xlsx)xml=Nokogiri::XML::Build

  5. ruby-on-rails - Nokogiri:使用 XPath 搜索 <div> - 2

    我使用Nokogiri(Rubygem)css搜索寻找某些在我的html里面。看起来Nokogiri的css搜索不喜欢正则表达式。我想切换到Nokogiri的xpath搜索,因为这似乎支持搜索字符串中的正则表达式。如何在xpath搜索中实现下面提到的(伪)css搜索?require'rubygems'require'nokogiri'value=Nokogiri::HTML.parse(ABBlaCD3"HTML_END#my_blockisgivenmy_bl="1"#my_eqcorrespondstothisregexmy_eq="\/[0-9]+\/"#FIXMEThefoll

  6. ruby - 查找字符串中的内容类型(数字、日期、时间、字符串等) - 2

    我正在尝试解析一个CSV文件并使用SQL命令自动为其创建一个表。CSV中的第一行给出了列标题。但我需要推断每个列的类型。Ruby中是否有任何函数可以找到每个字段中内容的类型。例如,CSV行:"12012","Test","1233.22","12:21:22","10/10/2009"应该产生像这样的类型['integer','string','float','time','date']谢谢! 最佳答案 require'time'defto_something(str)if(num=Integer(str)rescueFloat(s

  7. postman接口测试工具-基础使用教程 - 2

    1.postman介绍Postman一款非常流行的API调试工具。其实,开发人员用的更多。因为测试人员做接口测试会有更多选择,例如Jmeter、soapUI等。不过,对于开发过程中去调试接口,Postman确实足够的简单方便,而且功能强大。2.下载安装官网地址:https://www.postman.com/下载完成后双击安装吧,安装过程极其简单,无需任何操作3.使用教程这里以百度为例,工具使用简单,填写URL地址即可发送请求,在下方查看响应结果和响应状态码常用方法都有支持请求方法:getpostputdeleteGet、Post、Put与Delete的作用get:请求方法一般是用于数据查询,

  8. 软件测试基础 - 2

    Ⅰ软件测试基础一、软件测试基础理论1、软件测试的必要性所有的产品或者服务上线都需要测试2、测试的发展过程3、什么是软件测试找bug,发现缺陷4、测试的定义使用人工或自动的手段来运行或者测试某个系统的过程。目的在于检测它是否满足规定的需求。弄清预期结果和实际结果的差别。5、测试的目的以最小的人力、物力和时间找出软件中潜在的错误和缺陷6、测试的原则28原则:20%的主要功能要重点测(eg:支付宝的支付功能,其他功能都是次要的)80%的错误存在于20%的代码中7、测试标准8、测试的基本要求功能测试性能测试安全性测试兼容性测试易用性测试外观界面测试可靠性测试二、质量模型衡量一个优秀软件的维度①功能性功

  9. ES基础入门 - 2

    ES一、简介1、ElasticStackES技术栈:ElasticSearch:存数据+搜索;QL;Kibana:Web可视化平台,分析。LogStash:日志收集,Log4j:产生日志;log.info(xxx)。。。。使用场景:metrics:指标监控…2、基本概念Index(索引)动词:保存(插入)名词:类似MySQL数据库,给数据Type(类型)已废弃,以前类似MySQL的表现在用索引对数据分类Document(文档)真正要保存的一个JSON数据{name:"tcx"}二、入门实战{"name":"DESKTOP-1TSVGKG","cluster_name":"elasticsear

  10. sql - 查询忽略时间戳日期的时间范围 - 2

    我正在尝试查询我的Rails数据库(Postgres)中的购买表,我想查询时间范围。例如,我想知道在所有日期的下午2点到3点之间进行了多少次购买。此表中有一个created_at列,但我不知道如何在不搜索特定日期的情况下完成此操作。我试过:Purchases.where("created_atBETWEEN?and?",Time.now-1.hour,Time.now)但这最终只会搜索今天与那些时间的日期。 最佳答案 您需要使用PostgreSQL'sdate_part/extractfunction从created_at中提取小时

随机推荐