Or, if I just want to look at such a file, without modifying it, I can run ~/bin/ms-fix in my UTF-8 terminal.
![delete zero byte file in unix delete zero byte file in unix](https://www.tecmint.com/wp-content/uploads/2016/12/Empty-Delete-File-Content-Linux.png)
The -delete action is not available on all find command implementations. There are many ways that could manually create a zero-byte file, for example, saving empty content in a text editor, using utilities provided by operating systems, or programming to create it.On Unix-like systems, the shell command touch filename results in a zero-byte file filename. The -type f option makes sure that we are working on a regular file and not on directories or other special files.
DELETE ZERO BYTE FILE IN UNIX CODE
So that if I need to apply this to say all C source files and headers (my old code from the MS-DOS era, for example!), I just run find. How do I remove a zero byte in Unix To delete all zero byte files in the current directory and sub-directories, use the following find command syntax. I personally like to have this as ~/bin/fix-ms for example, as #!/bin/dash If you use -i.old, then sed saves the original file as filename.old, and the new file (with the modifications, if any) as filename.
![delete zero byte file in unix delete zero byte file in unix](https://user-images.githubusercontent.com/2417276/29788990-357ef47e-8bfa-11e7-9f0d-c420312c8c3d.png)
The LANG=C LC_ALL=C tells the shell you want the command to run in the default C locale (also known as the default POSIX locale), where the three bytes forming the Byte Order Mark are treated as bytes. To remove the byte order mark from the beginning of the file, if it has any, as well as convert any CR LF newlines to LF only. You can use LANG=C LC_ALL=C sed -e 's/\r$// 1 s/^\xef\xbb\xbf//' -i - filename 7 Ways to Recover 0 Byte Files in Windows 10/8/7 When your saved files suddenly turned into 0 bytes, don't worry.