当前位置: 首页 > news >正文

Linux 基础(六)常用命令 - find locate which whereis gzip gunzip tar

find & locate & which & whereis & gzip & gunzip & tar

    • find
    • locate
    • which
    • whereis
    • gzip
    • gunzip
    • zip/unzip
    • tar

find

在指定目录下查找文件或目录

find --help
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]default path is the current directory; default expression is -print
expression may consist of: operators, options, tests, and actions:operators (decreasing precedence; -and is implicit where no others are given):( EXPR )   ! EXPR   -not EXPR   EXPR1 -a EXPR2   EXPR1 -and EXPR2EXPR1 -o EXPR2   EXPR1 -or EXPR2   EXPR1 , EXPR2positional options (always true): -daystart -follow -regextypenormal options (always true, specified before other expressions):-depth --help -maxdepth LEVELS -mindepth LEVELS -mount -noleaf--version -xautofs -xdev -ignore_readdir_race -noignore_readdir_racetests (N can be +N or -N or N): -amin N -anewer FILE -atime N -cmin N-cnewer FILE -ctime N -empty -false -fstype TYPE -gid N -group NAME-ilname PATTERN -iname PATTERN -inum N -iwholename PATTERN -iregex PATTERN-links N -lname PATTERN -mmin N -mtime N -name PATTERN -newer FILE-nouser -nogroup -path PATTERN -perm [-/]MODE -regex PATTERN-readable -writable -executable-wholename PATTERN -size N[bcwkMG] -true -type [bcdpflsD] -uid N-used N -user NAME -xtype [bcdpfls]-context CONTEXTactions: -delete -print0 -printf FORMAT -fprintf FILE FORMAT -print-fprint0 FILE -fprint FILE -ls -fls FILE -prune -quit-exec COMMAND ; -exec COMMAND {} + -ok COMMAND ;-execdir COMMAND ; -execdir COMMAND {} + -okdir COMMAND ;

find 目录(不指定目录,则以当前目录查找) 查找参数
最常用的查找参数是 tests 项下的

 -name-user-group
  • 如在当前目录下查找 abc.txt
find -name abc.txt
  • 通配符查询,在opt下模糊查找 tes*.txt
find /opt -name tes*.txt

locate

通过本地数据库并非实时搜索文件,定位文件,Linux系统会为每个文件建立路径对应的本地数据库。
只要完整路径中包含 关键字的都会找出来

基本语法

locate 文件(夹)

其相关文档

[root@test-centos ~]# locate --help
Usage: locate [OPTION]... [PATTERN]...
Search for entries in a mlocate database.-A, --all              only print entries that match all patterns-b, --basename         match only the base name of path names-c, --count            only print number of found entries-d, --database DBPATH  use DBPATH instead of default database (which is/var/lib/mlocate/mlocate.db)-e, --existing         only print entries for currently existing files-L, --follow           follow trailing symbolic links when checking fileexistence (default)-h, --help             print this help-i, --ignore-case      ignore case distinctions when matching patterns-l, --limit, -n LIMIT  limit output (or counting) to LIMIT entries-m, --mmap             ignored, for backward compatibility-P, --nofollow, -H     don't follow trailing symbolic links when checking fileexistence-0, --null             separate entries with NUL on output-S, --statistics       don't search for entries, print statistics about eachused database-q, --quiet            report no error messages about reading databases-r, --regexp REGEXP    search for basic regexp REGEXP instead of patterns--regex            patterns are extended regexps-s, --stdio            ignored, for backward compatibility-V, --version          print version information-w, --wholename        match whole path name (default)

但是这个数据库并不是实时更新的,可能最近添加的文件并未收录进去,也可能已经删除的文件没来得及移除;
默认是一周更新次,如果要修改这个频率,编辑 /etc/updatedb.conf,输入以下内容

DB_UPDATE_PERIOD="daily"

可选项为:

  • daily:每天更新一次
  • weekly:每周更新一次(默认值)
  • monthly:每月更新一次
  • never:禁止自动更新,需要手动运行updatedb命令来更新

若要立即同步,也可以手动执行命令 sudo updatedb

which

查找可执行文件。

基本语法

which 可执行文件名
which java

whereis

查找执行文件或命令相关的文件,其查询目录通常在系统标准目录
/usr
/etc
等等

基本语法

whereis 可执行文件名
whereis java

gzip

压缩或解压缩文件(默认,为压缩文件),不保留源文件,压缩多个文件时分别压缩成单个压缩文件

  • -d 参数 为解压

压缩

gzip filename

保留源文件压缩

gzip filname -c > 自定义压缩文件名

解压

gzip -d filename.gz

保留源文件解压

gzip -d filename.gz -c > 自定义文件名

gunzip

直接对gzip生成的压缩文件进行解压

解压

gunzip filename.gz

zip/unzip

同样是压缩,解压工具
但是zip可以压缩目录 -r,并且默认保留源文件,压缩多个文件默认生成到一个压缩文件

基本语法

  • 压缩文件 (-r 压缩文件夹)
zip [opts] 压缩文件名 源文件1 源文件2 ....
  • 解压 (-d 指定解压到哪个目录)
unzip [opts] 压缩文件名

tar

常用于打包,归档操作。同时可以通过 参数-z 结合 gzip 使用

基本语法

tar [opts] xx.tar.gz(如果不压缩,就tar) 要打包的文件/目录1 要打包的文件/目录2 ...

tar 命令是通过 参数来决定是打包还是解压的操作,常用参数如下

命令功能
-c打包成 tar文件
-f指定(压缩后/要解压)的文件名
-z进行 gzip 压缩或解压
-x解压 tar 文件,不包含解压 .gz
-C自定义解压到哪个目录,默认解压到当前目录下压缩文件名的目录
-v展示执行过程

还有很多参数,具体可以参考帮助文档;以下展示部分参数

tar --help[root@test-centos test]# tar --help
Usage: tar [OPTION...] [FILE]...
GNU `tar' saves many files together into a single tape or disk archive, and can
restore individual files from the archive.Examples:tar -cf archive.tar foo bar  # Create archive.tar from files foo and bar.tar -tvf archive.tar         # List all files in archive.tar verbosely.tar -xf archive.tar          # Extract all files from archive.tar.Main operation mode:-A, --catenate, --concatenate   append tar files to an archive-c, --create               create a new archive-d, --diff, --compare      find differences between archive and file system--delete               delete from the archive (not on mag tapes!)-r, --append               append files to the end of an archive-t, --list                 list the contents of an archive--test-label           test the archive volume label and exit-u, --update               only append files newer than copy in archive-x, --extract, --get       extract files from an archive
http://www.lryc.cn/news/120858.html

相关文章:

  • 【Ajax】回调地狱解决方法
  • 解决Vue根组件设置transition失效的问题
  • 【剑指 Offer 40】最小的k个数
  • vue3+vite在main.ts文件中引入./App.vue报错(./App.vue不是模块)
  • 【LeetCode】102. 二叉树的层序遍历、107. 二叉树的层序遍历 II
  • HTML详解连载(2)
  • qt事件系统源码-----定时器
  • 【Android】ViewBinding+DataBinding+MVVM新手快速上手
  • 生成式人工智能模型:提升营销分析用户体验
  • 【并发编程】无锁环形队列Disruptor并发框架使用
  • 【C语言】初阶指针详解
  • ElasticSearch:项目实战(1)
  • React 实现文件分片上传和下载
  • 2023.8.13
  • kvm not all arguments converted during string
  • JVM 基础
  • 智谷星图赵俊:让人才和区块链产业“双向奔赴”丨对话MVP
  • C# Equals()方法报错:NullReferenceException was unhandled
  • Linux下C语言调用libcurl库获取天气预报信息
  • “深入解析JVM:Java虚拟机原理和内部结构“
  • Arrays.asList() 返回的list不能add,remove
  • 命令执行漏洞
  • Hive 中 sort by 和 order by 的区别
  • 网络资源利用最大化:爬虫带宽优化解决方案
  • STDF - 基于 Svelte 和 Tailwind CSS 打造的移动 web UI 组件库,Svelte 生态里不可多得的优秀项目
  • C语言一些有趣的冷门知识
  • Oracle数据库审计
  • Node.js新手在哪儿找小项目练手?
  • 全国各城市-货物进出口总额和利用外资-外商直接投资额实际使用额(1999-2020年)
  • CentOS 7查看磁盘空间