成为大佬之路--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]# 
相关推荐
UVM_ERROR3 分钟前
UVM实战:RDMA Host侧激励开发全流程问题排查与解决
服务器·网络·数据库
福尔摩斯张10 分钟前
插件式架构:解耦与扩展的艺术与实践(超详细)
linux·服务器·网络·网络协议·tcp/ip
txzz888820 分钟前
CentOS-Stream-10 搭建YUM源Web服务器
linux·运维·centos·yum源·linux系统更新·centos系统更新·自建web yum源
Molesidy30 分钟前
【Linux】基于Imx6ull Pro开发板和platform_device+platform_driver框架的LED驱动设计以及上机测试
linux·驱动开发
我科绝伦(Huanhuan Zhou)1 小时前
Linux系统硬件时钟与系统时钟深度解析及同步实操指南
linux·运维·服务器
k***92161 小时前
【Linux】进程概念(六):地址空间核心机制
linux·运维·算法
李白同学1 小时前
Linux:调试器-gdb/cgdb使用
linux·服务器·c语言·c++
保持低旋律节奏1 小时前
linux——进程调度(时间片+优先级轮转调度算法O(1))
linux·运维·算法
少年、潜行1 小时前
F1C100/200S学习笔记(3)-- 裸机开发
linux·笔记·学习·驱动·裸机·f1c200s
老王熬夜敲代码1 小时前
网路编程--协议
linux·网络·笔记