How to create a file in Linux from terminal window

2019-01-15 23:59发布

What's the easiest way to create a file in Linux terminal?

15条回答
霸刀☆藐视天下
2楼-- · 2019-01-16 00:16

Use touch

touch filename
查看更多
再贱就再见
3楼-- · 2019-01-16 00:17

haha! it's easy! try this:

$ touch filename
查看更多
爱情/是我丢掉的垃圾
4楼-- · 2019-01-16 00:17
touch filename

for permission denied error use sudo command as:

sudo touch filename
查看更多
甜甜的少女心
5楼-- · 2019-01-16 00:19

How to create a text file on Linux:

  • Using touch to create a text file: $ touch NewFile.txt
  • Using cat to create a new file: $ 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.
  • Simply using > to create a text file: $ > NewFile.txt
  • Lastly, we can use any text editor name and then create the file, such as:
    nano MyNewFile vi MyNewFile NameOfTheEditor NewFileName
查看更多
我只想做你的唯一
6楼-- · 2019-01-16 00:22

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. You have to create all non existent directories first, using the mkdir /path/to/dir command.

查看更多
Lonely孤独者°
7楼-- · 2019-01-16 00:24

I like the nano command-line editor (text):

nano filename
查看更多
登录 后发表回答