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)
1. What is the cardinality? Cardinality refers to...
Today we are going to implement a Thunder Fighter...
1.What is margin? Margin is used to control the sp...
This article shares the specific code of js to im...
background When you open the product details on s...
When I used g++ to compile the cpp file for the f...
1. Download the pip installation package accordin...
Preface Linux's file permission management is...
question Nginx takes $remote_addr as the real IP ...
URL rewriting helps determine the preferred domai...
0x0 Parameter verification Most of the parameter ...
Preface In front-end development, we often encoun...
In the previous article, we played with timeouts ...
I recently added a very simple color scheme (them...
nginx Nginx (engine x) is a high-performance HTTP...