Unix command to trim file contents

can someone help me with the unix command to trim the contents of files in a directory. I use Cygwin in windows.

+4
source share
3 answers
for file in * do >$file done 
+9
source

Just redirect from nowhere:

 > somefile.txt 
+7
source

If you want to truncate the file in order to save the n last lines of the file, you can do something like (500 lines in this example)

 mv file file.tmp && tail -n 500 file.tmp > file && rm file.tmp 
+2
source

Source: https://habr.com/ru/post/1303124/


All Articles