本文共 2166 字,大约阅读时间需要 7 分钟。
find
命令find
是一个强大的文件搜索工具,可用于在文件系统中查找符合特定条件的文件和目录。
基本用法
find /etc -name init
find / -name init???
使用通配符进行匹配。find / -size +2048000
搜索大小超过 2048000 字节的文件(1 GB)。find / -user leon
搜索所有者为 leon
的文件或文件夹。find / -group michael
搜索所属组为 michael
的文件或文件夹。find /etc -cmin -5
搜索 5 分钟内被修改过属性的文件和目录。find /etc -amin -5
搜索访问时间在 5 分钟内的文件和目录。find /etc -mmin -5
搜索 5 分钟内被修改过文件内容的文件和目录。find /etc -name init* -a -type f
搜索名为 init*
的文件(*
表示零或多个字符)。find /etc -name init* -exec ls -l {} \;
对匹配结果执行 ls -l
命令。高级用法
使用-exec
选项可执行外部命令。例如:find . -inum 31531 -exec rm {} \;
根据 i 节查找特定 inode,用于删除硬链接。locate
命令locate
命令用于快速定位文件或目录,支持文件夹搜索。
locate filename1
locate -i filename
忽略大小写匹配。which
, whereis
, whatis
, apropos
, --help
, help
, info
这些命令用于查询命令或文件的信息。
which ls
ls
的路径。whereis rm
返回 rm
的路径及相关帮助文档。whatis ls
显示命令的简要说明。apropos ls
显示与 ls
相关的配置文件说明。ls --help
显示命令选项说明。info ls
显示详细说明,类似于 man
。man
命令man
是查看文档的标准工具,支持分节浏览。
man ls
ls
的说明。man services
查看配置文件说明。man 5 passwd
查看 passwd
在第 5 部分的说明。man -k passwd
查看所有相关的 passwd
说明。grep
命令grep
用于在文本中搜索特定模式。
grep multiuser /etc/inittab
multiuser
字符串。grep -v ^# /etc/inittab
忽略以 #
开头的行。useradd
, passwd
useradd leon
添加用户 leon
。passwd leon
修改用户 leon
的密码。who
, w
who
显示当前登录用户信息。w
显示详细的系统状态信息。gzip
, bzip2
, tar
, zip
gzip
gzip boduo
压缩文件 boduo
,不保留源文件。gzip -d boduo.gz
解压文件 boduo.gz
。bzip2
bzip2 boduo
使用 bzip2 压缩文件,不保留源文件。bzip2 -k boduo
压缩文件,保留源文件。tar
tar -cvf japan.tar japan
打包文件 japan
到 japan.tar
。tar -zxvf japan.tar.gz
解压压缩的 japan.tar.gz
。zip
zip boduo.zip bodu
压缩文件或目录 bodu
到 boduo.zip
。write
, wall
, mail
write michael
向用户 michael
发送邮件。wall
向所有登录用户发送消息。mail michael
启动邮件客户端。ping
, ifconfig
, tracert
ping baidu.com
测试到 baidu.com
的网络延迟。ping -c 3 www.baidu.com
发送 3 个数据包。ifconfig eth0 192.168.0.1
设置网络接口 eth0
的 IP 地址。last
, lastlog
last
显示当前和过去登录的系统信息。lastlog
显示用户最后一次登录的详细信息。netstat
netstat
显示网络状态信息。netstat -tlun
查看本地监听端口。netstat -an
显示正在连接的服务和端口。mount
mkdir /mnt/cdrom
创建挂载点目录。mount -t iso9660 /dev/sr0 /mnt/cdrom
挂载 CD-ROM 到 /mnt/cdrom
。umount /dev/sr0
卸载 CD-ROM。注意事项
-exec
时需谨慎,避免误删重要文件。转载地址:http://khzfk.baihongyu.com/