1753601 Members
6639 Online
108796 Solutions
New Discussion юеВ

Corrupted files

 
Leif Halvarsson_2
Honored Contributor

Corrupted files

Hi
I have found some corrupted files on one filesystem. The files is ordinary text files. Is there any fast way to check if a file contains only printable characters.
9 REPLIES 9
Cheryl Griffin
Honored Contributor

Re: Corrupted files

How about:
# cat filename |vis

vis will show garbage as \002 for example.
"Downtime is a Crime."
Robert-Jan Goossens
Honored Contributor

Re: Corrupted files

Hi,

# file *

Robert-Jan.
T G Manikandan
Honored Contributor

Re: Corrupted files

#file
Balaji N
Honored Contributor

Re: Corrupted files

hi,

man file.

to view the contents, strings filename.

-balaji
Its Always Important To Know, What People Think Of You. Then, Of Course, You Surprise Them By Giving More.
Michael Steele_2
Honored Contributor

Re: Corrupted files

file file_name

...will report ascii text or not. ASCII text is printable characters.

strings file_name |more

...will allow you to convert binary to ascii text for reading purposes.
Support Fatherhood - Stop Family Law
Ian Lochray
Respected Contributor

Re: Corrupted files

Be carefull if you decide to use file from a script and check the output from the command for "ascii text" as the file command will attempt to try to find out what language an ascii file is written in (see man file). This guess can often be wrong. FOr instance, file believes that my /etc/hosts file is "s200 assembler program text".
Bill Hassell
Honored Contributor

Re: Corrupted files

As mentioned, the file command can be used to 'guess' what the contents might be. The problem is that unlike commercial operating systems, Unix does not maintain a concept of a file type. All ordinary files are simply a stream of bytes and only the creator knows what the file's content and purpose might be.

As mentioned, the vis command can be used scan a file and if the output contains \0something, then there is at least one non-printable ASCII character.


Bill Hassell, sysadmin
Leif Halvarsson_2
Honored Contributor

Re: Corrupted files

Hi,

Thank you everybody. vis show there is strange characters in som of the files. The problem seems to be with large files (>1MB). I think I first have to find out how the files have been corrupted.
Michael Steele_2
Honored Contributor

Re: Corrupted files

'cksum' is a quick test of corruption when transporting files, say from one server to another via ftp, or when copying files between new and old file systems.

'cksum' executes a hashing algorithm for the puspose of error correction and the results will be the same if a successful transport occurred.
Support Fatherhood - Stop Family Law