Get the App
SLTechnology News&Howtos  ›  Servers  › 

The method of creating files by linux

Shulou Source: shulou.com Published: 2022-06-01 23:52:42 09月25日 Update

Editor to share with you the method of linux to create files, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Linux to create a file method: 1, use the touch method, code for [touch yy..]; 2, use vi and vim, code for [vi test.txt]; 3, use [>, >], code for [> test.ini]; 4, use cp to create a file; 5, use cat to create a file.

How linux creates a file:

1 、 touch

1.1 create a file

Touch yyTest.ini

1.2 create two files at the same time

Touch test1.txt test2.txt

1.3 create files in batches (e.g. 2000 files)

Touch test {0001..2000} .txt

1.4 change the file yyTest.ini time to the current time (yyTest.ini already exists)

Touch yyTest.ini

2. Vi and vim

Vi test.txtvim touch.txt

3. Use >, > >

3.1 >

Directly overwrite the original file without any hint

3.2 > >

Append to the end of the original file and will not overwrite the contents of the original file

3.3 create an empty file directly with >

> test.ini

3.4 ls create a file (write the result to a file)

Ls > test.inils > > test.ini

3.5 grep create a file (write the result to a file)

Ps-ef | grep java > test.inips-ef | grep java > > test.ini

3.6 echo create a file (write the result to a file)

Echo $PATH > test.iniecho $PATH > > test.ini

4. Create a file using cp

A file is created as long as the target file is a new file. For more information on cp commands, please see this blog post: https://www.cnblogs.com/poloyy/p/12514389.html

5. Create a file using cat

5.1 simple use >, > >

Cat > test.inicat > > test.ini

In fact, you also use > and > >, but the difference is that after typing the above command, you will enter the editing mode of test.ini. You can enter the content you want to write directly, and finally press ctrl+z to exit the editing mode to save automatically.

5.2 cat combined with eof

Cat > > test.ini test.ini

Tags: File method content code article result command time mode input not much two at the same time size most more end goal knowledge industry Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft NVidia OPPO Reno vpn Apple