Is there a way to empty a configuration file in Linux without deleting it so that it won't lose the permissions?
cat /dev/null > file.txt
Executing this command will make the file blank.
Another solution is
printf '' > file
The >file trick has a slightly different behaviour depending on the used shell. In zsh for instance, it's required to terminate the redirection with ctrl-d if NULLCMD is set to cat (which is the default).
cat > file
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
3 years ago
2 years ago