We all know that we can use the mkdir command to create a new directory, but more often it would be more pleasant if we could directly create a file (ordinary file); in this way, we don’t have to open a special software to create text files, and then set the file name and save path. Here are some methods to create files directly in the Linux terminal. Method 1 We can use the dd command to create a file of a specific size, which is stored in the directory /bin. The dd command copies the given input and then writes an identical copy to the output. Standard input, ordinary files, and device files can all be used as input; standard output, device files, ordinary files, etc. can be used as output. The usage format of the dd command is: dd if=... of=... bs=... count=... if indicates input file, of indicates output file, bs specifies the block size in bytes by default (the units are byte c, word w, block B, kilobyte m, megabyte m, gigabyte G), and count indicates the number of blocks to be copied; For example: create a 1024-byte file with all contents of 0 (empty); /dev/zero is a device file that can provide a null character (\0) and can be used to generate an empty file of a specific size. If bs=2048, count=2, then a file with a size of 4096 bytes is created. If if is not specified, dd will read input from standard input. If of is not specified, dd will use standard output stdout as output. Be careful when using dd as root. If you accidentally clear or damage important files or devices, it will cause irreparable trouble. Method 2 We can also use the touch command to generate a blank file. This command is simpler to operate and is generally located in the /usr/bin directory: touch uses a non-existent file name as a parameter to create a blank file. The format is: touch filename; such as: Of course, some friends may say that they can also use the command vi/vim. This is because I emphasized that it is to create a normal file, and vi/vim, as an editor, emphasizes more on editing. After we create a file, we can use the vi editor, vi filenmae, and then enter the insert mode to edit the content. Finally, press :wq to exit and save. Note that the above file name can be in any format, it can be a text file (txt), or a c, c++ file, etc. The file suffix depends on the content and function of your file. The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: MySQL scheduled database backup operation example
>>: Vue implements QR code scanning function (with style)
Dividing lines are a common type of design on web...
Preface This article aims to explain the most bor...
Table of contents 1. Basic principles 2. Specific...
The method of using CSS style to vertically cente...
Click here to return to the 123WORDPRESS.COM HTML ...
MySQL 5.7.8 and later began to support a native J...
Introduction to NFS NFS (Network File System) is ...
The general way of writing is as follows: XML/HTM...
A word in advance: Suddenly I received a task to ...
<br />From the launch of NetEase's new h...
What is CN2 line? CN2 stands for China Telecom Ne...
In combination with the scenario in this article,...
Table of contents 1. The principle of index push-...
Sometimes we may need to operate servers in batch...
Glass Windows What we are going to achieve today ...