本文翻译自:How to create a file in Linux from terminal window?

在Linux终端中创建文件最简单的方法是什么?


#1楼

参考:https://stackoom.com/question/dMXv/如何在终端窗口中在Linux中创建文件


#2楼

In case you guys are trying to create a new file, but it says: 'File does not exist' , it's simply because you are also accessing a directory, which does not exist yet. 如果你们正在尝试创建一个新文件,但它说: 'File does not exist' ,这只是因为你也在访问一个目前尚不存在的目录。 You have to create all non existent directories first, using the mkdir /path/to/dir command. 您必须首先使用mkdir /path/to/dir命令创建所有不存在的目录。


#3楼

这将创建一个包含当前时间戳的空文件

touch filename

#4楼

我喜欢nano命令行编辑器(文本):

nano filename

#5楼

You can use touch command, as the others said: 您可以使用touch命令,其他人说:

touch filename

To write on file on command line, you can use echo or printf : 要在命令行上写入文件,可以使用echoprintf

echo "Foo" > filename
printf "Foo" > filename

Maybe you can have problems with permissions. 也许你可以遇到权限问题。 If you are getting the following error: bash: filename: Permission denied , you need to use sudo bash -c 'echo "Foo" > filename' , as described here: https://askubuntu.com/questions/103643/cannot-echo-hello-x-txt-even-with-sudo 如果您收到以下错误: bash: filename: Permission denied ,您需要使用sudo bash -c 'echo "Foo" > filename' ,如下所述: https : //askubuntu.com/questions/103643/cannot-呼应问候-X-TXT偶数与-须藤


#6楼

How to create a text file on Linux: 如何在Linux上创建文本文件:

  • Using touch to create a text file: $ touch NewFile.txt 使用touch创建文本文件: $ touch NewFile.txt
  • Using cat to create a new file: $ cat NewFile.txt 使用cat创建一个新文件: $ cat NewFile.txt
    The file is created, but it's empty and still waiting for the input from the user. 该文件已创建,但它是空的,仍在等待用户的输入。 You can type any text into the terminal, and once done CTRL-D will close it, or CTRL-C will escape you out. 您可以在终端中输入任何文本,一旦完成,CTRL-D将关闭它,或者CTRL-C将使您逃脱。
  • Simply using > to create a text file: $ > NewFile.txt 只需使用>创建一个文本文件: $ > NewFile.txt
  • Lastly, we can use any text editor name and then create the file, such as: 最后,我们可以使用任何文本编辑器名称,然后创建文件,例如:
    nano MyNewFile vi MyNewFile NameOfTheEditor NewFileName

如何在终端窗口中在Linux中创建文件?相关推荐

  1. linux 函数 创建文件路径,linux中创建文件和文件夹的方法

    linux中创建文件和文件夹的方法 发布时间:2020-06-12 19:32:19 来源:亿速云 阅读:174 作者:鸽子 首先说一下touch 创建文件的命令,touch可以用于创建二进制文件,用 ...

  2. Linux中创建文件与文件夹

    一.创建文件夹 命令:mkdir 文件夹名 例: 一开始home目录下没有test文件夹,命令创建后生成 二.创建文件 命令:touch 文件名 例: 一开始test文件夹下没有boot.proper ...

  3. linux中对文件的权限设置以及作用

    一.通过权限的设置达到目录共享 在linux中通过对文件的权限设置可以充分对文件的 owner进行内容保护,也可以把内容分享给想要分享的用户.下面举例说明: 1.首先在root权限下创建一个组,三个用 ...

  4. Linux 中创建 USB 启动盘来拯救 Windows 用户

    WoeUSB 可以在 Linux 中制作 Windows 启动盘,并帮助你的朋友解锁他们罢工的机器. 人们经常要求我帮助他们恢复被锁死或损坏的 Windows 电脑.有时,我可以使用 Linux US ...

  5. 启动盘Linux windows,Linux 中创建 USB 启动盘来拯救 Windows 用户

    人们经常要求我帮助他们恢复被锁死或损坏的 Windows 电脑.有时,我可以使用 Linux USB 启动盘来挂载 Windows 分区,然后从损坏的系统中传输和备份文件. 有的时候,客户丢失了他们的 ...

  6. linux usb 重启电脑,技术|如何在 Linux 中创建 USB 启动盘来拯救 Windows 用户

    WoeUSB 可以在 Linux 中制作 Windows 启动盘,并帮助你的朋友解锁他们罢工的机器. 人们经常要求我帮助他们恢复被锁死或损坏的 Windows 电脑.有时,我可以使用 Linux US ...

  7. linux怎样自动检查link文件_怎样理解和识别 Linux 中的文件类型 | Linux 中国

    众所周知,在 Linux 中一切皆为文件,包括硬盘和显卡等.在 Linux 中导航时,大部分的文件都是普通文件和目录文件.但是也有其他的类型,对应于 5 类不同的作用.因此,理解 Linux 中的文件 ...

  8. Linux中的文件权限

    在linux中的每个用户必须属于一个组,不能独立于组外.在linux中每个文件有所有者.所在组.其它组的概念.通常文件是谁创建的,那么所有者就是谁. 在终端输入ls -ahl查看文件的信息 drwxr ...

  9. linux创建分区_在Linux中创建分区-分步指南

    linux创建分区 In this tutorial, we'll be covering the steps to create a partition in Linux. This can hel ...

最新文章

  1. python实现文件下载-python实现文件下载的方法总结
  2. [LeetCode] Remove Duplicates from Sorted Array II
  3. STL:priority_queue
  4. 【AI视野·今日Robot 机器人论文速览 第二十四期】Thu, 30 Sep 2021
  5. 树形控件显示数据库数据项
  6. 数据库的跨平台设计(转)
  7. mysql show命令用不了_MySQL show命令的用法
  8. 学习信号与系统的看过来~~
  9. IEEE论文latex模板
  10. 说说全栈工程师有什么发展前景?
  11. Spatial Join学习
  12. 最好的投资是投资自己:20本投资书单推荐
  13. idea打包meven镜像_docker打包maven项目推送到阿里云镜像仓库
  14. 终于放假咯~寒假规划
  15. android模拟win98中文版,Android模拟Win 98模拟器(Bochs)
  16. 林业行业上的调查规划设计资质办理管理办法
  17. java热敏打印机_用java在POS热敏打印机上打印PDF或PNG
  18. 解决xcode doesn‘t support iphone’s ios 14.6 (18f72)
  19. ecshop 服务器操作系统,ecshop 云服务器
  20. module xxx missing dependencies

热门文章

  1. 7.EVE-NG硬盘扩容,存储海量镜像
  2. 1503171912-ny-一道水题
  3. java打包成jar文件
  4. 错误3:系统找不到指定的路径
  5. H.264的三种开源编码器比较
  6. bosboot -a的作用
  7. Shell脚本修改Nginx upstream配置文件
  8. 数据结构上机实验:单链表操作
  9. iOS $99 刀 开发者证书的申请步骤
  10. Windows Mobile 中 Cellular Emulator 与 Device Emulator 连接不上的解决办法?