一、常规方式,touch

使用touch命令来创建一个空文件,或者多个文件。当文件存在时,只会修改文件的访问和修改时间,不会清空内容。

[root@centos7 a]#touch test01
[root@centos7 a]#ls
test01
[root@centos7 a]#touch test02 test03 test04
[root@centos7 a]#ls
test01  test02  test03  test0

批量创建

root@centos7 a]#touch test{001..050}
[root@centos7 a]#ls
test001  test007  test012  test018  test023  test029  test034  test04   test045
test002  test008  test013  test019  test024  test03   test035  test040  test046
test003  test009  test014  test02   test025  test030  test036  test041  test047
test004  test01   test015  test020  test026  test031  test037  test042  test048
test005  test010  test016  test021  test027  test032  test038  test043  test049
test006  test011  test017  test022  test028  test033  test039  test044  test050[root@centos7 a]#touch test{a..d}
[root@centos7 a]#ls
testa  testb  testc  testd

二、创建单个,vi&vim

使用vi&vim编辑器,输入内容并保存退出,来创建一个文件

vi test1   示例1
vim test2  示例2

:wq 保存退出

三、重定向, > &>>

使用重定向符号>创建一个空文件

[root@centos7 a]#> testb
[root@centos7 a]#ls
testa  testb

使用>创建文件,需要注意,当文件存在时,会清空文件内容,并且不会提示。

[root@centos7 a]#cat testa
1
2
3
4
[root@centos7 a]#> testa
[root@centos7 a]#cat testa
[root@centos7 a]#

>>>基本一致,区别在于>>是追加,不会清空内容。

四、重定向延伸,ll >

将此目录列出的结果,重定向到文件中,如果没有文件,就直接创建。

[root@centos7 a]#ll > testd
[root@centos7 a]#ll
total 8
-rw-r--r--. 1 root root   8 Feb 23 17:38 testa
-rw-r--r--. 1 root root   0 Feb 23 17:35 testb
-rw-r--r--. 1 root root   0 Feb 23 17:40 testc
-rw-r--r--. 1 root root 188 Feb 23 17:47 testd[root@centos7 a]#cat testd
total 8
-rw-r--r--. 1 root root 8 Feb 23 17:38 testa
-rw-r--r--. 1 root root 0 Feb 23 17:35 testb
-rw-r--r--. 1 root root 0 Feb 23 17:40 testc
-rw-r--r--. 1 root root 0 Feb 23 17:47 testd

五、重定向延伸,echo >

使用echo配合重定向>符号来创建一个空文件。

注意因为echo默认带换行符创建空文件时需要带-n选项

创建文件同时还可以输入内容,此时不用加-n。

[root@centos7 a]#echo "" >test1
[root@centos7 a]#ls
test1
[root@centos7 a]#cat test1[root@centos7 a]#
[root@centos7 a]#echo -n "" > testb
[root@centos7 a]#ls
test1  testb
[root@centos7 a]#cat testb[root@centos7 a]#echo  "hello" > testb
[root@centos7 a]#cat testb
hello

六、重定向延伸,cat >

/dev/null 是一个特殊的设备文件,这个文件接收到任何数据都会被丢弃,俗称“黑洞”

写入到它的内容都会被丢弃,如果尝试从该文件读取内容,那么什么也读取不到。

[root@centos7 a]#cat /dev/null > testa
[root@centos7 a]#ls
testa
[root@centos7 a]#cat testa

Linux创建文件的几种方式相关推荐

  1. Linux创建文件的四种方式

    Linux 创建文件 第一种 使用touch 创建a1文件 touch a1 第二种 使用vi 创建a2文件 vi a2 第三种 使用ls 创建文件 > 覆盖 >>追加 ls > ...

  2. Linux创建文件的5种方式

    1 touch touch指令,很常用的一种方法 1.1 创建一个文件 touch yyTest.ini 1.2 同时创建两个文件 touch test1.txt test2.txt 1.3 批量创建 ...

  3. Linux创建文件的五种方法,Linux创建文件的5种方式

    1 touch 1.1 创建一个文件 touch yyTest.ini 1.2 同时创建两个文件 touch test1.txt test2.txt 1.3 批量创建文件(如创建2000个文件) to ...

  4. linux 删除文件的几种方式

    linux 删除文件的几种方式 创建.删除和修改文件是用户在 Linux 系统中执行的非常常见操作.大家都知道,在 Linux 系统里使用 rm 命令删除单个文件时,几乎一瞬间就完成了.但是如果文件数 ...

  5. Java File.createNewFile 创建文件的四种方式小笔记

    本文为joshua317原创文章,转载请注明:转载自joshua317博客 Java File.createNewFile 创建文件的四种方式小笔记 - joshua317的博客 1.File(Str ...

  6. 创建文件的三种方式和一些操作方法

    package IO;import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException;/*** @ ...

  7. ubuntu创建文件的三种方式

    ubuntu下创建文件的三种方式 1.touch命令:touch 文件名.后缀 在当前工作目录底下新建一个文件,如 touch velocity_publisher.cpp 2.gedit命令:ged ...

  8. Linux创建文件的五种方法,Linux常用命令 - 五种创建文件命令详解

    21篇测试必备的Linux常用命令,每天敲一篇,每次敲三遍,每月一循环,全都可记住!! 创建文件,你知道有哪几个命令 ?(写出至少两种方式) 首先,touch 创建一个文件 touch yyTest. ...

  9. Linux 清空文件(6种方式)

    Linux 清空文件 文件外清空内容的shell命令(共5种): cat /dev/null > filenameecho "" > filenameecho > ...

最新文章

  1. 适合初学者的java书籍
  2. Git的工作区与暂存区
  3. EasyUC博客助手 [支持:博客园,MSN/Live空间,CSDN, 博客之家,PJBlog,Z-Blog...]
  4. PyTorch基础-猫狗分类实战-10
  5. mysql 5.74安装教程_MySQL安装、基本账户安全(5.0以后版本)
  6. 用Veritas制作MSI文件,Active Directory系列之二十四
  7. 基于Websocket草案10协议的升级及基于Netty的握手实现
  8. 谷歌查询mysql,谷歌地图:使用mysql查询更新标记不起作用
  9. SpringFramework核心技术一(IOC:命名bean)
  10. SaaS架构设计之高性能的Multi-Tenant最佳实践
  11. 开源ext2read代码走读之--“\\\\.\\PhysicalDrive0”意义?
  12. fsf大流行政治天网抗议监视
  13. 〖Python接口自动化测试实战篇⑦〗- 接口抓包工具 Fiddler 的使用
  14. Kotlin 元编程(注解,反射)
  15. swipe放大效果的焦点图demo
  16. UI设计师未来职业规划
  17. 看了第一句,有人就哭了?
  18. 【Rust 日报】2021-11-11 保持冷静,学习Rust,我们很快就会在Linux中更多的看到这种语言...
  19. 一款简洁的 image-crop.js图片裁剪工具
  20. JAVA梅森旋转随机算法_梅森旋转算法

热门文章

  1. Chrome浏览器背景颜色设置为豆沙绿保护色详细教程!
  2. 6-75 绘制多叶玫瑰线
  3. android横屏ui,换个角度看风景 手机产品UI设计之横屏模式(2)
  4. java的字典序排序_java字典序排序
  5. 轻量级java snmp设备网管软件开发技术
  6. ValueError: X has 2 features, but LogisticRegression is expecting 5 features as input.
  7. 配置 CentOS 7 man 命令帮助显示简体中文
  8. 手撸设计模式之-责任链模式
  9. 3d 角色血条制作方案:解决近大远小的策略
  10. C++中cout的格式使用