EN
Linux empty a file
2 points
Quick solution:
xxxxxxxxxx
1
cp /dev/null my_filename.txt
Practical example.
In below example we empty the tomcat logs.
Steps:
- Before the file size is 636M
- We executed the command to empty the file
cp /dev/null catalina.out
- After the file size is 0
Below we have an example from linux command line.
Before - file size 636M:
xxxxxxxxxx
1
root@local:/opt/tomcat/logs# ls -alh
2
-rw-r----- 1 root root 636M Jan 14 20:22 catalina.out
Execute command:
xxxxxxxxxx
1
root@local:/opt/tomcat/logs# cp /dev/null catalina.out
After - file size 0:
xxxxxxxxxx
1
root@local:/opt/tomcat/logs# ls -alh
2
-rw-r----- 1 root root 0 Jan 14 20:23 catalina.out
1. It is posible to redirect empty string into file.
xxxxxxxxxx
1
echo -n > my_filename.txt
2. dev-null redirection gives same result
xxxxxxxxxx
1
cat /dev/null > my_filename.txt