linux does not delete files empty the contents of the file command

  • 2020-05-14 05:51:19
  • OfStack

At some point, you need to empty the file without deleting the file. Metaphor some log files (log.txt); The command under linux is: true > log.txt

Test results:

touch log. txt →# new file log. txt

vi log.txt →# edit file

Just type in something

: wq! Press enter →# save exit;

cat log.txt →# view file content;

true > log.txt →# view the contents of the file;

The attached:

rm -r deletes directories, whether or not there are files in the directory

rm-rf forced deletion without prompting

These are the only two files used in general. To delete files, you can use rm-f, which is also a mandatory delete

Another way to do this is to use /etc/null, which is also the equivalent of the recycle bin in windows!

cat /etc/passwd | cut-f 1-d: view all users

su switches users

userdel delete the account name

adduser username new user


Related articles: