1. How to use redirection
[email protected] ~]# du-4. 0K test.txt test.txt [[email protected] ~]# du-0 test.txt
2. Use the true command to redirect the empty file
[email protected] ~]# du-4. 0K true > test.txt [[email protected] ~]# du-0 test.txt /c5>
3. Use CAT/CP/DD command and/dev/null device to clear the file
[Email protected] ~]# du-h test.txt
4.0K Test.txt
[Email protected] ~]#cat/dev/null > Test.txt
[Email protected] ~]# du-h test.txt
Test.txt
###################################################
[Email protected] ~]# echo "Hello World" > Test.txt
[Email protected] ~]# du-h test.txt
4.0K Test.txt
[Email protected] ~]#cp/dev/null test.txt
CP: Do you want to overwrite "test.txt"? Y
[Email protected] ~]# du-h test.txt
Test.txt
##################################################
[Email protected] ~]# echo "Hello World" > Test.txt
[Email protected] ~]# du-h test.txt
4.0K Test.txt
[Email protected] ~]#DD If=/dev/null of=test.txt
Recorded 0+0 read-in
Recorded the writing of 0+0.
0 bytes (0 B) copied, 0.000266781 seconds, 0.0 kb/sec
[Email protected] ~]# du-h test.txt
Test.txt
4. Use the echo command to clear the file
[[email protected] ~]# echo "hello World "> Test.txt [[email protected] ~]# du-h test.txt 4.0k test.txt [[email protected] ~]# echo-n test.txt/* To add"-n "parameter, by default use" \ n ", carriage return [[email protected] ~]# du-h test.txt 0 test.txt999
5. Empty the file using the truncate command
[[email protected] ~]# du-4. 0K test.txt0 test.txt-s parameter is used to set the file size, empty the file, set to 0; [email Protected] ~]# du-0 test.txt
Several ways to empty Linux files