Domin1c0's Blog

A technical blog sharing my journey in programming, development, and open source.

View on GitHub
20 July 2025

ShellEnd

by

Shell 相关(续)

5. 用户权限、用户、用户组


5.1 chmod 修改文件权限

linux通过权限对文件进行控制,使用chmod命令可以修改文件相关的权限

#为file的所有者和所属组添加读写权限
chmod ug+wr file.txt 
#给file.txt文件设置 rw-rw-r--
chmod 664 file.txt

5.2 chown 修改文件所有者和所属组

sudo chown newowner file.txt
#两种方法均可
sudo chown newowner:newowner file.txt
sudo chown newowner.newowner file.txt

注意:普通用户需使用管理员用户权限执行该命令


5.3 chgrp 修改文件所属组

sudo chgrp newowner file.txt

6. find 命令


6.1 按文件名查询

使用参数:-name
命令使用方式:find 路径 -name "文件名"

#查询后缀为.c的文件
find /home -name "*.c"

6.2 按文件类型查询

使用参数:-type
命令使用方式:find 路径 -type "类型"
7种固定文件类型(其中普通文件类型用f表示,而非-)


6.3 按文件日期

#创建日期
-ctime -n/+n
#修改日期
-mtime -n/+n
#访问日期
-atime -n/+n

注:


6.4 按深度

使用参数:-maxdepth 命令使用方式:


6.5 高级查找

#查找指定目录下所有目录,并列出目录中文件的详细信息

find ./ type d -exec ls -l {}\

find ./ type d -ok ls -l {}\

find ./ type d | xargs ls -l {}\

7. grep 命令

命令使用方式grep -r(有目录) "查找的内容" 搜索的路径

#搜索当前目录下包含hello world字符串的文件

grep -r -n "hello world" ./ #显示行号

grep -r -i -n "HELLO world" ./ #忽略大小写查找

#find和grep命令结合使用
#先使用find命令查找文件,然后使用grep命令查找哪些文件包含某个字符串
find . -name "*.c" | xargs grep -n "main"

8. 软件安装和卸载


8.1 在线安装

#以安装sl为例
#软件安装
sudo apt install sl
#软件卸载
sudo apt remove sl
#更新软件列表
sudo apt update
#清理安装包
sudo apt clean

8.2 软件包安装

在ubuntu系统中必须有deb格式的安装包

#软件安装
sudo dpkg -i xxx.deb
#软件卸载
sudo dpkg -r sl

9. 压缩与解压缩


9.1 gzip 和 bzip2


9.2 tar 工具

tags: Linux - 基础指令