Quick Tip: 3 Ways To Truncate a File in Linux
Share
The following are 3 quick ways to delete the contents of (truncate) a file in Linux:
- Truncate
bash$ truncate -s 0 filename.txt
- I/O Redirection
bash$ > filename.txt
- /dev/null
bash$ cp /dev/null filename.txt
If you get an error it may be because the noclobber feature is enabled on your file. The noclobber feature of Linux is used to prevent accidental overwriting of files. It can be overridden by using either of the following depending on the shell you are using:
If you have any other tricks to truncate files, let me know.
Author
Stewart Schatz
More Stories
Quick Tip: Determine Active Directory Account Status From The Windows Commandline
Use the following command to Determine Active Directory Account Status from the Windows Commandline without Powershell or any special software....
Where Is Java Installed?
Below are a few commands that can be run to determine where Java is installed on each Operating System: Windows:...
Windows God Mode… What!?!
Windows God Mode is a hidden feature in the Windows operating system that allows users to access all of the system’s control panel options and settings in a single place.
A Better SMTP Test
Several years ago, I posted about an SMTP Test that I was using. Well, lately, I've needed something with a...
How To Kill All Processes With The Same Name On Windows
The taskkill command can be used many different ways to end or kill running processes on Windows Server 2012 and...
How To Start/Stop The Server Manager Agent On Linux
The following command can be executed from the Server Manager Console's bin directory to start/stop the Server Manager Agent: nohup...
Average Rating