LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
LinkBack Search this Thread
Old 05-29-2007, 09:36 AM   #1
yubemen
LQ Newbie
 
Registered: May 2007
Location: Japan
Posts: 3

Rep: Reputation: 0
about detecting dos file in linux OS


Hi,i got a question.
I want to know if there is some command to use to detect dos file in Linux OS.
Some people told me with "grep -l '^M' filename ",but i try it and find it doesn't work.Maybe it works in Unix OS.
If you know how to do it ,please tell me ,thanks.
 
Old 05-29-2007, 09:44 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Location: the Netherlands
Distribution: lfs, debian, rhel
Posts: 7,514
Blog Entries: 1

Rep: Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139
Hi,

I don't know if the file command could help. It can determine file types and is not limited to dos files.

Take a look at the man page, or here (online version).

Hope this helps.
 
Old 05-29-2007, 10:28 PM   #3
bartonski
Member
 
Registered: Jul 2006
Location: Louisville, KY
Distribution: Fedora 12, Slackware, Debian, Ubuntu Karmic, FreeBSD 7.1
Posts: 438
Blog Entries: 1

Rep: Reputation: 47
I did a quick test using file, here's what I found:

Code:
>file testfile.txt

testfile.txt: ASCII English text, with CRLF line terminators
so... file works. If that hadn't worked, I would have gone for

the -v option on cat makes non-printable characters printable.
Code:
>cat -v testfile.txt
These are the days of miracle and wonder^M
^M
If you absolutely need to know what's in a file, bring out the heavy guns and use od:

Code:
>od -c testfile.txt
0000000   T   h   e   s   e       a   r   e       t   h   e       d   a
0000020   y   s       o   f       m   i   r   a   c   l   e       a   n
0000040   d       w   o   n   d   e   r  \r  \n  \r  \n
0000054
 
Old 05-30-2007, 05:06 AM   #4
yubemen
LQ Newbie
 
Registered: May 2007
Location: Japan
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks you druuna.
Thanks bartonski for your script about my question.
For a single file, I do know how to detect if it is a dos file or others,
but if there are many files need to detect, i just want to detect them with simple command.For this,is there much better method to resolve it?
Through File command,i can do it.But i think it is not the best one.
< find ./ -type f | xargs file | grep "CRLF" | awk -F: '{print $1}' >

If someone know the better method, please tell me.
Thanks.
 
Old 05-31-2007, 01:41 PM   #5
bartonski
Member
 
Registered: Jul 2006
Location: Louisville, KY
Distribution: Fedora 12, Slackware, Debian, Ubuntu Karmic, FreeBSD 7.1
Posts: 438
Blog Entries: 1

Rep: Reputation: 47
grep -Pr "\r" .

-P uses Perl regular expressions, therefore understands "\r" as a carriage return.
-r does a recursive grep.

Your find isn't too shabby though.
 
Old 05-31-2007, 01:44 PM   #6
bartonski
Member
 
Registered: Jul 2006
Location: Louisville, KY
Distribution: Fedora 12, Slackware, Debian, Ubuntu Karmic, FreeBSD 7.1
Posts: 438
Blog Entries: 1

Rep: Reputation: 47
Come to think of it, you probably want

grep -Prl "\r" .

The -l option prints the name of a matching file, without printing the line that matches.
 
Old 05-31-2007, 11:14 PM   #7
yubemen
LQ Newbie
 
Registered: May 2007
Location: Japan
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks bartonski.
That is what i want.very great!

In my pc,the man content of grep is old.(2000/06/09)
So i cann't find the option of "-P".
But grep version is like this : grep (GNU grep) 2.5.1 .
and it has had the function to deal with "-P",i didn't notice it.

Ok,i got my question to be resoled.
Thanks all.

yubemen
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to run DOS EXE file in Debian Linux RMLinux Linux - Newbie 4 08-17-2006 01:25 PM
detecting a DOS attack ignus Linux - Security 4 07-29-2004 02:17 PM
Make file, dos, linux The_Nerd Programming 1 05-29-2004 11:36 PM
converting text file from linux to ms dos Berhanie Linux - Newbie 4 12-24-2003 10:54 PM
Like MS-DOS batch file but for Linux? rverlander Programming 2 06-23-2002 02:51 PM


All times are GMT -5. The time now is 09:39 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration