In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you the "Linux does not use the Linux command line editor to clean up or delete the contents of large files", the content is easy to understand, well-organized, hope to help you solve your doubts, the following let the editor lead you to study and learn "Linux how to use the Linux command line editor to clean or delete the contents of large files" this article.
Note: since everything is a file in Linux, you need to be careful at all times to make sure that the file you are about to empty is not an important user file or system file. Emptying important system files or configuration files can cause serious application failures or system errors.
* * Tip: * * in the following example, we will use a file named access.log as a sample.
1. Clear the contents of the file by redirecting to Null
The easiest way to empty or make a file blank is to redirect null (things that don't exist) to the file through shell as follows:
# > access.log
two。 Use the 'true' command redirect to empty the file
Next we will use the: symbol, which is a built-in command for shell, which is equivalent to the true command, and can be used as a no-op (that is, to do nothing). Another way to empty a file is to redirect the output of: or true built-in commands to a file, as follows:
#: > access.log# true > access.log
3. Use the cat/cp/dd utility and / dev/null device to empty the file
In Linux, the null device is basically used to discard output streams that are no longer needed by a process, or as a blank file of an input stream, which can usually be achieved by using the redirection mechanism, so the / dev/null device file is a special file that empties all inputs sent to it, while its output can be treated as an empty file. In addition, you can empty the file by displaying the contents of / dev/null using the cat command and then redirecting the output to a file.
# cat / dev/null > access.log
Next, we will use the cp command to copy the contents of / dev/null to a file for the purpose of emptying it, as shown below:
# cp / dev/null access.log
In the following command, if represents the input file and of represents the output file.
# dd if=/dev/null of=access.log
4. Use the echo command to empty the file
Here, you can use the echo command to redirect the contents of the empty string to the file, as follows:
# echo "" > access.log or # echo > access.log
* * Note: * * you should remember that an empty string is not the same as null. A string indicates that it is a concrete thing, except that its content may be empty, but null means that something does not exist. For this reason, when you redirect the output of the echo command to a file as input and use the cat command to view the contents of the file, you will see a blank line (that is, an empty string). To input null into a file as output, you should use the-n option, which tells echo not to output the new line at the end like the command above.
# echo-n "" > access.log
5. Use the truncate command to clear the contents of the file
Truncate can be used to shrink or expand a file to a given size. You can use it and the-s parameter to specify the size of the file. To empty the contents of the file, set the size of the file to 0 in the following command:
# truncate-s 0 access.log and above are all the contents of the article "how Linux does not use the Linux command line editor to clear or delete large files". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.