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

Linux之文件和目录类命令详解(2)

Linux之文件和目录类命令详解(2)

  • 1、mv-移动文件或重命名
  • 2、find-查找文件和目录
  • 3、locate-快速查找文件
  • 4、du-显示目录或文件的磁盘使用情况
  • 5、df-显示文件系统的磁盘空间使用情况
  • 6、chmod-更改文件或目录的权限
  • 7、chown-更改文件或目录的拥有者
  • 8、tree-以树状结构列出目录内容

1、mv-移动文件或重命名

1.1 基本用法:

##移动文件或目录,或者重命名文件。
mv source_file destination_file

1.2 常用选项:

-i:在目标文件已存在时提示确认
mv -i old_name new_name

1.3 实例

[root@test test]# ll
total 4
-rw-r--r-- 1 root root 8 Nov 10 18:41 a.txt
[root@test test]# mv a.txt b.txt
[root@test test]# ll
total 4
-rw-r--r-- 1 root root 8 Nov 10 18:41 b.txt##当前系统redhat7.9,执行mv默认带-i
[root@test test]# ll
total 8
-rw-r--r-- 1 root root 8 Nov 10 18:53 b.txt
-rw-r--r-- 1 root root 8 Nov 10 18:41 c.txt
[root@test test]# mv b.txt c.txt
mv: overwrite ‘c.txt’? n
[root@test test]# ll
total 8
-rw-r--r-- 1 root root 8 Nov 10 18:53 b.txt
-rw-r--r-- 1 root root 8 Nov 10 18:41 c.txt##若仅执行mv,则不会提示确认,直接更改
[root@test test]# \mv b.txt c.txt
[root@test test]# ll
total 4
-rw-r--r-- 1 root root 8 Nov 10 18:53 c.txt

2、find-查找文件和目录

2.1 基本用法

find /path/to/search -name filename

2.2 常用选项

-type f:仅查找文件-type d:仅查找目录-name pattern:根据文件名模式查找

2.3 实例

[root@test test]# find /root/test -type f -name "*.txt"
/root/test/c.txt
[root@test test]# find /root/ -type d -name "test"
/root/test

3、locate-快速查找文件

3.1 基本用法

locate filename

3.2 常用选项

-r:使用正则表达式实现精确匹配

3.3 实例

[root@test test]# locate c.txt
/root/test/c.txt
/usr/share/doc/alsa-lib-1.1.8/asoundrc.txt
/usr/share/doc/libreswan-3.25/opportunistic-v1.historic/opportunism-spec.txt
/usr/share/doc/python-kitchen-1.1.1/html/_sources/api-text-misc.txt
/usr/share/doc/qemu-kvm/qmp-spec.txt
/usr/share/doc/skkdic-20130104/edict_doc.txt
/usr/share/doc/vim-common-7.4.629/README_amisrc.txt
/usr/share/doc/vim-common-7.4.629/README_mac.txt
/usr/share/doc/vim-common-7.4.629/README_src.txt
/usr/share/vim/vim74/doc/arabic.txt.gz
/usr/share/vim/vim74/doc/os_mac.txt.gz
/usr/share/vim/vim74/doc/os_risc.txt.gz
/usr/share/vim/vim74/doc/pi_spec.txt.gz
/usr/share/vim/vim74/doc/usr_toc.txt.gz##使用正则表达式实现精确匹配
[root@test test]# locate -r '/c\.txt$'
/root/test/c.txt
[root@test test]#

4、du-显示目录或文件的磁盘使用情况

4.1 基本用法

du directory_name

4.2 常用选项

-h:以人类可读的格式显示(KB, MB, GB)
-s:显示总计而非每个文件的大小

4.3 实例

[root@test test]# ll
total 12
-rw-r--r-- 1 root root 8 Nov 10 19:10 a.txt
-rw-r--r-- 1 root root 8 Nov 10 19:10 b.txt
-rw-r--r-- 1 root root 8 Nov 10 18:53 c.txt
[root@test test]# du -h
12K     .
[root@test test]# du -h *
4.0K    a.txt
4.0K    b.txt
4.0K    c.txt
[root@test test]# du -s
12      .
[root@test test]# du -s *
4       a.txt
4       b.txt
4       c.txt
[root@test test]# du -sh
12K     .
[root@test test]# du -sh *
4.0K    a.txt
4.0K    b.txt
4.0K    c.txt

5、df-显示文件系统的磁盘空间使用情况

5.1 基本用法

df

5.2 常用选项

-h:以人类可读的格式显示

5.3 实例

[root@test test]# df -h
Filesystem             Size  Used Avail Use% Mounted on
devtmpfs               3.9G     0  3.9G   0% /dev
tmpfs                  3.9G     0  3.9G   0% /dev/shm
tmpfs                  3.9G   13M  3.9G   1% /run
tmpfs                  3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/mapper/rhel-root   26G  3.9G   23G  15% /
/dev/sda1             1014M  170M  845M  17% /boot
tmpfs                  797M   12K  797M   1% /run/user/42
tmpfs                  797M     0  797M   0% /run/user/0

6、chmod-更改文件或目录的权限

6.1 基本用法

chmod 755 filename

6.2 常用选项

+x:添加执行权限
-x:移除执行权限
r:读取权限
w:写入权限
x:执行权限

6.3 实例

[root@test test]# ll
total 4
-rw-r--r-- 1 root root 8 Nov 10 19:10 a.txt
[root@test test]# chmod u+x a.txt
[root@test test]# ll
total 4
-rwxr--r-- 1 root root 8 Nov 10 19:10 a.txt

7、chown-更改文件或目录的拥有者

7.1 基本用法

chown user:group filename

7.2 常用选项

-R:递归地更改目录及目录内所有文件的所有者和组

7.3 实例

[root@test test]# ll
total 4
-rwxr--r-- 1 root root 8 Nov 10 19:10 a.txt
[root@test test]# chown test:test a.txt
[root@test test]# ll
total 4
-rwxr--r-- 1 test test 8 Nov 10 19:10 a.txt##更改文件目录也一样,若果想更改文件目录及目录下所有文件的权限,可加-R参数
[root@test test]# chown -R test:test test/

8、tree-以树状结构列出目录内容

8.1 基本用法

##通常不是在某些Linux发行版中默认安装的,使用前需进行安装
tree /path/to/directory

8.2 实例

[root@test ~]# tree /root
/root
├── anaconda-ks.cfg
├── Desktop
├── Documents
├── Downloads
├── initial-setup-ks.cfg
├── Music
├── Pictures
├── Public
├── Templates
├── test
│   └── a.txt
└── Videos
http://www.lryc.cn/news/481688.html

相关文章:

  • NVR管理平台EasyNVR多品牌NVR管理工具/设备摄像头开启ONVIF的方法
  • Pr 视频过渡:沉浸式视频
  • SwiftUI开发教程系列 - 第1章:简介与环境配置
  • gitlab ci/cd搭建及使用笔记
  • Xcode 16 中 Swift Testing 的参数化(Parameterized)机制趣谈
  • Python自动化运维DevSecOps与安全自动化
  • 2024下半年系统架构师考试【回忆版】
  • UE5.4 PCG 自定义PCG蓝图节点
  • 迁移学习相关基础
  • 华为云计算HCIE-Cloud Computing V3.0试验考试北京考场经验分享
  • 数据分析——学习框架
  • 量化交易系统开发-实时行情自动化交易-3.4.2.Okex行情交易数据
  • pytorch实现深度神经网络DNN与卷积神经网络CNN
  • 芯片测试-LDO测试
  • 期权懂|期权新手看过来:看跌期权该如何交易?
  • 《深入浅出HTTPS​​​​​​​​》读书笔记(8):密码学Hash算法的分类
  • 大语言模型安全,到底是什么的安全
  • 论文2—《基于柔顺控制的智能神经导航手术机器人系统设计》文献阅读分析报告
  • 试编写算法将单链表就地逆置(默认是带头节 点,如果是不带头节点地逆置呢?)
  • FPGA学习笔记#3 Vitis HLS编程规范、数据类型、基本运算
  • 爬虫 - 二手交易电商平台数据采集 (一)
  • “成交量分布指标“,通过筹码精准锁定价格方向+简单找市场支撑压力位 MT4免费公式!
  • 简记Vue3(四)—— 路由
  • Python批量合并多个PDF
  • Linux:vim命令总结及环境配置
  • 贪心算法day05(k次取反后最大数组和 田径赛马)
  • 默认 iOS 设置使已锁定的 iPhone 容易受到攻击
  • 上海市计算机学会竞赛平台2024年11月月赛丙组
  • Python批量设置图片背景为透明
  • Vue CLI 脚手架