红帽学习笔记[RHCSA] 第二课[文件、目录、相关命令]
2024-10-03 04:17:27
第二课
常用的目录结构与用途
/ 根目录
/boot 存储的是系统起动时的信息和内核等
/dev 存储的是设备文件
/etc 存储的是系统的配置文件
/root 存储的是root用户的家目录
/home 存储的是普通用户的家目录
/mnt 存储的是自定义的挂在光盘或U盘
/var 存储的系统里经常变化的信息,比如日志
/tmp 存储的是临时文件
/bin 出处的是系统里的基本命令。普通用户就可以执行
/sbin 存储的是管理类的命令,root用户执行
/usr 存储的是应用程序文件,占用磁盘最大的
/proc 伪文件系统,几乎里面的东西全是内存中的数据,基本不占用磁盘空间。
本次课程涉及到的命令
cd
切换目录
# cd 什么都不加会切换到当前用户的家目录
[root@localhost /]# cd
[root@localhost ~]#
# cd ~ 同样的操作
[root@localhost /]# cd ~
[root@localhost ~]#
# cd -切换到上一次的目录
[root@localhost ~]# cd -
/
[root@localhost /]#
# cd . 当前目录
[root@localhost /]# cd .
[root@localhost /]#
# cd ..切换到上一级目录
[root@localhost test]# cd ..
[root@localhost /]#
pwd
显示当前所在目录
[root@localhost test]# pwd
/test
[root@localhost test]#
$LANG
临时切换语言环境
[root@localhost test]# LANG=zh_CN.UTF8
[root@localhost test]# aa
bash: aa: 未找到命令...
[root@localhost test]# LANG=zh_EN.UTF8
[root@localhost test]# aa
bash: aa: command not found...
touch
更新文件时间戳。
将文件的时间戳更新为当前的日期与时间,如果文件不出存在会创建文件
[root@localhost test]# touch 33.txt
[root@localhost test]#
[root@localhost test]# ls
11.txt 22.txt 33 33.txt 44
# 可以同时touch多个文件
[root@localhost test]# touch 11.txt 22.txt 33.txt 44.txt
[root@localhost test]# ls
11.txt 22.txt 33.txt 44.txt 55
# 关于同时创建多个文件的写法
# 创建100个文件 test1.mul 到 test100.mul
[root@localhost test]# touch test{1..100}.mul
# 创建26个文件 testa.mul 到 testz.mul
[root@localhost test]# touch test{a..z}.mul
# 创建两个文件 test_i.mul test_y.mul
[root@localhost test]# touch test{i,y}.nul
# ------------------------------------------------
# {}可以并列写多个,可以嵌套写,{..}表示一连串{,}表示并列。
cp
复制文件或者目录
[root@localhost test]# cp 11.txt /test1
[root@localhost test]# ls test1
ls: cannot access test1: No such file or directory
[root@localhost test]# ls /test1
11.txt
mv
移动文件,或重命名文件
# test文件夹下
[root@localhost test]# ls
11.txt 22.txt 33 33.txt 44
# 将22.txt移动到 /test1下
[root@localhost test]# mv 22.txt /test1
# 将33.txt重命名为44.txt
[root@localhost test]# mv 33.txt 44.txt
#查看test下结果
[root@localhost test]# ls
11.txt 33 44 44.txt
#查看test1下结果
[root@localhost test]# ls /test1
11.txt 22.txt
rm
删除文件或文件夹
# 查看test内容
[root@localhost test]# ls
11.txt 33 44 44.txt
# 删除11.txt 提示是否确认删除
[root@localhost test]# rm 11.txt
rm: remove regular file '11.txt'? y
# -f 强制删除44.txt,不提示是否删除
[root@localhost test]# rm -f 44.txt
# 删除33文件夹失败
[root@localhost test]# rm -f 33
rm: cannot remove '33': Is a directory
# -r 删除文件夹
[root@localhost test]# rm -rf 33
[root@localhost test]# ls
44
rmdir
删除空的文件夹
# 递归显示55文件夹下有文件 44是空的文件夹
[root@localhost test]# ls -R
.:
44 55
./44:
./55:
11.txt
# 删除空的44
[root@localhost test]# rmdir 44
# 删除非空55失败
[root@localhost test]# rmdir 55
rmdir: failed to remove '55': Directory not empty
ESC+.
使用上一个命令的最后一个参数
这是一个快捷键,使用是一条命令的最后一个参数
[root@localhost test]# ls 55
11.txt
# 下面这个 55 是通过ESC+.按出来的
[root@localhost test]# ls 55
clear
清空当前屏幕,但是不是真正的删除
# CTRL + L相同的作用
man
和 firefox file:///usr/share/doc/
查看帮助
# 查看 ls 命令的帮助
[root@localhost test]# man ls
# 用 火狐打开帮助文档
firefox file:///usr/share/doc/
最新文章
- Holographic Remoting Player
- NOIP201307货车运输
- unity3d 三分钟实现简单的赛车漂移
- XCODE UITextField 中的属性和用法
- 重构第16天 封装条件(Encapsulate Conditional)
- Modulo Sum(背包 + STL)
- java学习之动态代理模式
- JQuery Each循环遍历每个元素
- React .js框架的环境搭建
- Leetcode#500. Keyboard Row(键盘行)
- Mysql的学习笔记03
- CSS-背景-渐变-文本格式化
- Vue源码翻译之组件初始化。
- jinja模板语言
- 详细介绍C++STL:unordered_map
- gulp#4.0 Did you forget to signal async completion?
- 前端福利之jQuery文字轮播特效(转)
- 【微信小程序】再次授权地理位置getLocation+openSetting使用
- OpenCV-Python 视频读取
- LUA速成教程