成为大佬之路--linux软件安装使用第000000040篇-linux操作文件和文件夹常用命令

1.创建文件

touch 文件名

下面命令创建了AscendKing.txt文件

然后过滤只要包含AscendKing的文件和文件夹

复制代码
[root@VM-24-14-centos opt]# touch AscendKing.txt
[root@VM-24-14-centos opt]# ls -l AscendKing*
-rw-r--r-- 1 root root 0 7月  31 23:13 AscendKing.txt
[root@VM-24-14-centos opt]# 

2.创建文件夹

mkdir 文件夹名称

下面示例演示了创建"AscendKing1"文件夹

复制代码
[root@VM-24-14-centos opt]# mkdir  AscendKing1
[root@VM-24-14-centos opt]# ls -l AscendKing*
-rw-r--r-- 1 root root    0 7月  31 23:13 AscendKing.txt

AscendKing1:
总用量 0

AscendKing9:
总用量 0
[root@VM-24-14-centos opt]# 

3.创建多级文件夹(级联创建)

mkdir -p 多级文件目录

复制代码
[root@VM-24-14-centos AscendKing]# pwd
/opt/AscendKing
[root@VM-24-14-centos AscendKing]# mkdir -p ./AscendKing-test1/AscendKing-test2/AscendKing-test3
[root@VM-24-14-centos AscendKing]# ls
AscendKing-test1
[root@VM-24-14-centos AscendKing]# cd AscendKing-test1/
[root@VM-24-14-centos AscendKing-test1]# ls
AscendKing-test2
[root@VM-24-14-centos AscendKing-test1]# cd AscendKing-test2/
[root@VM-24-14-centos AscendKing-test1]# ls
AscendKing-test3
[root@VM-24-14-centos AscendKing-test2]# cd AscendKing-test3/
[root@VM-24-14-centos AscendKing-test3]# 

4.复制文件

cp 需要复制的文件 新地址

cp -i强制询问是否覆盖

cp可以使用通配符

cp -R 可以递归复制,可以用来复制目录

复制代码
[root@VM-24-14-centos AscendKing]# touch test.txt
[root@VM-24-14-centos AscendKing]# cp test.txt  test.txt 
cp: 'test.txt' 与'test.txt' 为同一文件
[root@VM-24-14-centos AscendKing]# cp test.txt  test2.txt 
[root@VM-24-14-centos AscendKing]# cp test.txt  -i test2.txt 
cp:是否覆盖'test2.txt'? 
[root@VM-24-14-centos AscendKing]# 

5.移动文件(重命名)

mv 需要复制的文件 新地址

复制代码
[root@VM-24-14-centos AscendKing]# ls
AscendKing-test1  test2.txt  test.txt
[root@VM-24-14-centos AscendKing]# mv test.txt test3.txt
[root@VM-24-14-centos AscendKing]# ls
AscendKing-test1  test2.txt  test3.txt
[root@VM-24-14-centos AscendKing]# 

6.删除文件

rm 文件名

示例

复制代码
[root@VM-24-14-centos AscendKing]# ls
AscendKing-test1  test2.txt  test3.txt
[root@VM-24-14-centos AscendKing]# rm -rf ./*.txt
[root@VM-24-14-centos AscendKing]# 

7.删除文件夹

方式1:使用rm

方式2:使用rmdir

复制代码
[root@VM-24-14-centos AscendKing]# ls
AscendKing-test1
[root@VM-24-14-centos AscendKing]# mkdir test
[root@VM-24-14-centos AscendKing]# ls
AscendKing-test1  test
[root@VM-24-14-centos AscendKing]# rmdir test
[root@VM-24-14-centos AscendKing]# ls
AscendKing-test1

8.查看文件类型

file 文件

复制代码
[root@VM-24-14-centos AscendKing]# ls
AscendKing-test1  test
[root@VM-24-14-centos AscendKing]# file AscendKing-test1/
AscendKing-test1/: directory
[root@VM-24-14-centos AscendKing]# touch test.txt
[root@VM-24-14-centos AscendKing]# file test.txt 
test.txt: empty
[root@VM-24-14-centos AscendKing]# vim test.txt 
[root@VM-24-14-centos AscendKing]# file test.txt 
test.txt: ASCII text

9.查看文件内容

9.1cat

cat 文件

cat -n 文件 显示所有行行号

cat -b 文件 只显示有文本的行号

cat -T 文件 不显示制表符

复制代码
[root@VM-24-14-centos AscendKing]# cat test.txt 
111
[root@VM-24-14-centos AscendKing]# 

9.2more

我的文件内容少,直接展示了全部,如果文件内容多直接enter继续阅读下面

复制代码
[root@VM-24-14-centos AscendKing]# more test.txt 
开水
第1行内容
第2行内容
第3行内容
第4行内容
第5行内容
第6行内容
结束
[root@VM-24-14-centos AscendKing]# 

9.3less

复制代码
[root@VM-24-14-centos AscendKing]# less test.txt 
开水
第1行内容
第2行内容
第3行内容
第4行内容
第5行内容
第6行内容
结束
[root@VM-24-14-centos AscendKing]# 

9.4查看文件最后几行tail

复制代码
[root@VM-24-14-centos AscendKing]# tail -5f test.txt
第3行内容
第4行内容
第5行内容
第6行内容
结束

9.5查看文件开头几行head

复制代码
[root@VM-24-14-centos AscendKing]# head -5 test.txt
开始
第1行内容
第2行内容
第3行内容
第4行内容
[root@VM-24-14-centos AscendKing]# 
相关推荐
曼巴UE521 分钟前
UE FString, FName ,FText 三者转换,再次学习,官方文档理解
服务器·前端·javascript
wanhengidc30 分钟前
云手机的存储空间可以灵活扩展吗?
运维·服务器·科技·智能手机·云计算
Danileaf_Guo1 小时前
256台H100服务器的RoCEv2无损与全互联算力网络建设方案
运维·服务器·网络
解压专家6661 小时前
怎么找书?怎么传输?在Kred里完成的全过程
运维·服务器·网络
OnlyEasyCode1 小时前
快速上手!查看、拷贝、编辑、远程连接Linux命令
linux·运维·服务器
dualven_in_csdn2 小时前
UDP广播接收小优化
linux·运维·服务器
Xの哲學2 小时前
Linux二层转发: 从数据包到网络之桥的深度解剖
linux·服务器·算法·架构·边缘计算
石像鬼₧魂石2 小时前
Termux ↔ Windows 靶机 反向连接实操命令清单
linux·windows·学习
yuguo.im2 小时前
Docker 两大基石:Namespace 和 Cgroups
运维·docker·容器